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