forked from cadence/breezewiki
		
	Use ini for configuration
This commit is contained in:
		
							parent
							
								
									73a5cb68c5
								
							
						
					
					
						commit
						b18a31df4a
					
				
					 5 changed files with 41 additions and 26 deletions
				
			
		
							
								
								
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -12,4 +12,4 @@ | ||||||
| compiled | compiled | ||||||
| 
 | 
 | ||||||
| # Personal | # Personal | ||||||
| /config.txt | /config.ini | ||||||
|  |  | ||||||
|  | @ -23,7 +23,8 @@ | ||||||
|         #".svg" #"image/svg+xml")) |         #".svg" #"image/svg+xml")) | ||||||
| 
 | 
 | ||||||
| (serve/launch/wait | (serve/launch/wait | ||||||
|  #:port (config-get 'port) |  #:listen-ip (if (config-true? 'debug) "127.0.0.1" #f) | ||||||
|  |  #:port (string->number (config-get 'port)) | ||||||
|  (λ (quit) |  (λ (quit) | ||||||
|    (sequencer:make |    (sequencer:make | ||||||
|     (pathprocedure:make "/proxy" page-proxy) |     (pathprocedure:make "/proxy" page-proxy) | ||||||
|  | @ -38,5 +39,5 @@ | ||||||
|                                  #:path->mime-type |                                  #:path->mime-type | ||||||
|                                  (lambda (u) |                                  (lambda (u) | ||||||
|                                    (hash-ref mime-types (path-get-extension u))) |                                    (hash-ref mime-types (path-get-extension u))) | ||||||
|                                  #:cache-no-cache (config-get 'debug) #;"browser applies heuristics if unset")) |                                  #:cache-no-cache (config-true? 'debug) #;"browser applies heuristics if unset")) | ||||||
|     (lift:make page-not-found)))) |     (lift:make page-not-found)))) | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								info.rkt
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								info.rkt
									
										
									
									
									
								
							|  | @ -1,3 +1,3 @@ | ||||||
| #lang info | #lang info | ||||||
| 
 | 
 | ||||||
| (define build-deps '("rackunit-lib" "web-server-lib" "http-easy-lib" "html-parsing" "html-writing" "json-pointer")) | (define build-deps '("rackunit-lib" "web-server-lib" "http-easy-lib" "html-parsing" "html-writing" "json-pointer" "ini-lib")) | ||||||
|  |  | ||||||
|  | @ -47,9 +47,10 @@ | ||||||
|                                (div (@ (id "mw-content-text")) |                                (div (@ (id "mw-content-text")) | ||||||
|                                     ,content)) |                                     ,content)) | ||||||
|                           (footer (@ (class "custom-footer")) |                           (footer (@ (class "custom-footer")) | ||||||
|                                   (img (@ (class "my-logo") (src "/static/breezewiki.svg"))) |  | ||||||
|                                   (div (@ (class "custom-footer__cols")) |                                   (div (@ (class "custom-footer__cols")) | ||||||
|                                        (div |                                        (div | ||||||
|  |                                         (p | ||||||
|  |                                          (img (@ (class "my-logo") (src "/static/breezewiki.svg")))) | ||||||
|                                         (p |                                         (p | ||||||
|                                          (a (@ (href "https://gitdab.com/cadence/breezewiki")) |                                          (a (@ (href "https://gitdab.com/cadence/breezewiki")) | ||||||
|                                             ,(format "~a source code" (config-get 'application-name)))) |                                             ,(format "~a source code" (config-get 'application-name)))) | ||||||
|  | @ -61,7 +62,7 @@ | ||||||
|                                                  (a (@ (href "https://cadence.moe/contact")) |                                                  (a (@ (href "https://cadence.moe/contact")) | ||||||
|                                                     "Cadence.")) |                                                     "Cadence.")) | ||||||
|                                              `(p |                                              `(p | ||||||
|                                                ,(format "This unofficial instance is based off the ~a source code, but is not administered by its developer." (config-get 'application-name))))) |                                                ,(format "This unofficial instance is based off the ~a source code, but is not controlled by the code developer." (config-get 'application-name))))) | ||||||
|                                        (div |                                        (div | ||||||
|                                         (p "This page displays proxied content from " |                                         (p "This page displays proxied content from " | ||||||
|                                            (a (@ (href ,source-url) (rel "noreferrer")) ,source-url) |                                            (a (@ (href ,source-url) (rel "noreferrer")) ,source-url) | ||||||
|  |  | ||||||
|  | @ -1,36 +1,49 @@ | ||||||
| #lang racket/base | #lang racket/base | ||||||
| (require racket/runtime-path) | (require racket/runtime-path | ||||||
|  |          ini) | ||||||
| 
 | 
 | ||||||
| (provide | (provide | ||||||
|  |  config-true? | ||||||
|  config-get) |  config-get) | ||||||
| 
 | 
 | ||||||
| (define-runtime-path path-config "../config.txt") | (define-runtime-path path-config "../config.ini") | ||||||
|  | 
 | ||||||
|  | (define (config-true? key) | ||||||
|  |   (not (member (hash-ref config key) '("" "false")))) | ||||||
| 
 | 
 | ||||||
| (define (config-get key) | (define (config-get key) | ||||||
|   (hash-ref config key)) |   (hash-ref config key)) | ||||||
| 
 | 
 | ||||||
| (define default-config | (define default-config | ||||||
|   '((port . 10416) |   '((port . "10416") | ||||||
|     (debug . #f) |     (debug . "false") | ||||||
|     (instance-is-official . #f) ; please don't turn this on, or you will make me very upset |     (instance-is-official . "false") ; please don't turn this on, or you will make me very upset | ||||||
|     (application-name . "BreezeWiki"))) |     (application-name . "BreezeWiki"))) | ||||||
| 
 | 
 | ||||||
| (define config | (define config | ||||||
|   (make-hasheq |   (make-hasheq | ||||||
|    (append |    (append | ||||||
|     default-config |     default-config | ||||||
|     (with-handlers ([exn:fail:filesystem:errno? (λ (exn) |     (with-handlers ([exn:fail:filesystem:errno? | ||||||
|                                                   '())]) |                      (λ (exn) | ||||||
|       (call-with-input-file path-config |                        (begin0 | ||||||
|         (λ (in) |                            '() | ||||||
|           (let loop ([alist '()]) |                          (displayln "note: config file not detected, using defaults")))] | ||||||
|             (let ([key (read in)] |                     [exn:fail:contract? | ||||||
|                   [value (read in)]) |                      (λ (exn) | ||||||
|               (if (eq? value eof) |                        (begin0 | ||||||
|                   alist |                            '() | ||||||
|                   (loop (cons (cons key |                          (displayln "note: config file empty or missing [] section, using defaults")))]) | ||||||
|                                     (cond |       (let ([l (hash->list | ||||||
|                                       [(eq? value 'true) #t] |                 (hash-ref | ||||||
|                                       [(eq? value 'false) #f] |                  (ini->hash | ||||||
|                                       [#t value])) |                   (call-with-input-file path-config | ||||||
|                               alist))))))))))) |                     (λ (in) | ||||||
|  |                       (read-ini in)))) | ||||||
|  |                  '||))]) | ||||||
|  |             (begin0 | ||||||
|  |                 l | ||||||
|  |               (printf "note: ~a items loaded from config file~n" (length l)))))))) | ||||||
|  | 
 | ||||||
|  | (when (config-true? 'debug) | ||||||
|  |   (printf "config: ~v~n" config)) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue