summaryrefslogtreecommitdiffstats
path: root/pkgs
diff options
context:
space:
mode:
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)