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 |
|
8 | local utils = require("utils/utils") |
9 | local git = require("git/git") |
10 |
|
11 | local builder = require("utils/builder") |
12 |
|
13 | local _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 |
34 | end |
35 |
|
36 | return _M |
37 |
|