summaryrefslogtreecommitdiffstats
path: root/pkgs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-18 11:51:38 +0000
committertv <tv@krebsco.de>2026-11-18 12:52:08 +0100
commit3d57242810feab10c11cd1df66a7c2958869497f (patch)
tree07d46960c3e4685597f09c921f91718758d413ef /pkgs
parentac6ec0d3a636514e854947d523c128ae59361143 (diff)
cgit-about-filter: link symbol after headings
A chain link after each heading links to it, so the link can be copied. It shows when the heading is hovered or focused, and always on devices without hover.
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/simple/cgit-about-filter/cgit-about-filter.lua14
1 files changed, 13 insertions, 1 deletions
diff --git a/pkgs/simple/cgit-about-filter/cgit-about-filter.lua b/pkgs/simple/cgit-about-filter/cgit-about-filter.lua
index 0833c38..f317c54 100644
--- a/pkgs/simple/cgit-about-filter/cgit-about-filter.lua
+++ b/pkgs/simple/cgit-about-filter/cgit-about-filter.lua
@@ -227,6 +227,17 @@ local function slug(content)
return (text:lower():gsub("[^%w%s_%-\128-\255]", ""):gsub("%s", "-"))
end
+-- A chain link, after each heading, linking to it.
+local anchor = [[<a class="anchor" href="#%s" aria-label="Link to this section"><svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="1.5" transform="rotate(-45 8 8)"><rect x="1" y="5.5" width="8" height="5" rx="2.5"/><rect x="7" y="5.5" width="8" height="5" rx="2.5"/></g></svg></a>]]
+
+local anchor_style = [[
+<style>
+div#summary a.anchor { color: #888; margin-left: 0.3em; opacity: 0; }
+div#summary :is(h1, h2, h3, h4, h5, h6):is(:hover, :focus-within) a.anchor { opacity: 1; }
+@media (hover: none) { div#summary a.anchor { opacity: 1; } }
+</style>
+]]
+
-- Give headings ids, so links to #fragments work. A repeated id gets -1,
-- -2, etc., and so do ids cgit uses on the about page itself.
local function heading_ids(output)
@@ -242,7 +253,7 @@ local function heading_ids(output)
else
seen[id] = 0
end
- return string.format('<h%s id="%s">%s</h%s>', level, id, content, level)
+ return string.format('<h%s id="%s">%s' .. anchor .. '</h%s>', level, id, content, id, level)
end))
end
@@ -410,6 +421,7 @@ local function close()
output = heading_ids(output)
if output:find('<h%d id="') then
emit(target_style)
+ emit(anchor_style)
end
if output:find("<table>", 1, true) then
emit(table_style)