commit
message
Cleaner git data, better links
author
Ben Vogt <[email protected]>
date
2023-04-10 18:20:44
stats
3 file(s) changed,
24 insertions(+),
17 deletions(-)
files
file.go
main.go
template.index.html
1diff --git a/file.go b/file.go
2index 41d6567..d14471c 100644
3--- a/file.go
4+++ b/file.go
5@@ -25,9 +25,9 @@ type FilePage struct {
6
7 func (f *FilePage) RenderPage(t *template.Template) {
8 debug("file %v %v", f.RepoData.Name, f.Name)
9- err := os.MkdirAll(f.DestinationDir, 0775)
10+ err := os.MkdirAll(f.DestinationDir, 0777)
11 checkErr(err)
12- err = os.MkdirAll(filepath.Dir(f.Destination), 0775)
13+ err = os.MkdirAll(filepath.Dir(f.Destination), 0777)
14 checkErr(err)
15 output, err := os.Create(f.Destination)
16 checkErr(err)
17diff --git a/main.go b/main.go
18index e0b1f7d..3a333be 100644
19--- a/main.go
20+++ b/main.go
21@@ -46,15 +46,15 @@ func main() {
22 RenderSingleFilePages(data)
23 }
24 RenderIndexPage(allRepoData)
25- RenderAssets()
26+ renderAssets()
27 for _, repo := range config.Repos {
28- HostRepo(repo)
29+ hostRepo(repo)
30 }
31 }
32
33 func Init() {
34 log.SetFlags(0)
35- log.SetOutput(new(LogWriter))
36+ log.SetOutput(new(logger))
37 args = DefaultCmdArgs()
38 settings = DefaultSettings()
39 pwd, err := os.Getwd()
40@@ -111,33 +111,38 @@ func CloneAndGetData(repo Repo, r *git.Repository) RepoData {
41 return data
42 }
43
44-func RenderAssets() {
45+func renderAssets() {
46 debug("rendering gshr.css")
47 debug("rendering favicon.ico")
48 checkErr(os.WriteFile(path.Join(args.OutputDir, "gshr.css"), css, 0666))
49 checkErr(os.WriteFile(path.Join(args.OutputDir, "favicon.ico"), favicon, 0666))
50 }
51
52-func HostRepo(data Repo) {
53+func hostRepo(data Repo) {
54 if data.HostGit {
55 debug("hosting of '%v' is ON", data.Name)
56 old := path.Join(data.CloneDir(), ".git")
57- new := path.Join(args.OutputDir, fmt.Sprintf("%v.git", data.Name))
58- debug("renaming '%v', new %v", data.Name, new)
59- checkErr(os.Rename(old, new))
60- debug("running 'git update-server-info' in %v", new)
61+ renamed := path.Join(args.OutputDir, fmt.Sprintf("%v.git", data.Name))
62+ repoFiles := path.Join(args.OutputDir, data.Name, "git")
63+ final := path.Join(args.OutputDir, "git", data.Name)
64+ debug("renaming '%v', new %v", data.Name, renamed)
65+ os.MkdirAll(path.Join(args.OutputDir, "git"), 0777)
66+ checkErr(os.Rename(old, renamed))
67+ debug("running 'git update-server-info' in %v", renamed)
68 cmd := exec.Command("git", "update-server-info")
69- cmd.Dir = new
70+ cmd.Dir = renamed
71 checkErr(cmd.Run())
72- debug("hosting '%v' at %v", data.Name, new)
73+ os.RemoveAll(repoFiles)
74+ checkErr(os.Rename(renamed, final))
75+ debug("hosting '%v' at %v", data.Name, final)
76 } else {
77 debug("hosting of '%v' is OFF", data.Name)
78 }
79 }
80
81-type LogWriter struct{}
82+type logger struct{}
83
84-func (writer LogWriter) Write(bytes []byte) (int, error) {
85+func (writer logger) Write(bytes []byte) (int, error) {
86 return fmt.Print(string(bytes))
87 }
88
89diff --git a/template.index.html b/template.index.html
90index c4f47f4..2cc747a 100644
91--- a/template.index.html
92+++ b/template.index.html
93@@ -37,8 +37,8 @@
94 <r-cell span="7">
95 <div class="ellipsis">
96 {{ if .HostGit }}
97- <a class="mono" href="{{ .BaseURL }}{{ .Name }}.git">
98- {{ .BaseURL }}{{ .Name }}.git
99+ <a class="mono" href="{{ .BaseURL }}git/{{ .Name }}">
100+ {{ .BaseURL }}git/{{ .Name }}
101 </a>
102 {{ else if not (eq .PublishedGitURL "") }}
103 <a class="mono" href="{{ .PublishedGitURL }}">