forked from cadence/breezewiki
		
	Pass siteinfo through code; show sitename in title
This commit is contained in:
		
							parent
							
								
									9aba3ad432
								
							
						
					
					
						commit
						59332fd9d1
					
				
					 5 changed files with 30 additions and 24 deletions
				
			
		|  | @ -48,8 +48,8 @@ | ||||||
|                 ,(if source-url |                 ,(if source-url | ||||||
|                      `(div (p "This page displays proxied content from " |                      `(div (p "This page displays proxied content from " | ||||||
|                               (a (@ (href ,source-url) (rel "noreferrer")) ,source-url) |                               (a (@ (href ,source-url) (rel "noreferrer")) ,source-url) | ||||||
|                               ,(format ". Text content is available under the ~a license, " (license-text license)) |                               ,(format ". Text content is available under the ~a license, " (license^-text license)) | ||||||
|                               (a (@ (href ,(license-url license))) "see license info.") |                               (a (@ (href ,(license^-url license))) "see license info.") | ||||||
|                               " Media files may have different copying restrictions.") |                               " Media files may have different copying restrictions.") | ||||||
|                            (p ,(format "Fandom is a trademark of Fandom, Inc. ~a is not affiliated with Fandom." (config-get 'application_name)))) |                            (p ,(format "Fandom is a trademark of Fandom, Inc. ~a is not affiliated with Fandom." (config-get 'application_name)))) | ||||||
|                      `(div (p "Text content on wikis run by Fandom is available under the Creative Commons Attribution-Share Alike License 3.0 (Unported), " |                      `(div (p "Text content on wikis run by Fandom is available under the Creative Commons Attribution-Share Alike License 3.0 (Unported), " | ||||||
|  | @ -63,7 +63,8 @@ | ||||||
|          #:wikiname wikiname |          #:wikiname wikiname | ||||||
|          #:title title |          #:title title | ||||||
|          #:body-class [body-class-in #f] |          #:body-class [body-class-in #f] | ||||||
|          #:license [license #f]) |          #:siteinfo [siteinfo-in #f]) | ||||||
|  |   (define siteinfo (or siteinfo-in siteinfo-default)) | ||||||
|   (define body-class (if (not body-class-in) |   (define body-class (if (not body-class-in) | ||||||
|                          "skin-fandomdesktop" |                          "skin-fandomdesktop" | ||||||
|                          body-class-in)) |                          body-class-in)) | ||||||
|  | @ -82,7 +83,10 @@ | ||||||
|   `(html |   `(html | ||||||
|     (head |     (head | ||||||
|      (meta (@ (name "viewport") (content "width=device-width, initial-scale=1"))) |      (meta (@ (name "viewport") (content "width=device-width, initial-scale=1"))) | ||||||
|      (title ,(format "~a | ~a" title (config-get 'application_name))) |      (title ,(format "~a | ~a+~a" | ||||||
|  |                      title | ||||||
|  |                      (regexp-replace #rx" ?Wiki$" (siteinfo^-sitename siteinfo) "") | ||||||
|  |                      (config-get 'application_name))) | ||||||
|      ,@(map (λ (url) |      ,@(map (λ (url) | ||||||
|               `(link (@ (rel "stylesheet") (type "text/css") (href ,url)))) |               `(link (@ (rel "stylesheet") (type "text/css") (href ,url)))) | ||||||
|             (required-styles (format "https://~a.fandom.com" wikiname))) |             (required-styles (format "https://~a.fandom.com" wikiname))) | ||||||
|  | @ -101,7 +105,7 @@ | ||||||
|                           (div (@ (id "content") #;(class "page-content")) |                           (div (@ (id "content") #;(class "page-content")) | ||||||
|                                (div (@ (id "mw-content-text")) |                                (div (@ (id "mw-content-text")) | ||||||
|                                     ,content)) |                                     ,content)) | ||||||
|                           ,(application-footer source-url #:license license))))))) |                           ,(application-footer source-url #:license (siteinfo^-license siteinfo)))))))) | ||||||
| (module+ test | (module+ test | ||||||
|   (define page |   (define page | ||||||
|     (parameterize ([(config-parameter 'strict_proxy) "true"]) |     (parameterize ([(config-parameter 'strict_proxy) "true"]) | ||||||
|  |  | ||||||
							
								
								
									
										16
									
								
								src/data.rkt
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								src/data.rkt
									
										
									
									
									
								
							|  | @ -6,15 +6,17 @@ | ||||||
|          "xexpr-utils.rkt") |          "xexpr-utils.rkt") | ||||||
| 
 | 
 | ||||||
| (provide | (provide | ||||||
|  (struct-out siteinfo) |  (struct-out siteinfo^) | ||||||
|  (struct-out license) |  (struct-out license^) | ||||||
|  siteinfo-fetch |  siteinfo-fetch | ||||||
|  |  siteinfo-default | ||||||
|  license-default) |  license-default) | ||||||
| 
 | 
 | ||||||
| (struct siteinfo (sitename basepage license) #:transparent) | (struct siteinfo^ (sitename basepage license) #:transparent) | ||||||
| (struct license (text url) #:transparent) | (struct license^ (text url) #:transparent) | ||||||
| 
 | 
 | ||||||
| (define license-default (license "CC-BY-SA" "https://www.fandom.com/licensing")) | (define license-default (license^ "CC-BY-SA" "https://www.fandom.com/licensing")) | ||||||
|  | (define siteinfo-default (siteinfo^ "Test Wiki" "Main_Page" license-default)) | ||||||
| 
 | 
 | ||||||
| (define/memoize (siteinfo-fetch wikiname) #:hash hash | (define/memoize (siteinfo-fetch wikiname) #:hash hash | ||||||
|   (define dest-url |   (define dest-url | ||||||
|  | @ -28,7 +30,7 @@ | ||||||
|   (log-outgoing dest-url) |   (log-outgoing dest-url) | ||||||
|   (define res (easy:get dest-url)) |   (define res (easy:get dest-url)) | ||||||
|   (define data (easy:response-json res)) |   (define data (easy:response-json res)) | ||||||
|   (siteinfo (jp "/query/general/sitename" data) |   (siteinfo^ (jp "/query/general/sitename" data) | ||||||
|              (second (regexp-match #rx"/wiki/(.*)" (jp "/query/general/base" data))) |              (second (regexp-match #rx"/wiki/(.*)" (jp "/query/general/base" data))) | ||||||
|             (license (jp "/query/rightsinfo/text" data) |              (license^ (jp "/query/rightsinfo/text" data) | ||||||
|                        (jp "/query/rightsinfo/url" data)))) |                        (jp "/query/rightsinfo/url" data)))) | ||||||
|  |  | ||||||
|  | @ -35,14 +35,14 @@ | ||||||
|          #:members-data members-data |          #:members-data members-data | ||||||
|          #:page page |          #:page page | ||||||
|          #:body-class [body-class #f] |          #:body-class [body-class #f] | ||||||
|          #:license [license #f]) |          #:siteinfo [siteinfo #f]) | ||||||
|   (define members (jp "/query/categorymembers" members-data)) |   (define members (jp "/query/categorymembers" members-data)) | ||||||
|   (generate-wiki-page |   (generate-wiki-page | ||||||
|    #:source-url source-url |    #:source-url source-url | ||||||
|    #:wikiname wikiname |    #:wikiname wikiname | ||||||
|    #:title title |    #:title title | ||||||
|    #:body-class body-class |    #:body-class body-class | ||||||
|    #:license license |    #:siteinfo siteinfo | ||||||
|    `(div |    `(div | ||||||
|      ,(update-tree-wiki page wikiname) |      ,(update-tree-wiki page wikiname) | ||||||
|      (hr) |      (hr) | ||||||
|  | @ -89,7 +89,7 @@ | ||||||
|                 (log-outgoing dest-url) |                 (log-outgoing dest-url) | ||||||
|                 (define dest-res (easy:get dest-url #:timeouts timeouts)) |                 (define dest-res (easy:get dest-url #:timeouts timeouts)) | ||||||
|                 (easy:response-json dest-res)] |                 (easy:response-json dest-res)] | ||||||
|      [license (siteinfo-license (siteinfo-fetch wikiname))]) |      [siteinfo (siteinfo-fetch wikiname)]) | ||||||
| 
 | 
 | ||||||
|     (define title (preprocess-html-wiki (jp "/parse/title" page-data prefixed-category))) |     (define title (preprocess-html-wiki (jp "/parse/title" page-data prefixed-category))) | ||||||
|     (define page-html (preprocess-html-wiki (jp "/parse/text" page-data ""))) |     (define page-html (preprocess-html-wiki (jp "/parse/text" page-data ""))) | ||||||
|  | @ -105,7 +105,7 @@ | ||||||
|                   #:members-data members-data |                   #:members-data members-data | ||||||
|                   #:page page |                   #:page page | ||||||
|                   #:body-class body-class |                   #:body-class body-class | ||||||
|                   #:license license)) |                   #:siteinfo siteinfo)) | ||||||
| 
 | 
 | ||||||
|     (when (config-true? 'debug) |     (when (config-true? 'debug) | ||||||
|       ; used for its side effects |       ; used for its side effects | ||||||
|  |  | ||||||
|  | @ -25,13 +25,13 @@ | ||||||
|   (define search-json-data |   (define search-json-data | ||||||
|     '#hasheq((batchcomplete . #t) (query . #hasheq((search . (#hasheq((ns . 0) (pageid . 219) (size . 1482) (snippet . "") (timestamp . "2022-08-21T08:54:23Z") (title . "Gacha Capsule") (wordcount . 214)) #hasheq((ns . 0) (pageid . 201) (size . 1198) (snippet . "") (timestamp . "2022-07-11T17:52:47Z") (title . "Badges") (wordcount . 181))))))))) |     '#hasheq((batchcomplete . #t) (query . #hasheq((search . (#hasheq((ns . 0) (pageid . 219) (size . 1482) (snippet . "") (timestamp . "2022-08-21T08:54:23Z") (title . "Gacha Capsule") (wordcount . 214)) #hasheq((ns . 0) (pageid . 201) (size . 1198) (snippet . "") (timestamp . "2022-07-11T17:52:47Z") (title . "Badges") (wordcount . 181))))))))) | ||||||
| 
 | 
 | ||||||
| (define (generate-results-page dest-url wikiname query data #:license [license #f]) | (define (generate-results-page dest-url wikiname query data #:siteinfo [siteinfo #f]) | ||||||
|   (define search-results (jp "/query/search" data)) |   (define search-results (jp "/query/search" data)) | ||||||
|   (generate-wiki-page |   (generate-wiki-page | ||||||
|    #:source-url dest-url |    #:source-url dest-url | ||||||
|    #:wikiname wikiname |    #:wikiname wikiname | ||||||
|    #:title "Search Results" |    #:title "Search Results" | ||||||
|    #:license license |    #:siteinfo siteinfo | ||||||
|    `(div (@ (class "mw-parser-output")) |    `(div (@ (class "mw-parser-output")) | ||||||
|          (p ,(format "~a results found for " (length search-results)) |          (p ,(format "~a results found for " (length search-results)) | ||||||
|             (strong ,query)) |             (strong ,query)) | ||||||
|  | @ -70,11 +70,11 @@ | ||||||
|    (thread-let |    (thread-let | ||||||
|     ([dest-res (log-outgoing dest-url) |     ([dest-res (log-outgoing dest-url) | ||||||
|                (easy:get dest-url #:timeouts timeouts)] |                (easy:get dest-url #:timeouts timeouts)] | ||||||
|      [license (siteinfo-license (siteinfo-fetch wikiname))]) |      [siteinfo (siteinfo-fetch wikiname)]) | ||||||
| 
 | 
 | ||||||
|     (define data (easy:response-json dest-res)) |     (define data (easy:response-json dest-res)) | ||||||
| 
 | 
 | ||||||
|     (define body (generate-results-page dest-url wikiname query data #:license license)) |     (define body (generate-results-page dest-url wikiname query data #:siteinfo siteinfo)) | ||||||
|     (when (config-true? 'debug) |     (when (config-true? 'debug) | ||||||
|       ; used for its side effects |       ; used for its side effects | ||||||
|       ; convert to string with error checking, error will be raised if xexp is invalid |       ; convert to string with error checking, error will be raised if xexp is invalid | ||||||
|  |  | ||||||
|  | @ -248,7 +248,7 @@ | ||||||
|                                          ("format" . "json"))))) |                                          ("format" . "json"))))) | ||||||
|               (log-outgoing dest-url) |               (log-outgoing dest-url) | ||||||
|               (easy:get dest-url #:timeouts timeouts)] |               (easy:get dest-url #:timeouts timeouts)] | ||||||
|     [license (siteinfo-license (siteinfo-fetch wikiname))]) |     [siteinfo (siteinfo-fetch wikiname)]) | ||||||
| 
 | 
 | ||||||
|    (cond |    (cond | ||||||
|      [(eq? 200 (easy:response-status-code dest-res)) |      [(eq? 200 (easy:response-status-code dest-res)) | ||||||
|  | @ -271,7 +271,7 @@ | ||||||
|                 #:wikiname wikiname |                 #:wikiname wikiname | ||||||
|                 #:title title |                 #:title title | ||||||
|                 #:body-class body-class |                 #:body-class body-class | ||||||
|                 #:license license)) |                 #:siteinfo siteinfo)) | ||||||
|              (define redirect-msg ((query-selector (attribute-selector 'class "redirectMsg") body))) |              (define redirect-msg ((query-selector (attribute-selector 'class "redirectMsg") body))) | ||||||
|              (define headers (if redirect-msg |              (define headers (if redirect-msg | ||||||
|                                  (let* ([dest (get-attribute 'href (bits->attributes ((query-selector (λ (t a c) (eq? t 'a)) redirect-msg))))] |                                  (let* ([dest (get-attribute 'href (bits->attributes ((query-selector (λ (t a c) (eq? t 'a)) redirect-msg))))] | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue