add the ability to include in templates

This commit is contained in:
xenia 2021-06-08 05:12:07 -04:00
parent 6df697cf26
commit 7419859ffb
4 changed files with 24 additions and 7 deletions

View File

@ -114,10 +114,12 @@
(with-output-to-string (λ () (display "<!doctype html>") (display-xexpr document))))) (with-output-to-string (λ () (display "<!doctype html>") (display-xexpr document)))))
(define (compile-index-scss) (define (compile-index-scss index.scss)
(define scss-files (append mathml:scss-files syntax:scss-files)) (define scss-files (append mathml:scss-files syntax:scss-files))
(define top-level-style (define top-level-style
(string-join (map (λ (x) (format "@import \"~a\";" (path->string x))) scss-files) "\n")) (string-join
(cons index.scss (map (λ (x) (format "@import \"~a\";" (path->string x))) scss-files))
"\n"))
(sass:compile/string top-level-style #t)) (sass:compile/string top-level-style #t))
(module+ main (module+ main
@ -125,8 +127,8 @@
(command-line (command-line
#:program "meow" #:program "meow"
#:args (infile outfile) #:args (infile outfile)
(define-rule (scss [out "index.css"]) (define-rule (scss [out "index.css"] [in "index.scss"])
(~> (compile-index-scss) (write-string out))) (~> (compile-index-scss (port->string in)) (write-string out)))
(define-rule (render [out outfile] [in infile]) (define-rule (render [out outfile] [in infile])
(~> (read-input-doc in) input-doc->ir-doc ir-doc->page (write-string out))) (~> (read-input-doc in) input-doc->ir-doc ir-doc->page (write-string out)))
(generate/execute (list render scss)))) (generate/execute (list render scss))))

View File

@ -0,0 +1,5 @@
#lang s-exp "../xtemplate.rkt"
`(p ()
"this was included from another file #uwu the summary is: "
,(or (metadata-ref+ metadata 'summary) "no summary :("))

View File

@ -31,7 +31,8 @@
,content-toc) ,content-toc)
(main (main
() ()
,@content) ,@content
,(include "include.html.rkt"))
;; mathjax polyfill script sentinel -- gets replaced by a script tag for crying doge chrombe ;; mathjax polyfill script sentinel -- gets replaced by a script tag for crying doge chrombe
;; and with nothing for swole firefox ;; and with nothing for swole firefox
(div ([style "display: none"]) "__X_MATHJAX_POLYFILL_PLACEHOLDER__"))) (div ([style "display: none"]) "__X_MATHJAX_POLYFILL_PLACEHOLDER__")))

View File

@ -1,12 +1,14 @@
#lang racket/base #lang racket/base
(require racket/base racket/format racket/list racket/match racket/string (require racket/base racket/format racket/list racket/match racket/runtime-path racket/string
racket/splicing
"defs.rkt" "util.rkt" "defs.rkt" "util.rkt"
syntax/parse syntax/parse/define racket/stxparam syntax/parse syntax/parse/define racket/stxparam
(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]
[x:include include])
(except-out (all-from-out racket/base racket/format racket/list racket/match racket/string (except-out (all-from-out racket/base racket/format racket/list racket/match racket/string
"defs.rkt" "util.rkt") "defs.rkt" "util.rkt")
#%module-begin #%top)) #%module-begin #%top))
@ -20,6 +22,13 @@
(syntax->datum #'id))] (syntax->datum #'id))]
(hash-ref tem 'id)) (hash-ref tem 'id))
(define-syntax-parse-rule (x:include what:string)
#:with tem:id (syntax-parameter-value #'template-id)
#:with execute-temp:id (car (generate-temporaries '(included-execute)))
#:with execute-fn
(syntax-local-lift-require #`(rename what execute-temp execute) #'execute-temp)
(execute-fn tem))
(define-syntax-parse-rule (x:#%module-begin body) (define-syntax-parse-rule (x:#%module-begin body)
(#%module-begin (#%module-begin
(provide execute required-keys) (provide execute required-keys)