main
 1-- strip-old-css.lua — Remove old stylesheet links before injecting new ones
 2-- Strips: tufte.css, ox-tufte.css, 2022.css, new.css, syntax.css, custom.css
 3-- Keeps: our /style.css (injected by inject-css widget)
 4
 5links = HTML.select(page, "link[rel=\"stylesheet\"]")
 6i = 1
 7while links[i] do
 8  href = HTML.get_attribute(links[i], "href")
 9  if href then
10    -- Remove if it's an old stylesheet (not our /style.css)
11    is_old = Regex.match(href, "tufte\\.css")
12    if not is_old then is_old = Regex.match(href, "ox-tufte\\.css") end
13    if not is_old then is_old = Regex.match(href, "2022\\.css") end
14    if not is_old then is_old = Regex.match(href, "new\\.css") end
15    if not is_old then is_old = Regex.match(href, "syntax\\.css") end
16    if not is_old then is_old = Regex.match(href, "custom\\.css") end
17    if is_old then
18      HTML.delete(links[i])
19    end
20  end
21  i = i + 1
22end
23
24-- Also remove old favicon links (we'll add our own later if needed)
25icons = HTML.select(page, "link[rel=\"icon\"]")
26i = 1
27while icons[i] do
28  HTML.delete(icons[i])
29  i = i + 1
30end