fierj
PublicTiny personal git forge
950586c36ac58d600acbf0dff50c0e7009f92d4f
diff --git a/config.go b/config.go
index c66c41a..b3ffa6e 100644
--- a/config.go
+++ b/config.go
@@ -11,6 +11,7 @@ const envPrefix = "FIERJ_"
type Config struct {
Addr string `json:"addr" env:"ADDR"`
+ Host string `json:"host" env:"HOST"`
Dir string `json:"dir" env:"DIR"`
}
@@ -18,6 +19,7 @@ func LoadConfig(path string) Config {
// default config
cfg := Config{
Addr: ":8080",
+ Host: "localhost:8080",
Dir: "repos",
}
diff --git a/handlers.go b/handlers.go
index 1516859..da7ed5d 100644
--- a/handlers.go
+++ b/handlers.go
@@ -125,13 +125,20 @@ func Tree(cfg Config, tmpl *template.Template) http.HandlerFunc {
if ref == "" {
ref = git.DefaultBranch()
}
- if git.IsEmpty() {
+ cloneSSH := ""
+ cloneHTTPS := ""
+ if cfg.Host != "" {
+ cloneSSH = fmt.Sprintf("git@%s:%s.git", cfg.Host, git.Name)
+ cloneHTTPS = fmt.Sprintf("https://%s/%s.git", cfg.Host, git.Name)
+ }
+ if git.IsEmpty() {
tmpl.ExecuteTemplate(w, "tree.html", map[string]any{
"Repo": git.Repo(),
"Ref": ref,
"Path": "",
- "Entries": []FileEntry{},
- // "CloneURL": fmt.Sprintf("%s@%s:%s.git", cfg.SSHUser, cfg.Host, repoName),
+ "Entries": []FileEntry{},
+ "CloneSSH": cloneSSH,
+ "CloneHTTPS": cloneHTTPS,
"Description": git.Description(),
"Branches": []string{},
"Tags": []string{},
@@ -169,7 +176,8 @@ func Tree(cfg Config, tmpl *template.Template) http.HandlerFunc {
"Path": treePath,
"Breadcrumb": Breadcrumb(treePath),
"Entries": fileEntries,
- // "CloneURL": fmt.Sprintf("%s@%s:%s.git", cfg.SSHUser, cfg.Host, repoName),
+ "CloneSSH": cloneSSH,
+ "CloneHTTPS": cloneHTTPS,
"Description": git.Description(),
"Branches": git.Branches(),
"Tags": git.Tags(),
diff --git a/main.go b/main.go
index 39fa9f5..35f03fa 100644
--- a/main.go
+++ b/main.go
@@ -49,7 +49,7 @@ func main() {
srv.Shutdown(ctx)
}()
- slog.Info("fierj started", "addr", cfg.Addr, "repos", cfg.Dir)
+ slog.Info("fierj started", "addr", cfg.Addr, "host", cfg.Host, "repos", cfg.Dir)
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
slog.Error("failed to start server", "error", err)
}
diff --git a/templates/tree.html b/templates/tree.html
index 8737ed1..795a2df 100644
--- a/templates/tree.html
+++ b/templates/tree.html
@@ -6,8 +6,8 @@
{{if .Empty}}
<div class="empty-state">
<p>Empty repository. Push your first commit:</p>
- <pre><code>git remote add origin {{.CloneURL}}
-git push -u origin main</code></pre>
+ {{if .CloneSSH}}<pre><code>git remote add origin {{.CloneSSH}}
+git push -u origin main</code></pre>{{end}}
</div>
{{else}}
@@ -26,7 +26,7 @@ git push -u origin main</code></pre>
<span class="code-bar spacer"></span>
<span class="clone-btn">
<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor"><path d="M4.72 3.22a.75.75 0 0 1 1.06 1.06L2.06 8l3.72 3.72a.75.75 0 1 1-1.06 1.06L.47 8.53a.75.75 0 0 1 0-1.06Zm6.56 0a.75.75 0 1 0-1.06 1.06L13.94 8l-3.72 3.72a.75.75 0 1 0 1.06 1.06l4.25-4.25a.75.75 0 0 0 0-1.06Z"/></svg>
- {{.CloneURL}}
+ {{if .CloneSSH}}{{.CloneSSH}}{{end}}
</span>
<a href="/{{.Repo}}/feed.xml" title="RSS feed" class="clone-btn" style="text-decoration:none;">
<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor"><path d="M2.002 2.725a.75.75 0 0 1 .797-.699C8.79 2.42 13.58 7.21 13.974 13.201a.75.75 0 0 1-1.497.098 10.502 10.502 0 0 0-9.776-9.776.747.747 0 0 1-.7-.798ZM2.84 7.05h-.002a7.002 7.002 0 0 1 6.113 6.111.75.75 0 0 1-1.5.008 5.501 5.501 0 0 0-4.8-4.8.75.75 0 0 1 .189-1.319ZM2 13a1 1 0 1 0 2 0 1 1 0 0 0-2 0Z"/></svg>