summaryrefslogtreecommitdiffstats
path: root/plugins/tags-index.lua
blob: 75c7f6bc27945d6517ba917a04c13955aebff2ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
counts = {}
env = {}

function append_entry(entry)
  if entry["tags"] then
    i, tag = next(entry["tags"])

    while i do
      if not counts[tag] then
        env[tag] = {}
        counts[tag] = 1
      else
        counts[tag] = counts[tag] + 1
      end

      env[tag][counts[tag]] = entry

      i, tag = next(entry["tags"], i)
    end

    index, entry = next(site_index, index)
  end
end

Table.iter_values_ordered(append_entry, site_index)

tags = {}
tag_count = 1

function append_template_value (tag, entry_list)
  entry = {}
  entry['name'] = tag
  entry['contents'] = env[tag]
  tags[tag_count] = entry
  tag_count = tag_count + 1
end

Table.iter_ordered(append_template_value, env)

res = {}
res['tags'] = tags

template = Sys.read_file(config["index_template_file"])
rendered_entries = HTML.parse(String.render_template(template, res))

container = HTML.select_one(page, config["index_selector"])
HTML.replace_content(container, rendered_entries)

pages = {}
i = 1
current = res['tags'][i]

page_template = [[
<h1><span class="icon"><svg><use href="/img/icons.svg#tag"></use></svg></span> <code>{{ name }}</code></h2>
<article class="index" id="tags-index">
  {{ html }}
</article>
]]

while current  do
  pages[i] = {}
  pages[i]['page_file'] = Sys.join_path(Sys.dirname(page_file), current['name'] .. ".html")

  template = Sys.read_file("templates/index_archives_full.html")
  current['html'] = String.render_template(template, current)
  page_html = String.render_template(page_template, current)

  pages[i]['page_content'] = page_html

  i = i + 1
  current = res['tags'][i]
end