add outer-toc and full nginx config

This commit is contained in:
xenia 2021-06-11 06:09:29 -04:00
parent b2ea116d02
commit 44878e8510
6 changed files with 88 additions and 21 deletions

View File

@ -1,3 +1,12 @@
# meow
meow
## getting started
```bash
capybara-init my-awesome-website
cd my-awesome-website
nginx -c $PWD/nginx.conf
firefox http://localhost:8080
```

View File

@ -1,10 +1,12 @@
#lang racket/base
(require racket/file racket/path racket/pretty
(require racket/file racket/path racket/pretty racket/runtime-path
"compiler.rkt" "render.rkt" "util.rkt")
(provide init-project)
(define-runtime-path *nginx.conf* "support/nginx-dev.conf")
(define (init-project name [dir (build-path (current-directory) name)])
(when (directory-exists? dir)
(error "directory already exists!" (path->string dir)))
@ -30,7 +32,13 @@
(λ () (write-string "#lang capybara/pict\n\n(standard-cat 128 128)")))
(with-output-to-file
(build-path src "config.rktd")
(λ () (pretty-write (list (list 'base (path->string target))))))
(λ () (pretty-write (list (list 'base "http://localhost:8080")))))
(with-output-to-file
(build-path dir "nginx.conf")
(λ ()
(define conf (file->string *nginx.conf*))
(write-string (regexp-replace #rx"@PWD" conf (path->string target)))))
(parameterize ([current-directory dir])
(generate/execute (scan-for-rules)))

View File

@ -142,9 +142,34 @@
[(? string? str) str]))
(map lower-specials* xexpr))
(define (ir-doc->page doc site-config)
(define (ir-doc->page doc xrefs-repo site-config)
(match-define (ir-doc md xref-name content) doc)
(define base-url (assoc-ref+ site-config 'base))
(define exploded (explode-path xref-name))
(define exploded-length (length exploded))
(define (neighbor/immediate-child? p)
(or (= exploded-length (length p))
(and (= (add1 exploded-length) (length p))
(equal? (list-ref p (sub1 exploded-length))
(last exploded)))))
(define site-toc-defs
(for/list ([p (in-set xrefs-repo)] #:when (neighbor/immediate-child? p))
(define target (apply build-path p))
(define link (format "~a~a" base-url (path->string target)))
(define name (path->string (apply build-path (list-tail p (sub1 exploded-length)))))
(list
name
`(li () (a ([href ,link])
,(if (equal? p exploded) `(strong () ,name) name))))))
(define site-toc
(apply list 'ol '()
(for/list ([def (in-list (sort site-toc-defs string<? #:key first))])
(second def))))
(let ([content (lower-specials content base-url)])
(define content-toc (toc content))
@ -154,6 +179,7 @@
'site-config site-config
'xref-name xref-name
'base-url base-url
'site-toc site-toc
'content-toc content-toc
'content content)))
@ -202,6 +228,8 @@
xref-name))))
(define config.rktd (build-path src-dir *config.rktd*))
;; TODO : this sucks
;; we should have a radix tree
(define xrefs-repo
(for/set ([spec (in-list rule-specs)])
(define exploded (explode-path (rule-spec-xref-name spec)))
@ -227,7 +255,9 @@
(define config (read config-in))
(unless (config? config)
(error "invalid config in config.rktd!"))
(~> (port->bytes in) fasl->s-exp (ir-doc->page config) (write-string out)))
(~> (port->bytes in) fasl->s-exp
(ir-doc->page xrefs-repo config)
(write-string out)))
output-rule))
(append intermediate-rules output-rules (list scss favicon)))

35
support/nginx-dev.conf Normal file
View File

@ -0,0 +1,35 @@
# minimal standalone nginx config for development
# sufficient to serve a capybara-generated site tree
daemon off;
master_process off;
error_log /dev/stderr info;
pid /tmp/nginx-capybara.pid;
events {}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
charset UTF-8;
types_hash_max_size 4096;
access_log /dev/stdout;
gzip on;
map $http_user_agent $mathjax_polyfill {
default "<script type='text/javascript' src='https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>";
"~Mozilla.*Firefox/[0-9]+" "";
}
server {
server_name localhost;
listen 8080 default;
root @PWD;
index index.html;
location / {
try_files $uri $uri.html $uri/ =404;
sub_filter "__X_MATHJAX_POLYFILL_PLACEHOLDER__" $mathjax_polyfill;
}
}
}

View File

@ -1,16 +0,0 @@
map $http_user_agent $mathjax_polyfill {
default "<script type='text/javascript' src='https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>";
"~Mozilla.*Firefox/[0-9]+" "";
}
server {
server_name localhost;
listen 80 default;
root /var/www/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
sub_filter "__X_MATHJAX_POLYFILL_PLACEHOLDER__" $mathjax_polyfill;
}
}

View File

@ -28,7 +28,8 @@
()
(nav
()
,content-toc)
(section () ,site-toc)
(section () ,content-toc))
(main
()
,@content)