-- pages/index.lua -- Index (home) page builder -- Copyright (c) 2020 Joshua 'joshuas3' Stockin -- local utils = require("utils/utils") local git = require("git/git_commands") local builder = require("utils/builder") local tabulate = require("utils/tabulate") local nav = require("utils/nav") local _M = function(repos) local build = builder:new() build:add("
") build:add("

Git Repositories

") build:add("

Index of the git repositories hosted on this server

") build:add("
") build:add("
") local repo_sections = {} for _, repo in pairs(repos) do local section = builder:new() local url = "/"..repo.name local repo_dir = repo.location.dev -- Title and description section:add([[
]]) section:add(string.format([[

%s [more]

]], repo.name, repo.name)) section:add([[

]]..repo.description.."

") -- Latest Commit table local branch = git.get_head(repo_dir) local commit = git.commit(repo_dir, branch.name) section:add(string.format("

Latest Commit (%s)

", branch.name)) local commits_table_data = {} commits_table_data.class = "log" commits_table_data.headers = { {"count", [[{#}]]}, {"timestamp", "Time"}, {"shorthash", "Hash"}, {"subject", "Subject"}, {"author", "Author"}, {"changed_files", [[#]]}, {"changed_plus", [[(+)]]}, {"changed_minus", [[(-)]]}, {"gpggood", [[GPG?]]} } commits_table_data.rows = {{ commit.count, utils.iso8601(commit.timestamp), string.format([[%s]], repo.name, commit.hash, commit.shorthash), utils.html_sanitize(commit.subject), string.format([[%s]], commit.email, utils.html_sanitize(commit.author)), commit.diff.num, commit.diff.plus, commit.diff.minus, commit.gpggood }} section:add(tabulate(commits_table_data)) -- Navigation links local navlinks = { {string.format("/%s/download", repo.name), "Download"}, {string.format("/%s/refs", repo.name), "Refs"}, {string.format("/%s/log/%s", repo.name, branch.name), "Commit Log"}, {string.format("/%s/tree/%s", repo.name, branch.name), "Files"} } for _, special in pairs(repo.specialfiles) do -- create nav items for special files local split = string.split(special, " ") table.insert(navlinks, { string.format("/%s/blob/%s/%s", repo.name, branch.name, split[2]), split[1] }) end section:add([[") -- nav section:add("
") -- repo-section table.insert(repo_sections, section.body) end -- Format repo sections build:add(table.concat(repo_sections, "
")) build:add("
") return build end return _M