play with metas and color theme html

This commit is contained in:
Yann Esposito (Yogsototh) 2021-10-03 22:20:41 +02:00
parent 5e7bca80ad
commit 370e0a6ee7
Signed by untrusted user who does not match committer: yogsototh
GPG Key ID: 7B19A4C650D59646
6 changed files with 37 additions and 6 deletions

View File

@ -48,9 +48,10 @@ DST_PANDOC_FILES ?= $(patsubst %$(EXT),%.html, \
PANDOC_TEMPLATE ?= templates/post.html
PANDOC_LUA_FILTER ?= engine/links-to-html.lua
PANDOC_LUA_FILTER_IMG ?= engine/img-to-webp.lua
PANDOC_LUA_METAS ?= engine/metas.lua
MK_HTML := engine/mk-html.sh
PANDOC := $(MK_HTML) $(PANDOC_TEMPLATE) $(PANDOC_LUA_FILTER) $(PANDOC_LUA_FILTER_IMG)
$(DST_DIR)/%.html: $(SRC_DIR)/%.org $(PANDOC_TEMPLATE) $(PANDOC_LUA_FILTER) $(PANDOC_LUA_FILTER_IMG) $(MK_HTML) $(ENV_VARS)
PANDOC := $(MK_HTML) $(PANDOC_TEMPLATE) $(PANDOC_LUA_FILTER) $(PANDOC_LUA_FILTER_IMG) $(PANDOC_LUA_METAS)
$(DST_DIR)/%.html: $(SRC_DIR)/%.org $(PANDOC_TEMPLATE) $(PANDOC_LUA_FILTER) $(PANDOC_LUA_FILTER_IMG) $(PANDOC_LUA_METAS) $(MK_HTML) $(ENV_VARS)
@mkdir -p "$(dir $@)"
$(PANDOC) "$<" "$@.tmp"
minify --mime text/html "$@.tmp" > "$@"

22
engine/metas.lua Normal file
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

@ -5,8 +5,9 @@ cd "$(git rev-parse --show-toplevel)" || exit 1
template="$1"
luafilter="$2"
luafilterimg="$3"
orgfile="$4"
htmlfile="$5"
luametas="$4"
orgfile="$5"
htmlfile="$6"
tocoption=""
if grep -ie '^#+options:' "$orgfile" | grep 'toc:t'>/dev/null; then
@ -18,6 +19,7 @@ pandoc $tocoption \
--template="$template" \
--lua-filter="$luafilter" \
--lua-filter="$luafilterimg" \
--lua-filter="$luametas" \
--mathml \
--from org \
--to html5 \

View File

@ -14,6 +14,8 @@
#+lang: en
#+options: auto-id:t
#+startup: showeverything
#+lightbk: #ff0
#+darkbk: #880
#+html_head_extra: <style>
#+html_head_extra: :root { --bg: #ff0; --fg: #000; }
#+html_head_extra: img,svg {filter: contrast(0.5)sepia(100%)hue-rotate(20deg)saturate(15); }

View File

@ -7,10 +7,11 @@
<meta name="author" content="$author$">
<meta name="description" content="$description$">
<meta name="keywords" content="$keywords$">
<meta name="theme-color" content="#d84100">
<link rel="stylesheet" href="/css/y.css"/>
<link rel="alternate" type="application/rss+xml" href="/rss.xml" />
<link rel="icon" href="/favicon.ico">
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#d84100">
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#2E3440">
$header-includes$
</head>
<body>

View File

@ -7,10 +7,13 @@
<meta name="author" content="$author$">
<meta name="description" content="$description$">
<meta name="keywords" content="$keywords$">
<meta name="theme-color" content="#d84100">
<link rel="stylesheet" href="/css/y.css"/>
<link rel="alternate" type="application/rss+xml" href="/rss.xml" />
<link rel="icon" href="/favicon.ico">
<meta name="theme-color" media="(prefers-color-scheme: light)"
content=$if(lightbk)$"$lightbk$"$else$"#d84100"$endif$>
<meta name="theme-color" media="(prefers-color-scheme: dark)"
content=$if(darkbk)$"$darkbk$"$else$"#2E3440"$endif$>
$header-includes$
</head>
<body>