M commits.go => commits.go +39 -0
@@ 1,11 1,13 @@
package main
import (
+ "fmt"
"os"
"path/filepath"
"text/template"
"github.com/go-git/go-git/v5"
+ "github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
)
@@ 78,3 80,40 @@ func createCommitsFiles(repository *git.Repository) {
check(commitsIndex.Close())
wg.Done()
}
+
+func createRefsFile(r *git.Repository) {
+ tags := []string{}
+ iter, err := r.Tags()
+ check(err)
+ err = iter.ForEach(func(ref *plumbing.Reference) error {
+ c, err := r.CommitObject(ref.Hash())
+ if err != nil {
+ return err
+ }
+
+ tag := fmt.Sprintf(
+ "=> ../%s/%s.patch %s - %s",
+ commitsSubPath,
+ ref.Hash(),
+ c.Author.When.Format("2006-01-02"),
+ filepath.Base(ref.Name().String()),
+ )
+ tags = append(tags, tag)
+
+ return nil
+ })
+ check(err)
+
+ refsPath := filepath.Join(distPath, refsSubPath)
+ check(os.Mkdir(refsPath, os.ModePerm))
+
+ refsFile, err := os.Create(filepath.Join(refsPath, "index.gmi"))
+ check(err)
+ defer refsFile.Close()
+
+ fmt.Fprintf(refsFile, "# %s tags\n\n", projectName)
+
+ for i := len(tags) - 1; i >= 0; i-- {
+ fmt.Fprintln(refsFile, tags[i])
+ }
+}
M files.go => files.go +5 -0
@@ 121,6 121,11 @@ func createIndexFile() {
}
indexFile.WriteString("=> " + commitsSubPath + "/\n")
+
+ if generateRefs {
+ indexFile.WriteString("=> " + refsSubPath + "/\n")
+ }
+
indexFile.WriteString("=> " + treeSubPath + "/\n\n")
// convert README.md to gemini and write it to index.gmi in repository root
M main.go => main.go +14 -0
@@ 14,6 14,7 @@ var wg sync.WaitGroup
const (
treeSubPath = "tree"
commitsSubPath = "commits"
+ refsSubPath = "refs"
)
var (
@@ 21,6 22,8 @@ var (
distPath string
cloneURL string
showPermissions bool
+ generateRefs bool
+ projectName string
)
func main() {
@@ 29,6 32,8 @@ func main() {
flag.StringVar(&cloneURL, "url", "", "clone URL for end user (optional)")
flag.BoolVar(&showPermissions, "perms", false, "show files permissions in browsable tree")
+ flag.BoolVar(&generateRefs, "refs", false, "generate the tags page")
+ flag.StringVar(&projectName, "name", "", "project name, mandatory if generating the tags page")
flag.Parse()
@@ 37,6 42,11 @@ func main() {
return
}
+ if generateRefs && projectName == "" {
+ flag.Usage()
+ return
+ }
+
if err := os.RemoveAll(distPath); err != nil {
log.Fatalf("cannot remove dist directory: %s", err)
}
@@ 53,6 63,10 @@ func main() {
wg.Add(1)
+ if generateRefs {
+ createRefsFile(repository)
+ }
+
go createCommitsFiles(repository)
createBrowsableTree()
createIndexFile()