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{ |
24 | build.h2{nav(breadcrumb_nav, " / ")}, |
25 | build.p{repo.description} |
26 | } |
27 |
|
28 | -- Navigation links |
29 | local navlinks = { |
30 | {string.format("/%s/download", repo.name), "<b>Download</b>"}, |
31 | {string.format("/%s/refs", repo.name), "Refs"}, |
32 | {string.format("/%s/log/%s", repo.name, branch.name), "Commit Log"}, |
33 | {string.format("/%s/tree/%s", repo.name, branch.name), "Files"} |
34 | } |
35 |
|
36 | for _, special in pairs(repo.specialfiles) do -- create nav items for special files |
37 | local split = string.split(special, " ") |
38 | table.insert(navlinks, { |
39 | string.format("/%s/blob/%s/%s", repo.name, branch.name, split[2]), |
40 | split[1] |
41 | }) |
42 | end |
43 |
|
44 | build{ |
45 | build.div{class="nav", nav(navlinks)}, |
46 | build.h3{"Download URLs"} |
47 | } |
48 |
|
49 | -- Download URLs |
50 | local urls = {} |
51 | urls.class = "download-urls" |
52 | urls.headers = { |
53 | {"protocol", "Protocol"}, |
54 | {"url", "URL"} |
55 | } |
56 | urls.rows = {} |
57 |
|
58 | for _, url in pairs(repo.download) do |
59 | local split = string.split(url, " ") |
60 | table.insert(urls.rows, {split[1], string.format([[<a href="%s">%s</a>]], split[2], split[2])}) |
61 | end |
62 |
|
63 | build{tabulate(urls)} |
64 |
|
65 | -- Websites |
66 | build{build.h3{"Websites"}} |
67 |
|
68 | local sites = {} |
69 | sites.class = "websites" |
70 | sites.headers = { |
71 | {"name", "Website"}, |
72 | {"url", "URL"} |
73 | } |
74 | sites.rows = {} |
75 |
|
76 | for _, site in pairs(repo.urls) do |
77 | local split = string.split(site, " ") |
78 | table.insert(sites.rows, {split[1], string.format([[<a href="%s">%s</a>]], split[2], split[2])}) |
79 | end |
80 |
|
81 | build{tabulate(sites)} |
82 |
|
83 | return build |
84 | end |
85 |
|
86 | return _M |
87 |
|