Add css-url option
README.md
| 24 | 24 | ||
| 25 | 25 | * `--addr`: IPv4 address to listen on (default: `127.0.0.1`). | |
| 26 | 26 | * `--port`: port number to run pastebin on (default: `8080`). | |
| 27 | + | * `--css-url`: URL of a CSS file (default: no stylesheet). | |
| 27 | 28 | ||
| 28 | 29 | ## API | |
| 29 | 30 |
modules/pastebin/http.scm
| 60 | 60 | (values (build-response #:code 404) | |
| 61 | 61 | (lambda (port) 1))) | |
| 62 | 62 | ||
| 63 | - | (define (templatize title body) | |
| 63 | + | (define (templatize title body css-url) | |
| 64 | 64 | `(html (@ (lang "en")) | |
| 65 | 65 | (head | |
| 66 | 66 | (title ,title) | |
| 67 | 67 | (meta (@ (charset "utf-8"))) | |
| 68 | 68 | (meta (@ (name "viewport") (content "width=device-width, initial-scale=1.0"))) | |
| 69 | - | (link (@ (rel "stylesheet") (href "https://unpkg.com/simpledotcss/simple.min.css")))) | |
| 69 | + | ,(if css-url | |
| 70 | + | `(link (@ (rel "stylesheet") (href ,css-url))) | |
| 71 | + | '())) | |
| 70 | 72 | (body ,@body))) | |
| 71 | 73 | ||
| 72 | - | (define (list-handler pb-data-path) | |
| 74 | + | (define (list-handler pb-data-path css-url) | |
| 73 | 75 | (values (build-response | |
| 74 | 76 | #:code 200 | |
| 75 | 77 | #:headers '((content-type . (text/html)))) | |
… | |||
| 106 | 108 | (value "Submit")))))))) | |
| 107 | 109 | (footer (p (a (@ (href "https://repo.pisemsky.site/guile-pastebin") | |
| 108 | 110 | (target "_blank")) | |
| 109 | - | "Source"))))))) | |
| 111 | + | "Source")))) | |
| 112 | + | css-url))) | |
| 110 | 113 | (display "<!DOCTYPE html>\n" port) | |
| 111 | 114 | (sxml->xml sxml port))))) | |
| 112 | 115 | ||
… | |||
| 183 | 186 | (A inport'))))))))) | |
| 184 | 187 | (not-found))) | |
| 185 | 188 | ||
| 186 | - | (define (make-pastebin-handler data-path) | |
| 189 | + | (define* (make-pastebin-handler data-path #:key css-url) | |
| 187 | 190 | (lambda (request request-body) | |
| 188 | 191 | (match (split-and-decode-uri-path (uri-path (request-uri request))) | |
| 189 | 192 | (() | |
| 190 | - | (list-handler data-path)) | |
| 193 | + | (list-handler data-path css-url)) | |
| 191 | 194 | (("post") | |
| 192 | 195 | (post-handler request request-body data-path)) | |
| 193 | 196 | (("raw" pb-id) | |
modules/pastebin/main.scm
| 13 | 13 | ||
| 14 | 14 | (define (run-pastebin args) | |
| 15 | 15 | (let* ((option-spec '((addr (value #t)) | |
| 16 | - | (port (value #t)))) | |
| 16 | + | (port (value #t)) | |
| 17 | + | (css-url (value #t)))) | |
| 17 | 18 | (options (getopt-long args option-spec)) | |
| 18 | 19 | (data-dir (car (option-ref options '() '()))) | |
| 19 | 20 | (addr-str (option-ref options 'addr "127.0.0.1")) | |
| 20 | - | (port-str (option-ref options 'port "8080"))) | |
| 21 | + | (port-str (option-ref options 'port "8080")) | |
| 22 | + | (css-url (option-ref options 'css-url #f))) | |
| 21 | 23 | (if (not (file-exists? data-dir)) | |
| 22 | 24 | (mkdir data-dir)) | |
| 23 | - | (run-server (make-pastebin-handler data-dir) 'http | |
| 25 | + | (run-server (make-pastebin-handler data-dir #:css-url css-url) | |
| 26 | + | 'http | |
| 24 | 27 | (list #:addr (inet-pton AF_INET addr-str) | |
| 25 | 28 | #:port (string->number port-str))))) |