Introduction
Introduction Statistics Contact Development Disclaimer Help
Removing grouping and sorting by last commit instead. - staticgit - A git stati…
Log
Files
Refs
README
---
commit 2c17ce4ce5c99e093bcc742c8815e7ad64e3b233
parent 9d8853a409012768220b56db8959cdc7f73abff9
Author: Jay Scott <[email protected]>
Date: Sun, 14 Jul 2024 11:54:21 +0100
Removing grouping and sorting by last commit instead.
Diffstat:
M Makefile | 2 +-
M main.go | 77 +++++++++--------------------…
2 files changed, 22 insertions(+), 57 deletions(-)
---
diff --git a/Makefile b/Makefile
@@ -8,7 +8,7 @@ all: run
run:
@echo "Running $(APP_NAME)..."
- @go run . -g -p ./git -o tmp -i .ssh,jay.scot,internal-docs
+ @go run . -p ./git -o tmp -i .ssh,jay.scot,internal-docs
build:
@echo "Building $(APP_NAME) for local architecture..."
diff --git a/main.go b/main.go
@@ -7,10 +7,10 @@ import (
"log"
"os"
"path/filepath"
- "regexp"
"sort"
"strings"
"sync"
+ "time"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
@@ -26,14 +26,13 @@ type CommitInfo struct {
}
type RepoInfo struct {
- Name string
- Description string
- LastCommit string
+ Name string
+ Description string
+ LastCommitTime time.Time
}
const (
-
- base = `
+ base = `
<!DOCTYPE html>
<html lang="en">
<head>
@@ -73,7 +72,7 @@ const (
</html>
`
- details = `
+ details = `
{{define "content"}}
<pre>{{.ReadmeContent}}</pre>
@@ -112,7 +111,7 @@ const (
{{end}}
`
- index = `
+ index = `
{{define "content"}}
<table>
<thead>
@@ -123,15 +122,13 @@ const (
</tr>
</thead>
<tbody>
- {{range $group, $repos := .Repos}}
- {{range $repos}}
+ {{range .Repos}}
<tr>
<td><a href="{{.Name}}/index.html">{{.Name}}</a></td>
<td>{{.Description}}</td>
- <td>{{.LastCommit}}</td>
+ <td>{{.LastCommitTime.Format "2006-01-02 15:04:05"}}</td>
</tr>
{{end}}
- {{end}}
</tbody>
</table>
{{end}}
@@ -145,14 +142,16 @@ var (
}
reposPath string
- groupFlag bool
ignoreDirs map[string]bool
outputRoot string
commitLimit int
)
func generateIndex(repoInfos []RepoInfo) error {
- groupedRepos := groupRepos(repoInfos)
+ sort.Slice(repoInfos, func(i, j int) bool {
+ return repoInfos[i].LastCommitTime.After(repoInfos[j].LastComm…
+ })
+
indexOutputPath := filepath.Join(outputRoot, "index.html")
indexFile, err := os.Create(indexOutputPath)
@@ -162,13 +161,11 @@ func generateIndex(repoInfos []RepoInfo) error {
defer indexFile.Close()
return templates["index"].Execute(indexFile, struct {
- Title string
- IconPath string
- Repos map[string][]RepoInfo
+ Title string
+ Repos []RepoInfo
}{
- Title: "Repos for days!",
- IconPath: "./",
- Repos: groupedRepos,
+ Title: "Repos for days!",
+ Repos: repoInfos,
})
}
@@ -203,15 +200,11 @@ func generateRepo(repoName, repoPath, outputDir string) e…
return templates["details"].Execute(f, struct {
Title string
- 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,
@@ -360,39 +353,12 @@ func getRepo(repoPath string) (RepoInfo, error) {
description := getDescription(repoPath)
return RepoInfo{
- Name: filepath.Base(repoPath),
- Description: description,
- LastCommit: commit.Committer.When.Format("02 Jan 2006"),
+ Name: filepath.Base(repoPath),
+ Description: description,
+ LastCommitTime: commit.Committer.When,
}, nil
}
-func groupRepos(repos []RepoInfo) map[string][]RepoInfo {
- groupedRepos := make(map[string][]RepoInfo)
- for _, repo := range repos {
- group := getGroup(repo.Description)
- groupedRepos[group] = append(groupedRepos[group], repo)
- }
-
- for _, repoList := range groupedRepos {
- sort.Slice(repoList, func(i, j int) bool {
- return strings.ToLower(repoList[i].Name) < strings.ToL…
- })
- }
-
- return groupedRepos
-}
-
-func getGroup(description string) string {
- if groupFlag {
- groupRegex := regexp.MustCompile(`\[(.*?)\]`)
- matches := groupRegex.FindStringSubmatch(description)
- if len(matches) > 1 {
- return matches[1]
- }
- }
- return ""
-}
-
func parseIgnored(ignoreDirs string) map[string]bool {
ignoreMap := make(map[string]bool)
for _, dir := range strings.Split(ignoreDirs, ",") {
@@ -460,7 +426,6 @@ func processRepos() error {
func main() {
flag.StringVar(&reposPath, "p", "", "Path to the git repositories (req…
flag.StringVar(&outputRoot, "o", ".", "Root path where output director…
- flag.BoolVar(&groupFlag, "g", false, "Group repositories based on desc…
flag.IntVar(&commitLimit, "c", 100, "Limit for the number of commits t…
ignoreFlag := flag.String("i", "", "Directories to ignore (comma-separ…
@@ -469,7 +434,7 @@ func main() {
fmt.Fprintf(os.Stderr, "Options:\n")
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "\nExample:\n")
- fmt.Fprintf(os.Stderr, " %s -p /path/to/repos -g -i dir1,dir2…
+ fmt.Fprintf(os.Stderr, " %s -p /path/to/repos -i dir1,dir2 -o…
}
flag.Parse()
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.