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 = [[

tag: {{ name }} ({{ count | int }})

{{ html }} ]] tag_index_template = [[

Tags

]] pages[1] = {} pages[1]['page_file'] = "site/tag/index.html" pages[1]['page_content'] = String.render_template(tag_index_template, res) while current do pages[i+1] = {} pages[i+1]['page_file'] = Sys.join_path("site/tag", current['name'] .. ".html") template = Sys.read_file("templates/tags.html") current['count'] = counts[current['name']] current['html'] = String.render_template(template, current) page_html = String.render_template(page_template, current) pages[i+1]['page_content'] = page_html i = i + 1 current = res['tags'][i] end