Index

joshstock.in / 8147f6b

Source for serving and static templating/compiling of https://joshstock.in.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
9712 Dec 2020 21:058147f6bUpdate lua-gitwebJosh Stockin133G

Blob @ joshstock.in / lua-gitweb / pages / download.lua

text/plain2385 bytesdownload raw
1-- pages/download.lua
2-- Download page builder
3
4-- Copyright (c) 2020 Joshua 'joshuas3' Stockin
5-- <https://joshstock.in>
6
7local utils = require("utils/utils")
8local git = require("git/git_commands")
9
10local builder = require("utils/builder")
11local tabulate = require("utils/tabulate")
12local nav = require("utils/nav")
13
14local _M = function(repo, repo_dir, branch)
15 local build = builder:new()
16
17 -- Breadcrumb navigation and repository description
18 local breadcrumb_nav = {
19 {string.format("/%s", repo.name), repo.name},
20 {string.format("/%s/download", repo.name), "download"},
21 }
22 build:add("<h2>"..nav(breadcrumb_nav, " / ").."</h2>")
23 build:add("<p>"..repo.description.."</p>")
24
25 -- Navigation links
26 local navlinks = {
27 {string.format("/%s/download", repo.name), "<b>Download</b>"},
28 {string.format("/%s/refs", repo.name), "Refs"},
29 {string.format("/%s/log/%s", repo.name, branch.name), "Commit Log"},
30 {string.format("/%s/tree/%s", repo.name, branch.name), "Files"}
31 }
32
33 for _, special in pairs(repo.specialfiles) do -- create nav items for special files
34 local split = string.split(special, " ")
35 table.insert(navlinks, {
36 string.format("/%s/blob/%s/%s", repo.name, branch.name, split[2]),
37 split[1]
38 })
39 end
40
41 build:add([[<div class="nav">]])
42 build:add(nav(navlinks))
43 build:add("</div>")
44
45 -- Download URLs
46 build:add("<h3>Download URLs</h3>")
47
48 local urls = {}
49 urls.class = "download-urls"
50 urls.headers = {
51 {"protocol", "Protocol"},
52 {"url", "URL"}
53 }
54 urls.rows = {}
55
56 for _, url in pairs(repo.download) do
57 local split = string.split(url, " ")
58 table.insert(urls.rows, {split[1], string.format([[<a href="%s">%s</a>]], split[2], split[2])})
59 end
60
61 build:add(tabulate(urls))
62
63 -- Websites
64 build:add("<h3>Websites</h3>")
65
66 local sites = {}
67 sites.class = "websites"
68 sites.headers = {
69 {"name", "Website"},
70 {"url", "URL"}
71 }
72 sites.rows = {}
73
74 for _, site in pairs(repo.urls) do
75 local split = string.split(site, " ")
76 table.insert(sites.rows, {split[1], string.format([[<a href="%s">%s</a>]], split[2], split[2])})
77 end
78
79 build:add(tabulate(sites))
80
81 return build
82end
83
84return _M
85