Attempt to add resources

This commit is contained in:
Yann Esposito (Yogsototh) 2024-01-16 08:33:44 +01:00
parent 94d9d6127e
commit 698dc9d224
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
4 changed files with 94 additions and 15 deletions

View file

@ -0,0 +1,9 @@
-- img-to-webp.lua
function Image(el)
local fileext = el.src:match("%.[^%.]+$");
-- DEBUG -- print("LUA IMG: ", fileext);
if ( fileext == ".jpg" or fileext == ".png" or fileext == ".jpeg" ) then
el.src = el.src .. ".webp"
end
return el
end

View file

@ -0,0 +1,22 @@
-- intermediate store for variables and their values
local variables = {}
--- Function called for each raw block element.
function RawBlock (raw)
-- Don't do anything unless the block contains *org* markup.
if raw.format ~= 'org' then return nil end
-- extract variable name and value
local name, value = raw.text:match '#%+(%w+):%s*(.+)$'
if name and value then
variables[name] = value
end
end
-- Add the extracted variables to the document's metadata.
function Meta (meta)
for name, value in pairs(variables) do
meta[name] = value
end
return meta
end

View file

@ -0,0 +1,5 @@
-- links-to-html.lua
function Link(el)
el.target = string.gsub(string.gsub(el.target, "%.org", ".html"), "%.html::", ".html#" )
return el
end

73
statyk
View file

@ -36,13 +36,16 @@ exec clojure $OPTS -Sdeps "$DEPS" -M "$0" "$@"
)
(ns statyk
(:require [clojure.tools.cli :refer [parse-opts]]
[clojure.pprint :as pp]
[clojure.string :as string]
[ring.util.mime-type :as mime]
[ring.util.response :as resp]
[babashka.fs :as fs]
[ring.adapter.jetty :refer [run-jetty]]))
(:require
[clojure.java.shell :refer [sh]]
[clojure.tools.cli :refer [parse-opts]]
[clojure.java.io :as io]
[clojure.pprint :as pp]
[clojure.string :as string]
[ring.util.mime-type :as mime]
[ring.util.response :as resp]
[babashka.fs :as fs]
[ring.adapter.jetty :refer [run-jetty]]))
(def config
{:source-directory "_src"
@ -117,9 +120,34 @@ exec clojure $OPTS -Sdeps "$DEPS" -M "$0" "$@"
{:ext ext
:dst-path dst-path}))
(defn build-html
(defn find-org-mode-options
[org]
;; TODO search for options in the org mode file
;; (seek org #"^#+options:")
)
(defn org->html
[src-file dst-file]
(let [options (find-org-mode-options src-file)]
(sh "pandoc"
(when (:toc options) "--toc")
(when-let [tpl (:template options)]
(format "--template=%s" tpl))
"--lua-filter=.statik/org-links-to-html.lua"
"--lua-filter=.statik/img-to-webp.lua"
"--lua-filter=.statik/metas.lua"
"--mathml"
"--from" "org"
"--to" "html5"
"--standalone"
src-file
"--output"
dst-file)))
(defn build-html
[ext src-file dst-file]
;; TODO PANDOC then minify
(sh "pandoc" )
)
(defn build-css
[src-file dst-file]
@ -135,7 +163,7 @@ exec clojure $OPTS -Sdeps "$DEPS" -M "$0" "$@"
"Table with specific commands per type of file"
[src-file dst-file ext]
(cond
(html-src-type? ext) (build-html src-file dst-file)
(html-src-type? ext) (build-html ext src-file dst-file)
(css-src-type? ext) (build-css src-file dst-file)
(img-src-type? ext) (build-img src-file dst-file)
:else (fs/copy src-file dst-file)))
@ -157,13 +185,28 @@ exec clojure $OPTS -Sdeps "$DEPS" -M "$0" "$@"
"- clean delete generated files in _site"]))
(System/exit 0))
(defn cp-resource [resource-name]
(let [dst (str ".statyk/" resource-name)]
(println (format "Generating: %s" dst))
(if-let [resource (io/resource (str "statyk/" resource-name))]
(spit dst (slurp resource))
(err! "Cannot read %s" (io/resource (str "statyk/" resource-name)))
)))
(defn init-site
[options]
(mapv (fn [d]
(println (format "Create dir: %s" d))
(fs/create-dirs d)) [(:source-directory config)
(:dest-directory config)
(:templates-directory config)]))
[_options]
(doseq [d [(:source-directory config)
(:dest-directory config)
(:templates-directory config)
".statyk"]]
(println (format "Create dir: %s" d))
(fs/create-dirs d))
(doseq [f ["org-links-to-html.lua"
"img-to-webp.lua"
"metas.lua"]]
(cp-resource f))
)
(defn -main [& args]
(let [{:keys [options arguments summary errors]