summaryrefslogtreecommitdiff
path: root/.zs/styles
diff options
context:
space:
mode:
Diffstat (limited to '.zs/styles')
-rwxr-xr-x.zs/styles58
1 files changed, 48 insertions, 10 deletions
diff --git a/.zs/styles b/.zs/styles
index c51a369..bbe31ba 100755
--- a/.zs/styles
+++ b/.zs/styles
@@ -1,14 +1,52 @@
-#!/bin/sh
+#!/usr/bin/lua
-set -e
+---@class Stylesheet
+---@field name string
+---@field lazy? boolean
-CSS="reset main"
-CSS_ZS_FILE=$(echo $ZS_FILE | sed -e 's/.[^.]*$/.css/')
+---@type Stylesheet[]
+local stylesheets = {
+ {
+ name = "reset",
+ },
+ {
+ name = "main",
+ },
+ {
+ name = "content",
+ lazy = true
+ },
+ {
+ name = "deco",
+ lazy = true
+ }
+}
-for css in $CSS; do
- printf "<link rel=\"stylesheet\" href=\"/assets/css/%s.css\">\n" "$css"
-done
+---@param path string
+---@return string, integer
+local function get_file_stem(path)
+ return path
+ :gsub(".[^.]*$", "") -- get rid of ext
+ :gsub(".*/", "") -- get rid of prefix
+end
-if [ -f $(printf "assets/css/%s" "$CSS_ZS_FILE") ]; then
- printf "<link rel=\"stylesheet\" href=\"/assets/css/%s\">\n" "$CSS_ZS_FILE"
-fi
+local current_path = assert(os.getenv("ZS_FILE"))
+local current_file = get_file_stem(current_path)
+
+local f = io.open("assets/css/" .. current_file .. ".page.css")
+if f ~= nil then
+ f:close()
+ table.insert(stylesheets, {
+ name = current_file .. ".page"
+ })
+end
+
+for _, stylesheet in ipairs(stylesheets) do
+ local content = [[link rel="stylesheet" href="/assets/css/]] .. stylesheet.name .. [[.css"]]
+ if stylesheet.lazy then
+ print("<" .. content .. [[ media="print" onload="this.media='all'; this.onload = null">]])
+ print("<noscript><" .. content .. "></noscript>")
+ else
+ print("<" .. content .. ">")
+ end
+end