Introduction
Introduction Statistics Contact Development Disclaimer Help
Adding files to the details page. - staticgit - A git static site generator, th…
Log
Files
Refs
README
---
commit 3ae097a4ff6feb3c58b3e5c5aae916616d5bddf6
parent 89f13ce268930a8a931f4a82312653c96ac8d8ca
Author: Jay Scott <[email protected]>
Date: Sat, 13 Jul 2024 20:47:16 +0100
Adding files to the details page.
Diffstat:
M main.go | 50 +++++++++++++++++++++++++++++…
1 file changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/main.go b/main.go
@@ -61,7 +61,7 @@ const (
<img src="{{.IconPath}}logo.png" alt="" width="32" height="3…
</td>
<td>
- <span class="desc">{{.Title}}</span>
+ <span class="desc">{{.Title}}</span>
</td>
</tr>
</table>
@@ -78,7 +78,7 @@ const (
{{define "content"}}
<pre>{{.ReadmeContent}}</pre>
- <h2>Commit History</h2>
+ <h2 id="commits">Commit History</h2>
<hr>
<table>
<thead>
@@ -101,9 +101,19 @@ const (
<td style="color: green;">+{{.Added}}</td>
<td style="color: red;">-{{.Removed}}</td>
</tr>
+
{{end}}
</tbody>
</table>
+
+ <h2 id="files">Files</h2>
+ <hr>
+ <ul>
+ {{range .Files}}
+ <li>{{.}}</li>
+ {{end}}
+ </ul>
+
{{end}}
`
@@ -186,6 +196,11 @@ func generateRepo(repoName, repoPath, outputDir string) er…
return fmt.Errorf("failed to get commit history: %w", err)
}
+ files, err := getFiles(repo)
+ if err != nil {
+ return fmt.Errorf("failed to get repository files: %w", err)
+ }
+
outputPath := filepath.Join(outputDir, "index.html")
f, err := os.Create(outputPath)
@@ -199,12 +214,14 @@ func generateRepo(repoName, repoPath, outputDir string) e…
IconPath string
RepoName string
ReadmeContent string
+ Files []string
Commits []CommitInfo
}{
Title: "git clone [email protected]:" + repoName,
IconPath: "../",
RepoName: repoName,
ReadmeContent: readme,
+ Files: files,
Commits: commits,
})
}
@@ -264,6 +281,35 @@ func getDescription(repoPath string) string {
return strings.TrimSpace(string(description))
}
+func getFiles(repo *git.Repository) ([]string, error) {
+ ref, err := repo.Head()
+ if err != nil {
+ return nil, fmt.Errorf("failed to get HEAD reference: %w", err)
+ }
+
+ commit, err := repo.CommitObject(ref.Hash())
+ if err != nil {
+ return nil, fmt.Errorf("failed to get commit object: %w", err)
+ }
+
+ tree, err := commit.Tree()
+ if err != nil {
+ return nil, fmt.Errorf("failed to get tree: %w", err)
+ }
+
+ var files []string
+ err = tree.Files().ForEach(func(f *object.File) error {
+ files = append(files, f.Name)
+ return nil
+ })
+ if err != nil {
+ return nil, fmt.Errorf("failed to iterate over files: %w", err)
+ }
+
+ sort.Strings(files)
+ return files, nil
+}
+
func getReadme(repoPath string) (string, error) {
readmeFiles := []string{"README.md", "README.txt", "README"}
repo, err := git.PlainOpen(repoPath)
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.