add outer-toc and full nginx config
This commit is contained in:
parent
b2ea116d02
commit
44878e8510
|
@ -1,3 +1,12 @@
|
||||||
# meow
|
# meow
|
||||||
|
|
||||||
meow
|
meow
|
||||||
|
|
||||||
|
## getting started
|
||||||
|
|
||||||
|
```bash
|
||||||
|
capybara-init my-awesome-website
|
||||||
|
cd my-awesome-website
|
||||||
|
nginx -c $PWD/nginx.conf
|
||||||
|
firefox http://localhost:8080
|
||||||
|
```
|
||||||
|
|
12
init.rkt
12
init.rkt
|
@ -1,10 +1,12 @@
|
||||||
#lang racket/base
|
#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")
|
"compiler.rkt" "render.rkt" "util.rkt")
|
||||||
|
|
||||||
(provide init-project)
|
(provide init-project)
|
||||||
|
|
||||||
|
(define-runtime-path *nginx.conf* "support/nginx-dev.conf")
|
||||||
|
|
||||||
(define (init-project name [dir (build-path (current-directory) name)])
|
(define (init-project name [dir (build-path (current-directory) name)])
|
||||||
(when (directory-exists? dir)
|
(when (directory-exists? dir)
|
||||||
(error "directory already exists!" (path->string dir)))
|
(error "directory already exists!" (path->string dir)))
|
||||||
|
@ -30,7 +32,13 @@
|
||||||
(λ () (write-string "#lang capybara/pict\n\n(standard-cat 128 128)")))
|
(λ () (write-string "#lang capybara/pict\n\n(standard-cat 128 128)")))
|
||||||
(with-output-to-file
|
(with-output-to-file
|
||||||
(build-path src "config.rktd")
|
(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])
|
(parameterize ([current-directory dir])
|
||||||
(generate/execute (scan-for-rules)))
|
(generate/execute (scan-for-rules)))
|
||||||
|
|
34
render.rkt
34
render.rkt
|
@ -142,9 +142,34 @@
|
||||||
[(? string? str) str]))
|
[(? string? str) str]))
|
||||||
(map lower-specials* xexpr))
|
(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)
|
(match-define (ir-doc md xref-name content) doc)
|
||||||
(define base-url (assoc-ref+ site-config 'base))
|
(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)])
|
(let ([content (lower-specials content base-url)])
|
||||||
(define content-toc (toc content))
|
(define content-toc (toc content))
|
||||||
|
|
||||||
|
@ -154,6 +179,7 @@
|
||||||
'site-config site-config
|
'site-config site-config
|
||||||
'xref-name xref-name
|
'xref-name xref-name
|
||||||
'base-url base-url
|
'base-url base-url
|
||||||
|
'site-toc site-toc
|
||||||
'content-toc content-toc
|
'content-toc content-toc
|
||||||
'content content)))
|
'content content)))
|
||||||
|
|
||||||
|
@ -202,6 +228,8 @@
|
||||||
xref-name))))
|
xref-name))))
|
||||||
(define config.rktd (build-path src-dir *config.rktd*))
|
(define config.rktd (build-path src-dir *config.rktd*))
|
||||||
|
|
||||||
|
;; TODO : this sucks
|
||||||
|
;; we should have a radix tree
|
||||||
(define xrefs-repo
|
(define xrefs-repo
|
||||||
(for/set ([spec (in-list rule-specs)])
|
(for/set ([spec (in-list rule-specs)])
|
||||||
(define exploded (explode-path (rule-spec-xref-name spec)))
|
(define exploded (explode-path (rule-spec-xref-name spec)))
|
||||||
|
@ -227,7 +255,9 @@
|
||||||
(define config (read config-in))
|
(define config (read config-in))
|
||||||
(unless (config? config)
|
(unless (config? config)
|
||||||
(error "invalid config in config.rktd!"))
|
(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))
|
output-rule))
|
||||||
(append intermediate-rules output-rules (list scss favicon)))
|
(append intermediate-rules output-rules (list scss favicon)))
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -28,7 +28,8 @@
|
||||||
()
|
()
|
||||||
(nav
|
(nav
|
||||||
()
|
()
|
||||||
,content-toc)
|
(section () ,site-toc)
|
||||||
|
(section () ,content-toc))
|
||||||
(main
|
(main
|
||||||
()
|
()
|
||||||
,@content)
|
,@content)
|
||||||
|
|
Loading…
Reference in New Issue