Add css-url option

Evgeny PisemskySat Sep 13 12:12:30+0300 2025

c82bbe4

Add css-url option

README.md

2424
2525
* `--addr`: IPv4 address to listen on (default: `127.0.0.1`).
2626
* `--port`: port number to run pastebin on (default: `8080`).
27+
* `--css-url`: URL of a CSS file (default: no stylesheet).
2728
2829
## API
2930

modules/pastebin/http.scm

6060
  (values (build-response #:code 404)
6161
          (lambda (port) 1)))
6262
63-
(define (templatize title body)
63+
(define (templatize title body css-url)
6464
  `(html (@ (lang "en"))
6565
         (head
6666
          (title ,title)
6767
          (meta (@ (charset "utf-8")))
6868
          (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+
               '()))
7072
         (body ,@body)))
7173
72-
(define (list-handler pb-data-path)
74+
(define (list-handler pb-data-path css-url)
7375
  (values (build-response
7476
           #:code 200
7577
           #:headers '((content-type . (text/html))))

106108
                                                                          (value "Submit"))))))))
107109
                            (footer (p (a (@ (href "https://repo.pisemsky.site/guile-pastebin")
108110
                                             (target "_blank"))
109-
                                          "Source")))))))
111+
                                          "Source"))))
112+
                          css-url)))
110113
              (display "<!DOCTYPE html>\n" port)
111114
              (sxml->xml sxml port)))))
112115

183186
                              (A inport')))))))))
184187
      (not-found)))
185188
186-
(define (make-pastebin-handler data-path)
189+
(define* (make-pastebin-handler data-path #:key css-url)
187190
  (lambda (request request-body)
188191
    (match (split-and-decode-uri-path (uri-path (request-uri request)))
189192
      (()
190-
       (list-handler data-path))
193+
       (list-handler data-path css-url))
191194
      (("post")
192195
       (post-handler request request-body data-path))
193196
      (("raw" pb-id)

modules/pastebin/main.scm

1313
1414
(define (run-pastebin args)
1515
  (let* ((option-spec '((addr (value #t))
16-
                        (port (value #t))))
16+
                        (port (value #t))
17+
                        (css-url (value #t))))
1718
         (options (getopt-long args option-spec))
1819
         (data-dir (car (option-ref options '() '())))
1920
         (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)))
2123
    (if (not (file-exists? data-dir))
2224
        (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
2427
                (list #:addr (inet-pton AF_INET addr-str)
2528
                      #:port (string->number port-str)))))