main
 1-- link-timestamps.lua — Make org timestamps link to flux year archives
 2--
 3-- Before: <span class="timestamp-wrapper"><time class="timestamp" datetime="2026-02-03">&lt;2026-02-03 Tue&gt;</time></span>
 4-- After:  <span class="timestamp-wrapper"><a href="/flux/2026.html" class="timestamp-link"><time ...>2026-02-03</time></a></span>
 5--
 6-- Also cleans up the display: removes angle brackets, day name
 7
 8timestamps = HTML.select(page, "span.timestamp-wrapper")
 9i = 1
10while timestamps[i] do
11  wrapper = timestamps[i]
12
13  time_el = HTML.select_one(wrapper, "time.timestamp")
14  if time_el then
15    dt = HTML.get_attribute(time_el, "datetime")
16    if dt then
17      -- Extract year
18      year = Regex.find_all(dt, "^[0-9][0-9][0-9][0-9]")
19      if year[1] then
20        -- Clean up display text: just show YYYY-MM-DD
21        HTML.delete_content(time_el)
22        HTML.append_child(time_el, HTML.create_text(dt))
23
24        -- Wrap time element in a link to the year archive
25        link = HTML.create_element("a")
26        HTML.set_attribute(link, "href", "/flux/" .. year[1] .. ".html")
27        HTML.set_attribute(link, "class", "timestamp-link")
28
29        -- Move time_el into link, then put link into wrapper
30        HTML.delete_content(wrapper)
31        HTML.append_child(link, time_el)
32        HTML.append_child(wrapper, link)
33      end
34    end
35  end
36
37  i = i + 1
38end