Commit 3b3f037
Changed files (7)
cmd
gitmal
internal
templates
cmd/gitmal/main.go
@@ -14,6 +14,7 @@ import (
)
var flagOutput string
+var flagCloneBase string
func main() {
if err := run(); err != nil {
@@ -24,6 +25,7 @@ func main() {
func run() error {
flag.StringVar(&flagOutput, "output", "output", "Output directory")
+ flag.StringVar(&flagCloneBase, "clone-base", "", "Clone URL base domain")
flag.Usage = usage
flag.Parse()
@@ -50,6 +52,12 @@ func run() error {
name := filepath.Base(input)
name = strings.TrimSuffix(name, ".git")
+ var cloneURL string
+ if flagCloneBase != "" {
+ owner := filepath.Base(filepath.Dir(input))
+ cloneURL = fmt.Sprintf("https://%s/%s/%s.git", flagCloneBase, owner, name)
+ }
+
branches, err := git.Branches(input)
if err != nil {
return err
@@ -78,6 +86,7 @@ func run() error {
RepoDir: input,
OutputDir: outputDir,
DefaultRef: git.NewRef(defaultBranch),
+ CloneURL: cloneURL,
}
commits := make(map[string]git.Commit)
internal/generator/list.go
@@ -105,6 +105,7 @@ func GenerateIndex(files []git.Blob, params Params) error {
NeedsMarkdownCSS: hasReadme,
NeedsSyntaxCSS: hasReadme,
Year: currentYear(),
+ CloneURL: params.CloneURL,
},
HeaderParams: templates.HeaderParams{
Ref: params.Ref,
internal/generator/params.go
@@ -8,4 +8,5 @@ type Params struct {
Ref git.Ref
OutputDir string
DefaultRef git.Ref
+ CloneURL string
}
internal/templates/header.gohtml
@@ -23,5 +23,8 @@
{{- end}}
</nav>
{{- end}}
+{{- if .CloneURL}}
+ <code class="clone-url" style="margin-left:auto;font-size:12px;color:var(--color-fg-muted)">git clone {{.CloneURL}}</code>
+{{- end}}
</header>
{{- end}}
internal/templates/templates.go
@@ -64,6 +64,7 @@ type LayoutParams struct {
NeedsMarkdownCSS bool
NeedsSyntaxCSS bool
Year int
+ CloneURL string
}
type HeaderParams struct {
Makefile
@@ -7,7 +7,7 @@ test:
go test ./...
run: build
- ./gitmal --output output .
+ ./gitmal --clone-base git.mokhan.ca --output output .
clean:
rm -rf gitmal output
README.md
@@ -11,6 +11,7 @@ gitmal [options] [path ...]
### Options
- `--output` - Output directory (default: `output`)
+- `--clone-base` - Clone URL base domain (e.g., `git.mokhan.ca`)
## Output