~h3rald/hastysite

28fed70b2c947529e60f0a2e3e40aed7d887a2e2 — h3rald a month ago d5e8008 master
Updates.
M hastysitepkg/config.nim => hastysitepkg/config.nim +1 -1
@@ 1,5 1,5 @@
const
  pkgName* = "HastySite"
  pkgVersion* = "1.3.11"
  pkgVersion* = "1.4.0"
  pkgDescription* = "A small but powerful static site generator"
  pkgAuthor* = "Fabio Cevasco"

A site/contents/posts/v140-released.md => site/contents/posts/v140-released.md +9 -0
@@ 0,0 1,9 @@
-----
id: v140-released
title: "v1.4.0 released"
content-type: post
date: "19 October 2024"
timestamp: 1729372536
-----

Upgraded min to v0.45.0.

M site/rules.min => site/rules.min +22 -22
@@ 3,19 3,19 @@
;Routing
(
  (dict) expect -> :meta
  meta /id :id
  meta /ext :ext
  meta "id" dict.get :id
  meta "ext" dict.get :ext
  (
    ((id "home" ==) (
      meta (
        ("index" %id)
        (".html" %ext)
        ("index" "id" dict.set)
        (".html" "ext" dict.set)
      ) tap
    ))
    ((true) (
      meta (
        (".html" %ext)
        ("$1/index" (id) => % %id)
        (".html" "ext" dict.set)
        ("$1/index" (id) => % "id" dict.set)
      ) tap
    ))
  ) case


@@ 26,14 26,14 @@
  (dict) expect -> :meta
  "" :page
  "" :contents
  meta /content-type :tpl
  meta "content-type" dict.get :tpl
  meta (
    (input-fread @contents meta)
    (settings /title %site-title)
    (settings "title" dict.get "site-title" dict.set)
    (:temp contents temp markdown @contents temp)
    (contents %contents)
    (contents "contents" dict.set)
    (:temp tpl temp mustache @page temp)
    (page %contents)
    (page "contents" dict.set)
  ) tap
) ^process-content



@@ 44,36 44,36 @@
  meta (
    (input-fread @contents meta)
    (:temp contents preprocess-css @contents temp)
    (contents %contents)
    (contents "contents" dict.set)
  ) tap
  output-fwrite
) ^process-css-asset

;;; Main ;;;

;Filter and sort posts by timestamp
;;Filter and sort posts by timestamp
contents 
  ('content-type dhas?) filter
  (/content-type "post" ==) filter 
  (:a :b a /timestamp  b /timestamp >) sort :posts
  ('content-type dict.has?) filter
  ("content-type" dict.get "post" ==) filter 
  (:a :b a "timestamp" dict.get  b "timestamp" dict.get >) sort :posts

;Process contents
;;Process contents
contents (
  (dict) expect -> :content
  content (/id "news" ==) (content posts %posts @content) when
  content ("id" dict.get "news" ==) (content posts "posts" dict.set @content) when
  (
    ((content /id "/" split last "^[._]" match?) ()) ;Ignore files starting with a dot or underscore
    ((content "id" dict.get "/" split last "^[._]" match?) ()) ;;Ignore files starting with a dot or underscore
    ((true) (content process-content set-destination output-fwrite))
  ) case
) foreach

;Process assets
;;Process assets
assets (
  (dict) expect -> 
  dup
  stack.dup
  (
    ((/ext ".css" match?) (process-css-asset))
    ((/id "/" split last "^[._]" match?) ()) ;Ignore files starting with a dot or underscore
    (("ext" dict.get ".css" match?) (process-css-asset))
    (("id" dict.get "/" 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 +4 -4
@@ 1,10 1,10 @@
;Builds a site by processing contents and assets.
'hastysite import

"Preprocessing..." notice!
"Preprocessing..." io.notice!
preprocess
"Processing rules..." notice!
"Processing rules..." io.notice!
process-rules
"Postprocessing..." notice!
"Postprocessing..." io.notice!
postprocess
"All done." notice!
"All done." io.notice!

M site/scripts/clean.min => site/scripts/clean.min +3 -3
@@ 1,8 1,8 @@
;Deletes all temporary and output files.
'hastysite import

"Cleaning temporary folder..." notice!
"Cleaning temporary folder..." io.notice!
clean-temp
"Cleaning output folder..." notice!
"Cleaning output folder..." io.notice!
clean-output
"All done." notice!
"All done." io.notice!

M site/scripts/page.min => site/scripts/page.min +9 -15
@@ 6,33 6,27 @@ false   :valid-id
(
  (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
  (sys.pwd "contents") => "/" join sys.ls :filelist
  filelist (fs.filename "(.+)\\..+$" search 1 get) map ident in? not :valid-file
  valid-regexp valid-file and
) ^validate


(valid-id not) (
  "ID" ask @ident
  "ID" io.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 -" io.warn!) when
) while

"Title" ask @title
"Title" io.ask @title

"-----
id: $1
title: \"$2\"
content-type: page
-----

" (ident title) => % :metadata
"-----\nid: $1\ntitle: \"$2\"\ncontent-type: page\n-----\n\n" (ident title) => % :metadata

metadata puts!
("Create page?" confirm) 
("Create page?" io.confirm) 
(
  (ident ".md") => "" join :fn 
  (. "contents") => "/" join :dirpath
  (sys.pwd "contents") => "/" join :dirpath
  (dirpath fn) => "/" join :path
  metadata path fwrite
  metadata path fs.write
) when

M site/scripts/post.min => site/scripts/post.min +12 -20
@@ 1,43 1,35 @@
;Creates a new empty post.
""                        :ident
""                        :title
timestamp                 :ts
ts "d MMMM yyyy" tformat  :date
time.stamp                 :ts
ts "d MMMM yyyy" time.format  :date
false     :valid-id

(
  (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
  (sys.pwd "contents" "posts") => "/" join sys.ls :filelist
  filelist (fs.filename "(.+)\\..+$" search 1 get) map ident in? not :valid-file
  valid-regexp valid-file and
) ^validate


(valid-id not) (
  "ID" ask @ident
  "ID" io.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 -" io.warn!) when
) while

"Title" ask @title
"Title" io.ask @title

"-----
id: $1
title: \"$2\"
content-type: post
date: \"$3\"
timestamp: $4
-----

" (ident title date ts) => % :metadata
"-----\nid: $1\ntitle: \"$2\"\ncontent-type: post\ndate: \"$3\"\ntimestamp: $4\n-----\n\n" (ident title date ts) => % :metadata

metadata puts!
("Create post?" confirm) 
("Create post?" io.confirm) 
(
  (ident ".md") => "" join :fn 
  (. "contents" "posts") => "/" join :dirpath
  (dirpath exists? not) (dirpath mkdir) when
  (sys.pwd "contents" "posts") => "/" join :dirpath
  (dirpath fs.exists? not) (dirpath sys.mkdir) when
  (dirpath fn) => "/" join :path
  metadata path fwrite
  metadata path fs.write
) when