Index

joshstock.in / 009440a

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
9612 Dec 2020 20:23009440aUpdate lua-gitwebJosh Stockin17056G

Blob @ joshstock.in / lua-gitweb / app.lua

text/plain4597 bytesdownload raw
1-- app.lua
2-- Entry point for git HTTP site implementation
3
4-- Copyright (c) 2020 Joshua 'joshuas3' Stockin
5-- <https://joshstock.in>
6
7local utils = require("utils/utils")
8local git = require("git/git_commands")
9local request = require("utils/parse_uri")
10
11local parsed_uri = request.parse_uri()
12local content
13
14if parsed_uri.repo == nil then
15 content = require("pages/index")(yaml_config)
16else -- repo found
17 local repo
18 for _,r in pairs(yaml_config) do
19 if parsed_uri.repo == r.name then
20 repo = r
21 break
22 end
23 end
24 if repo then
25 local repo_dir = repo.location.dev
26 local view = parsed_uri.parts[2] or "tree"
27 local branch
28
29 if pcall(function() -- if branch is real
30 branch = git.get_head(repo_dir, parsed_uri.parts[3]) -- if parts[3] is nil, defaults to "HEAD"
31 end) then
32 if pcall(function() -- effectively catch any errors, 404 if any
33 if view == "tree" then -- directory display (with automatic README rendering)
34 local path = parsed_uri.parts
35 table.remove(path, 3) -- branch
36 table.remove(path, 2) -- "tree"
37 table.remove(path, 1) -- repo
38 if #path > 0 then
39 path = table.concat(path, "/").."/"
40 else
41 path = ""
42 end
43
44 content = require("pages/tree")(repo, repo_dir, branch, path)
45 elseif view == "blob" then
46 -- /repo/blob/branch/[FILE PATH]
47 elseif view == "raw" then
48 -- /repo/raw/branch/[FILE PATH]
49 elseif view == "log" then
50 content = require("pages/log")(repo, repo_dir, branch, ngx.var.arg_n, ngx.var.arg_skip)
51 elseif view == "refs" then
52 content = require("pages/refs")(repo, repo_dir, branch)
53 elseif view == "download" then
54 content = require("pages/download")(repo, repo_dir, branch)
55 elseif view == "commit" then
56 -- /repo/commit/[COMMIT HASH]
57 end
58 end) ~= true then
59 ngx.exit(ngx.HTTP_NOT_FOUND)
60 return
61 end
62 end
63 end
64end
65
66if content ~= nil then -- TODO: HTML templates from files, static serving
67ngx.say([[<style>
68@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,400i,700,700i&display=swap');
69*{
70box-sizing:border-box;
71}
72body{
73font-family:'Fira Sans', sans-serif;
74padding-bottom:200px;
75line-height:1.4;
76max-width:1000px;
77margin:20px auto;
78}
79body>h2{
80 margin-top:5px;
81 margin-bottom:0;
82}
83h3{
84margin-bottom:4px;
85}
86td,th{
87padding:2px 5px;
88border:1px solid #858585;
89text-align:left;
90vertical-align:top;
91}
92th{
93border:1px solid #000;
94}
95table.log,table.files,table.numberedlog{
96 width:100%;
97 max-width:100%;
98}
99table{
100 border-collapse:collapse;
101 overflow:auto;
102 font-family: monospace;
103 font-size:14px;
104}
105table.log td:not(:nth-child(3)), table.tree td:not(:nth-child(2)), table.numberedlog td:not(:nth-child(4)){
106 max-width:1%;
107 white-space:nowrap;
108}
109span.q{
110text-decoration:underline;
111text-decoration-style:dotted;
112}
113.q:hover{
114cursor:help;
115}
116tr:hover,th{ /*darker color for table head, hovered-over rows*/
117background-color:#dedede;
118}
119div.markdown{
120width:100%;
121padding:20px 50px;
122border:1px solid #858585;
123border-radius:6px;
124}
125img{
126max-width:100%;
127}
128pre{
129background-color:#eee;
130padding:15px;
131overflow-x:auto;
132border-radius:8px;
133}
134:not(pre)>code{
135background-color:#eee;
136padding:2.5px;
137border-radius:4px;
138}
139a{
140text-decoration:none;
141color: #0077aa;
142}
143a:hover{
144 text-decoration:underline;
145}
146.home-banner h1 {
147 margin-top:50px;
148 margin-bottom:0;
149}
150.home-banner p {
151 margin-top:8px;
152 margin-bottom:35px;
153}
154.repo-section .name {
155 margin-bottom:0;
156}
157.repo-section h3 {
158 margin-top:10px;
159}
160.repo-section .description {
161 margin-top:8px;
162}
163.repo-section .nav {
164 margin-top:10px;
165}
166hr {
167 margin: 25px 0;
168}
169</style>]])
170
171 if parsed_uri.repo then
172 local arrow_left_circle = [[<img style="width:1.2em;height:1.2em;vertical-align:middle;margin-right:0.2em" src="https://joshuas3.s3.amazonaws.com/svg/arrow-left.svg"/>]]
173 ngx.say("<a style=\"margin-left:-1.35em\" href=\"/\">"..arrow_left_circle.."<span style=\"vertical-align:middle\">Index</span></a>")
174 end
175 ngx.say(content:build())
176 ngx.exit(ngx.HTTP_OK)
177 return
178else
179 ngx.exit(ngx.HTTP_NOT_FOUND) -- default behavior
180 return
181end
182