Browse Source

Added forge title customization

feature/embedded-resources-and-css
root 5 months ago
parent
commit
7109c49897
  1. 2
      config.go
  2. 1
      gitmgr.go
  3. 6
      templates.go
  4. 2
      templates/edit-repository.html
  5. 4
      templates/homepage.html

2
config.go

@ -28,6 +28,7 @@ type Config struct {
CloneUrlTemplate string
VerboseLogging bool
UrlPrefix string
Title string
PublicGitLinkTemplate string
DefaultHeadRef string
}
@ -98,6 +99,7 @@ func GetConfig() (*Config, error) {
CloneUrlTemplate: getEnv("CLONE_URL_TEMPLATE", ""),
VerboseLogging: isVerbose,
UrlPrefix: getEnv("URL_PREFIX", ""),
Title: getEnv("TITLE", "gitmgr"),
PublicGitLinkTemplate: getEnv("PUBLIC_GIT_LINK_TEMPLATE", "/edit?repository={{.}}"),
DefaultHeadRef: getEnv("DEFAULT_HEAD", "heads/main"),
}, nil

1
gitmgr.go

@ -20,6 +20,7 @@ func main() {
MaxDescriptionLength = config.MaxDescriptionLength
UrlPrefix = config.UrlPrefix
DefaultHead = config.DefaultHeadRef
Title = config.Title
tpl, err := template.New("").Parse(fmt.Sprint(config.CloneUrlTemplate))
if err != nil {

6
templates.go

@ -24,11 +24,13 @@ var (
"reftype": RefTypeLabel,
"prettify": PrettifyRef,
"public_url": PublicGitUrl,
"title": GetTitle,
}).ParseFS(templateFS, "templates/*.html")
// Global configs
MaxDescriptionLength = 20
UrlPrefix = ""
PublicLinkTemplate *text.Template
Title = ""
)
func Trim(input string) html.HTML {
@ -79,3 +81,7 @@ func PublicGitUrl(repo string) string {
_ = PublicLinkTemplate.Execute(&tpl, repo)
return tpl.String()
}
func GetTitle() string {
return Title
}

2
templates/edit-repository.html

@ -5,7 +5,7 @@
<title>Editing {{.Repo.Name}}</title>
<link rel="stylesheet" href="/static/style.css">
<main>
<h1><a class="button" href="{{"/"|url}}">gitmgr</a> / {{.Repo.Name}}</h1>
<h1><a class="button" href="{{"/"|url}}">{{title}}</a> / {{.Repo.Name}}</h1>
{{with .Errors}}
<h2>Errors:</h2>
<ul>

4
templates/homepage.html

@ -2,10 +2,10 @@
<!DOCTYPE html>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>gitmgr</title>
<title>{{title}}</title>
<link rel="stylesheet" href="/static/style.css">
<script defer src="/static/homepage.js"></script>
<h1>gitmgr</h1>
<h1>{{title}}</h1>
<aside>
<form method="post">

Loading…
Cancel
Save