Index

resty-gitweb / 6f56890

A git web interface for Lua/OpenResty (you're on it right now!)

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
1224 Jan 2021 17:05dda0daeNew HTML generatorJosh Stockin111G

Blob @ resty-gitweb / pages / raw.lua

text/plain962 bytesdownload raw
1-- resty-gitweb@pages/raw.lua
2-- Raw file 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
8local utils = require("utils/utils")
9local git = require("git/git")
10
11local builder = require("utils/builder")
12
13local _M = function(repo, repo_dir, branch, file_path)
14 -- Pre checks
15 if file_path ~= "" then -- make sure path exists
16 local path_tree = git.list_tree(repo_dir, branch.name, file_path)
17 if #path_tree.files == 0 then -- no path found
18 error("file "..file_path.." is nonexistent")
19 end
20 else
21 error("file path is empty")
22 end
23
24 local build = builder:new()
25
26 -- File
27 local success, repo_obj = git.repo.open(repo_dir)
28 local content, is_binary = git.read_blob(repo_obj, branch.name, file_path)
29 git.repo.free(repo_obj)
30
31 build{content}
32
33 return build, is_binary
34end
35
36return _M
37