a webring manager, I guess
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

70 lines
2.1 KiB

#lang racket/base
(require racket/cmdline
racket/contract/base
racket/format
web-server/servlet
web-server/servlet-env
"src/indexhash.rkt"
"src/render.rkt"
"src/users.rkt")
(provide/contract (site-dispatch (request? . -> . response?)))
; retrieves the users file as a command line argument
(define user-files
(command-line
#:program "perihelion"
#:args (static filename)
(cons (path->complete-path static) (path->complete-path filename))))
(define static-path (car user-files))
(define users-path (cdr user-files))
; dispatch rules for the URL
; site-dispatch: request -> response
; entrypoint for the servlet
(define-values (site-dispatch site-url)
(dispatch-rules
[("") main-page]
; fuck you
[("5225225" "raw") (lambda (req)
(footer-page-raw req "5225225"))]
[((integer-arg) "raw") footer-page-raw] ; legacy
[((string-arg) "raw") footer-page-raw]
[("5225225" "pre") (lambda (req)
(footer-page req "5225225"))]
[((integer-arg)) footer-page] ; legacy
[((string-arg) "pre") footer-page]))
; main-page: request -> response
; index page
(define (main-page req)
(response/xexpr
(render-main-page (read-sites users-path))))
; footer-page-raw: request -> response
; raw entrypoint for footer if custom CSS is desired
(define (footer-page-raw req arg)
(let* ([sites (read-sites users-path)]
[idx (if (string? arg)
(key->index sites arg)
arg)])
(response/xexpr
(render-raw-footer idx sites))))
; footer-page: request -> response
; the footer for each individual site, indexed
(define (footer-page req arg)
(let* ([sites (read-sites users-path)]
[idx (if (string? arg)
(key->index sites arg)
arg)])
(response/xexpr
(render-footer idx sites))))
(serve/servlet site-dispatch
#:launch-browser? #f
#:quit? #f
#:listen-ip #f
#:port 5020
#:extra-files-paths (list static-path)
#:servlet-regexp #px"")