all repos — hastysite @ 756c24587761161a50f28e852a05fc7af4257716

A high-performance static site generator.

Fixes.
h3rald h3rald@h3rald.com
Fri, 12 Mar 2021 20:00:02 +0100
commit

756c24587761161a50f28e852a05fc7af4257716

parent

5568a15557fe5a329b9ac9430631279d92a85698

3 files changed, 33 insertions(+), 28 deletions(-)

jump to
M hastysite.nimhastysite.nim

@@ -17,7 +17,7 @@ {.passL:"-static".}

import packages/min/min, - packages/min/packages/niftylogger, + packages/min/minpkg/packages/niftylogger, packages/hastyscribe/src/hastyscribe, packages/moustachu/src/moustachu

@@ -75,17 +75,22 @@ const STYLE_LUXBAR = "./site/assets/styles/luxbar.css".slurp

const STYLE_SITE = "./site/assets/styles/site.css".slurp const RULES = "./site/rules.min".slurp -let PEG_CSS_VAR_DEF = peg"""'--' {[a-zA-Z0-9_-]+} ':' {@} ';'""" -let PEG_CSS_VAR_INSTANCE = peg""" +var PEG_CSS_VAR_DEF {.threadvar.} : Peg +PEG_CSS_VAR_DEF = peg"""'--' {[a-zA-Z0-9_-]+} ':' {@} ';'""" + +var PEG_CSS_VAR_INSTANCE {.threadvar.} : Peg +PEG_CSS_VAR_INSTANCE = peg""" instance <- 'var(--' {id} ')' id <- [a-zA-Z0-9_-]+ """ -let PEG_CSS_IMPORT = peg""" +var PEG_CSS_IMPORT {.threadvar.} : Peg +PEG_CSS_IMPORT = peg""" import <- '@import' \s+ '\'' {partial} '\';' partial <- [a-zA-Z0-9_-]+ """ -var CSS_VARS = initTable[string, string]() +var CSS_VARS {.threadvar.} : Table[string, string] +CSS_VARS = initTable[string, string]() #### Helper Functions

@@ -203,9 +208,9 @@ result["id"] = %path

else: result["id"] = %path.changeFileExt("") # output path relative to output without extension -proc hastysite_module*(i: In, hs1: HastySite) +proc hastysite_module*(i: In, hs1: HastySite) {.gcsafe.} -proc interpret(hs: HastySite, file: string) = +proc interpret(hs: HastySite, file: string) {.gcsafe.} = var i = newMinInterpreter(file, file.parentDir) i.hastysite_module(hs) i.interpret(newFileStream(file, fmRead))

@@ -407,14 +412,14 @@ outfile.parentDir.createDir

copyFileWithPermissions(infile, outfile) def.symbol("preprocess-css") do (i: In) {.gcsafe.}: - var vals = i.expect("string") + var vals = i.expect("str") let css = vals[0] var res = css.getString.processCssImportPartials(hs) res = res.processCssVariables() i.push res.newVal() def.symbol("mustache") do (i: In): - var vals = i.expect(["dict", "string"]) + var vals = i.expect(["dict", "str"]) let c = vals[0] let t = vals[1] let ctx = newContext(i%c)

@@ -423,7 +428,7 @@ let tpl = readFile(hs.dirs.templates/tplname)

i.push tpl.render(ctx, hs.dirs.templates).newval def.symbol("markdown") do (i: In) {.gcsafe.}: - var vals = i.expect(["dict", "string"]) + var vals = i.expect(["dict", "str"]) let c = vals[0] let t = vals[1] let options = HastyOptions(toc: false, output: "", css: "", watermark: "", fragment: true)
M site/rules.minsite/rules.min

@@ -2,7 +2,7 @@ 'hastysite import

;Routing ( - (dict) expect -> =meta + (dict) expect -> :meta meta /id :id meta /ext :ext (

@@ -19,50 +19,50 @@ ("$1/index" (id) => % %id)

) tap )) ) case -) :set-destination +) ^set-destination ;Process Markdown content ( - (dict) expect -> =meta + (dict) expect -> :meta "" :page "" :contents meta /content-type :tpl meta ( (input-fread @contents meta) (settings /title %site-title) - (=temp contents temp markdown @contents temp) + (:temp contents temp markdown @contents temp) (contents %contents) - (=temp tpl temp mustache @page temp) + (:temp tpl temp mustache @page temp) (page %contents) ) tap -) :process-content +) ^process-content ;Process CSS asset ( - (dict) expect -> =meta + (dict) expect -> :meta "" :contents meta ( (input-fread @contents meta) - (=temp contents preprocess-css @contents temp) + (:temp contents preprocess-css @contents temp) (contents %contents) ) tap output-fwrite -) :process-css-asset +) ^process-css-asset ;;; Main ;;; ;Filter and sort posts by timestamp contents - (?content-type) filter + ('content-type dhas?) filter (/content-type "post" ==) filter - (=a =b a /timestamp b /timestamp >) sort =posts + (:a :b a /timestamp b /timestamp >) sort :posts ;Process contents contents ( - (dict) expect -> =content - content (/id "news" ==) (content posts %posts #content) when + (dict) expect -> :content + content (/id "news" ==) (content posts %posts @content) when ( - ((content /id "/" split last "^[._]" match) ()) ;Ignore files starting with a dot or underscore + ((content /id "/" split last "^[._]" match?) ()) ;Ignore files starting with a dot or underscore ((true) (content process-content set-destination output-fwrite)) ) case ) foreach

@@ -72,8 +72,8 @@ assets (

(dict) expect -> dup ( - ((/ext ".css" match) (process-css-asset)) - ((/id "/" split last "^[._]" match) ()) ;Ignore files starting with a dot or underscore + ((/ext ".css" match?) (process-css-asset)) + ((/id "/" split last "^[._]" match?) ()) ;Ignore files starting with a dot or underscore ((true) (output-cp)) ) case ) foreach
M site/scripts/page.minsite/scripts/page.min

@@ -5,11 +5,11 @@ false :valid-id

( (string) expect first :ident - ident "^[a-z0-9-]+$" match :valid-regexp + ident "^[a-z0-9-]+$" match? :valid-regexp (. "contents") => "/" join ls =filelist filelist (filename "(.+)\..+$" search 1 get) map ident in? not :valid-file valid-regexp valid-file and -) :validate +) ^validate (valid-id not) (