Merge branch 'new-min'
h3rald h3rald@h3rald.com
Mon, 15 Mar 2021 19:39:42 +0100
8 files changed,
54 insertions(+),
44 deletions(-)
M
config.nim
→
config.nim
@@ -1,5 +1,5 @@
const pkgName* = "HastySite" - pkgVersion* = "1.3.5" + pkgVersion* = "1.3.6" pkgDescription* = "A small but powerful static site generator" pkgAuthor* = "Fabio Cevasco"
M
hastysite.nim
→
hastysite.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@@ -77,7 +77,8 @@ const RULES = "./site/rules.min".slurp
var PEG_CSS_VAR_DEF {.threadvar.} : Peg PEG_CSS_VAR_DEF = peg"""'--' {[a-zA-Z0-9_-]+} ':' {@} ';'""" -var PEG_CSS_VAR_INSTANCE {.threadvar.} : Peg + +var PEG_CSS_VAR_INSTANCE {.threadvar.} : Peg PEG_CSS_VAR_INSTANCE = peg""" instance <- 'var(--' {id} ')' id <- [a-zA-Z0-9_-]+@@ -88,7 +89,7 @@ import <- '@import' \s+ '\'' {partial} '\';'
partial <- [a-zA-Z0-9_-]+ """ -var CSS_VARS {.threadvar.} : Table[string, string] +var CSS_VARS {.threadvar.} : Table[string, string] CSS_VARS = initTable[string, string]() #### Helper Functions@@ -209,7 +210,7 @@ result["id"] = %path.changeFileExt("") # output path relative to output without extension
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))@@ -411,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)@@ -427,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)@@ -456,7 +457,7 @@ setLogFilter(lvlNotice)
proc usage(scripts: bool, hs: HastySite): string = var text = """ $1 v$2 - a tiny static site generator - (c) 2016-2018 Fabio Cevasco + (c) 2016-2021 Fabio Cevasco Usage: hastysite command
A
site/contents/posts/v136-released.md
@@ -0,0 +1,9 @@
+----- +id: v136-released +title: "Version 1.3.6 released" +content-type: post +date: "20 March 2021" +timestamp: 1616231032 +----- +* Updated min to v0.35.0 (contains breaking changes to scripts and rules syntax) +* Compiled with Nim v1.4.4
M
site/rules.min
→
site/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/build.min
→
site/scripts/build.min
@@ -1,10 +1,10 @@
;Builds a site by processing contents and assets. 'hastysite import -"Preprocessing..." notice +"Preprocessing..." notice! preprocess -"Processing rules..." notice +"Processing rules..." notice! process-rules -"Postprocessing..." notice +"Postprocessing..." notice! postprocess -"All done." notice +"All done." notice!
M
site/scripts/clean.min
→
site/scripts/clean.min
@@ -1,8 +1,8 @@
;Deletes all temporary and output files. 'hastysite import -"Cleaning temporary folder..." notice +"Cleaning temporary folder..." notice! clean-temp -"Cleaning output folder..." notice +"Cleaning output folder..." notice! clean-output -"All done." notice +"All done." notice!
M
site/scripts/page.min
→
site/scripts/page.min
@@ -4,18 +4,18 @@ "" :title
false :valid-id ( - (string) expect first :ident - ident "^[a-z0-9-]+$" match :valid-regexp - (. "contents") => "/" join ls =filelist + (str) expect first :ident + 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) ( "ID" ask @ident ident validate @valid-id - (valid-id not) ("ID must not be already used and it must contain only lowercase letters, numbers, or -" warn) when + (valid-id not) ("ID must not be already used and it must contain only lowercase letters, numbers, or -" warn!) when ) while "Title" ask @title@@ -28,7 +28,7 @@ -----
" (ident title) => % :metadata -metadata puts +metadata puts! ("Create page?" confirm) ( (ident ".md") => "" join :fn
M
site/scripts/post.min
→
site/scripts/post.min
@@ -6,18 +6,18 @@ ts "d MMMM yyyy" tformat :date
false :valid-id ( - (string) expect first :ident - ident "^[a-z0-9-]+$" match :valid-regexp - (. "contents" "posts") => "/" join ls =filelist + (str) expect first :ident + ident "^[a-z0-9-]+$" match? :valid-regexp + (. "contents" "posts") => "/" join ls :filelist filelist (filename "(.+)\..+$" search 1 get) map ident in? not :valid-file valid-regexp valid-file and -) :validate +) ^validate (valid-id not) ( "ID" ask @ident ident validate @valid-id - (valid-id not) ("ID must not be already used and it must contain only lowercase letters, numbers, or -" warn) when + (valid-id not) ("ID must not be already used and it must contain only lowercase letters, numbers, or -" warn!) when ) while "Title" ask @title@@ -32,7 +32,7 @@ -----
" (ident title date ts) => % :metadata -metadata puts +metadata puts! ("Create post?" confirm) ( (ident ".md") => "" join :fn