use template to generate page

This commit is contained in:
xenia 2021-06-06 23:09:23 -04:00
parent 45f4f4f0ac
commit 1d9c60bb28
6 changed files with 57 additions and 57 deletions

View File

@ -5,7 +5,7 @@
(define-runtime-path *js-path* "./mathml-render.js") (define-runtime-path *js-path* "./mathml-render.js")
(provide transform-xexprs get-styles) (provide transform-xexprs scss-files)
(define (mathtex-type? s) (define (mathtex-type? s)
(and (string? s) (regexp-match #rx"^math/tex" s) #t)) (and (string? s) (regexp-match #rx"^math/tex" s) #t))
@ -52,4 +52,4 @@
(cons tag (cons attrs (map transform-xexpr body)))] (cons tag (cons attrs (map transform-xexpr body)))]
[(? string? str) str])) [(? string? str) str]))
(define (get-styles) "") (define scss-files '())

View File

@ -7,6 +7,17 @@ pre.highlight, .highlight {
color: $mono-1; color: $mono-1;
} }
.highlighttable {
background: $syntax-gutter-background-color;
color: $syntax-gutter-text-color;
margin: 0.5em;
pre {
margin: 0;
}
}
.highlight { .highlight {
pre { background: $syntax-bg; } pre { background: $syntax-bg; }
.hll { background: $syntax-bg; } .hll { background: $syntax-bg; }

View File

@ -1,12 +1,11 @@
#lang racket/base #lang racket/base
(require racket/list racket/match racket/port racket/runtime-path racket/string (require racket/list racket/match racket/port racket/runtime-path racket/string xml)
xml sass)
(define-runtime-path *python-path* "syntax-render.py") (define-runtime-path *python-path* "syntax-render.py")
(define-runtime-path *css-path* "css") (define-runtime-path *css-path* "css")
(provide transform-xexprs get-styles) (provide transform-xexprs scss-files)
(define (brush-class? s) (define (brush-class? s)
(and (string? s) (regexp-match #rx"^brush:" s) #t)) (and (string? s) (regexp-match #rx"^brush:" s) #t))
@ -53,5 +52,4 @@
(cons tag (cons attrs (map transform-xexpr body)))] (cons tag (cons attrs (map transform-xexpr body)))]
[(? string? str) str])) [(? string? str) str]))
(define (get-styles) (define scss-files (list (build-path *css-path* "syntax.scss")))
(compile/file (build-path *css-path* "syntax.scss") #t))

View File

@ -1,8 +1,10 @@
#lang racket #lang racket
(require markdown markdown/display-xexpr markdown/toc (require markdown markdown/display-xexpr markdown/toc
(prefix-in sass: sass)
(prefix-in mathml: "ext-mathml/main.rkt") (prefix-in mathml: "ext-mathml/main.rkt")
(prefix-in syntax: "ext-syntax/main.rkt")) (prefix-in syntax: "ext-syntax/main.rkt")
(prefix-in article: "templates/article.html.rkt"))
(define metadata? (define metadata?
(listof (or/c (listof (or/c
@ -39,41 +41,20 @@
(define output-cooked (mathml:transform-xexprs (syntax:transform-xexprs output-raw))) (define output-cooked (mathml:transform-xexprs (syntax:transform-xexprs output-raw)))
(define output-toc (toc output-cooked)) (define output-toc (toc output-cooked))
(define styles (string-append (mathml:get-styles) (syntax:get-styles))) (define scss-files (append mathml:scss-files syntax:scss-files))
(define top-level-style
(string-join (map (λ (x) (format "@import \"~a\";" (path->string x))) scss-files) "\n"))
(define styles (sass:compile/string top-level-style #t))
(define document (define document
`(html (article:execute (hash 'metadata-ref metadata-ref
([lang "en"]) 'metadata-ref+ metadata-ref+
(head '*banner* *banner*
() '*mathjax-placeholder* *mathjax-placeholder*
,*banner* 'metadata md
(meta ([charset "utf-8"])) 'page-styles styles
(title () ,(metadata-ref+ md 'title "<untitled article>")) 'content-toc output-toc
(meta ([name "viewport"] [content "width=device-width, initial-scale=1"])) 'content output-cooked)))
,@(match (metadata-ref+ md 'summary)
[#f '()]
[summary
`((meta ([name "description"] [content ,summary])))])
,@(match (metadata-ref md 'authors)
[(or #f '()) '()]
[authors
`((meta ([name "author"] [content ,(string-join authors ", ")])))])
,@(match (metadata-ref md 'date)
[#f '()]
[(list y m d)
`((meta ([name "DC.Date.created"] [content ,(format "~a-~a~a" y m d)])))])
(meta ([name "generator"] [content "meow meow meow meow"]))
;<link rel="shortcut icon" type="image/png" href="haskal.png"/>
(style ([type "text/css"]) ,styles))
(body
()
(nav
()
,output-toc)
(main
()
,@output-cooked)
,*mathjax-placeholder*)))
(with-output-to-string (λ () (display "<!doctype html>") (display-xexpr document)))) (with-output-to-string (λ () (display "<!doctype html>") (display-xexpr document))))

View File

@ -6,29 +6,33 @@
() ()
,*banner* ,*banner*
(meta ([charset "utf-8"])) (meta ([charset "utf-8"]))
(title () ,(metadata-ref+ md 'title "<untitled article>")) (title () ,(metadata-ref+ metadata 'title "<untitled article>"))
(meta ([name "viewport"] [content "width=device-width, initial-scale=1"])) (meta ([name "viewport"] [content "width=device-width, initial-scale=1"]))
,@(match (metadata-ref+ md 'summary) ,@(match (metadata-ref+ metadata 'summary)
[#f '()] [#f '()]
[summary [summary
`((meta ([name "description"] [content ,summary])))]) `((meta ([name "description"] [content ,summary])))])
,@(match (metadata-ref md 'authors) ,@(match (metadata-ref metadata 'authors)
[(or #f '()) '()] [(or #f '()) '()]
[authors [authors
`((meta ([name "author"] [content ,(string-join authors ", ")])))]) `((meta ([name "author"] [content ,(string-join authors ", ")])))])
,@(match (metadata-ref md 'date) ,@(match (metadata-ref metadata 'date)
[#f '()] [#f '()]
[(list y m d) [(list yn mn dn)
`((meta ([name "DC.Date.created"] [content ,(format "~a-~a~a" y m d)])))]) `((meta ([name "DC.Date.created"]
[content ,(format "~a-~a-~a"
(~r yn #:min-width 4 #:pad-string "0")
(~r mn #:min-width 2 #:pad-string "0")
(~r dn #:min-width 2 #:pad-string "0"))])))])
(meta ([name "generator"] [content "meow meow meow meow"])) (meta ([name "generator"] [content "meow meow meow meow"]))
;<link rel="shortcut icon" type="image/png" href="haskal.png"/> ;<link rel="shortcut icon" type="image/png" href="haskal.png"/>
(style ([type "text/css"]) ,styles)) (style ([type "text/css"]) ,page-styles))
(body (body
() ()
(nav (nav
() ()
,output-toc) ,content-toc)
(main (main
() ()
,@output-cooked) ,@content)
,*mathjax-placeholder*)) ,*mathjax-placeholder*))

View File

@ -1,12 +1,12 @@
#lang racket/base #lang racket/base
(require racket/base racket/list racket/match racket/string (require racket/base racket/format racket/list racket/match racket/string
syntax/parse syntax/parse/define syntax/parse syntax/parse/define
(for-syntax racket/base racket/match racket/set)) (for-syntax racket/base racket/match racket/set))
(provide (rename-out [x:#%module-begin #%module-begin] (provide (rename-out [x:#%module-begin #%module-begin]
[x:#%top #%top]) [x:#%top #%top])
(except-out (all-from-out racket/base racket/list racket/match racket/string) (except-out (all-from-out racket/base racket/format racket/list racket/match racket/string)
#%module-begin #%top)) #%module-begin #%top))
(define-for-syntax *unbound-prop* 'xtemplate:unbound) (define-for-syntax *unbound-prop* 'xtemplate:unbound)
@ -28,10 +28,16 @@
(define-syntax-parse-rule (x:#%module-begin body) (define-syntax-parse-rule (x:#%module-begin body)
#:with #%template-args (datum->syntax #'body '#%template-args) #:with #%template-args (datum->syntax #'body '#%template-args)
#:with execute-fn #'(λ (#%template-args) body) #:with execute-fn #'(λ (#%template-args) body)
#:with expanded-execute-fn (local-expand #'execute-fn (syntax-local-context) '()) #:with expanded-execute-fn #'execute-fn
#:with (unbound-ids ...) ; #:with expanded-execute-fn (begin
(map (λ (stx) #`(quote #,stx)) (set->list (collect-unbounds #'expanded-execute-fn))) ; (displayln "expanding!")
; (local-expand #'execute-fn (syntax-local-context) '()))
; #:with (unbound-ids ...)
; (begin
; (displayln "collecting unbounds")
; (map (λ (stx) #`(quote #,stx)) (set->list (collect-unbounds #'expanded-execute-fn))))
(#%module-begin (#%module-begin
(provide execute required-ids) ;(provide required-ids)
(define required-ids (list unbound-ids ...)) ;(define required-ids (list unbound-ids ...))
(provide execute)
(define execute expanded-execute-fn))) (define execute expanded-execute-fn)))