Index

resty-gitweb / c69d6c0

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
703 Jan 2021 10:11609d330libgit2 binding updates, README updatesJosh Stockin1360G

Blob @ resty-gitweb / pages / raw.lua

text/plain915 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 return nil
19 end
20 else
21 return nil
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:add(content)
32
33 return build, is_binary
34end
35
36return _M
37