From c916e1854f36c22209987dcf7cb32c9feb811b22 Mon Sep 17 00:00:00 2001
From: Runxi Yu <me@runxiyu.org>
Date: Fri, 14 Feb 2025 11:56:21 +0800
Subject: [PATCH] *: Make the forge title configurable

---
 config.go                          |  5 +++++
 forge.scfg                         |  4 ++++
 http_global.go                     |  1 +
 templates/_header.html.tmpl        |  2 +-
 templates/group_repos.html.tmpl    |  2 +-
 templates/index.html.tmpl          |  6 +++---
 templates/login.html.tmpl          |  4 ++--
 templates/repo_commit.html.tmpl    | 10 +++++-----
 templates/repo_index.html.tmpl     |  6 +++---
 templates/repo_log.html.tmpl       |  2 +-
 templates/repo_raw_dir.html.tmpl   |  2 +-
 templates/repo_tree_dir.html.tmpl  |  2 +-
 templates/repo_tree_file.html.tmpl |  2 +-

diff --git a/config.go b/config.go
index 525581a37f18b8d85ad4d9ffcf14eb34b8fb209b..d427aeef47b4170ec919570e0b10e8f97bac16bc 100644
--- a/config.go
+++ b/config.go
@@ -26,6 +26,9 @@ 		Addr string `scfg:"addr"`
 		Key  string `scfg:"key"`
 		Root string `scfg:"root"`
 	} `scfg:"ssh"`
+	General struct {
+		Title string `scfg:"title"`
+	} `scfg:"general"`
 	Git struct {
 		Root string `scfg:"root"`
 	} `scfg:"git"`
@@ -55,6 +58,8 @@ 	database, err = pgxpool.New(context.Background(), config.DB.Conn)
 	if err != nil {
 		return err
 	}
+
+	global_data["forge_title"] = config.General.Title
 
 	return nil
 }
diff --git a/forge.scfg b/forge.scfg
index 11facbab8dda830492ade2fdd47087d959716c63..ba61a30d41e11396d88cbc51e4634625cc902077 100644
--- a/forge.scfg
+++ b/forge.scfg
@@ -11,6 +11,10 @@ 	key /etc/ssh/ssh_host_ed25519_key
 	root ssh://forge.example.org
 }
 
+general {
+	title "Test Forge"
+}
+
 db {
 	type postgres
 	conn postgresql:///lindenii-forge?host=/var/run/postgresql
diff --git a/http_global.go b/http_global.go
index e7ee580091ef9b078589ec07d7c197505b4e25d2..b1e55853a3892375f72621d12e5827f5885ae815 100644
--- a/http_global.go
+++ b/http_global.go
@@ -3,4 +3,5 @@
 var global_data = map[string]any{
 	"server_public_key_string":      &server_public_key_string,
 	"server_public_key_fingerprint": &server_public_key_fingerprint,
+	// Some other ones are populated after config parsing
 }
diff --git a/templates/_header.html.tmpl b/templates/_header.html.tmpl
index 7aebfbccd8ed5592394aeb49d320b6aba80515c0..6d0a3a2b74dc24a8036f3348998f353931bda52b 100644
--- a/templates/_header.html.tmpl
+++ b/templates/_header.html.tmpl
@@ -1,7 +1,7 @@
 {{- define "header" -}}
 <header id="main-header">
 	<div id="main-header-forge-title">
-		<a href="/">Lindenii Forge</a>
+		<a href="/">{{ .global.forge_title }}</a>
 	</div>
 	<div id="main-header-user">
 		{{ if ne .user_id "" }}
diff --git a/templates/group_repos.html.tmpl b/templates/group_repos.html.tmpl
index 2d0b7d9468d4fb9a62f60e5bdcfaf837a9cdaaad..8c95c916c8e67328d60b2955e9a3df7e19939efb 100644
--- a/templates/group_repos.html.tmpl
+++ b/templates/group_repos.html.tmpl
@@ -3,7 +3,7 @@ <!DOCTYPE html>
 <html lang="en">
 	<head>
 		{{ template "head_common" . }}
-		<title>Repos in {{ .group_name }} &ndash; Lindenii Forge</title>
+		<title>Repos in {{ .group_name }} &ndash; {{ .global.forge_title }}</title>
 	</head>
 	<body class="group-repos">
 		{{ template "header" . }}
diff --git a/templates/index.html.tmpl b/templates/index.html.tmpl
index c7259487f2810f4582f0599e2c801e731677a5d5..5f30f0ce530a9057ddd2007b19b4e065360818ac 100644
--- a/templates/index.html.tmpl
+++ b/templates/index.html.tmpl
@@ -3,7 +3,7 @@ <!DOCTYPE html>
 <html lang="en">
 	<head>
 		{{ template "head_common" . }}
-		<title>Index &ndash; Lindenii Forge</title>
+		<title>Index &ndash; {{ .global.forge_title }}</title>
 	</head>
 	<body class="index">
 		{{ template "header" . }}
@@ -41,11 +41,11 @@ 					</tr>
 				</thead>
 				<tbody>
 					<tr>
-						<th scope="row">SSH Public Key</th>
+						<th scope="row">SSH public key</th>
 						<td><code>{{ .global.server_public_key_string }}</code></td>
 					</tr>
 					<tr>
-						<th scope="row">SSH Fingerprint</th>
+						<th scope="row">SSH fingerprint</th>
 						<td><code>{{ .global.server_public_key_fingerprint }}</code></td>
 					</tr>
 				</tbody>
diff --git a/templates/login.html.tmpl b/templates/login.html.tmpl
index 99ee6b95adb6c5c2aec3af4c638f784081374f25..3b0e74a54a033fdb337edabb19f3e911d250da89 100644
--- a/templates/login.html.tmpl
+++ b/templates/login.html.tmpl
@@ -3,7 +3,7 @@ <!DOCTYPE html>
 <html lang="en">
 	<head>
 		{{ template "head_common" . }}
-		<title>Login &ndash; Lindenii Forge</title>
+		<title>Login &ndash; {{ .global.forge_title }}</title>
 	</head>
 	<body class="index">
 		{{ .login_error }}
@@ -13,7 +13,7 @@ 					<table>
 						<thead>
 							<tr>
 								<th class="title-row" colspan="2">
-									Password Authentication
+									Password authentication
 								</th>
 							</tr>
 						</thead>
diff --git a/templates/repo_commit.html.tmpl b/templates/repo_commit.html.tmpl
index bd87f87873ac479f5e7780c1e87b1de43c1f057e..658ed572049127a0381e662d0e741204697baa9f 100644
--- a/templates/repo_commit.html.tmpl
+++ b/templates/repo_commit.html.tmpl
@@ -3,7 +3,7 @@ <!DOCTYPE html>
 <html lang="en">
 	<head>
 		{{ template "head_common" . }}
-		<title>{{ .group_name }}/repos/{{ .repo_name }} &ndash; Lindenii Forge</title>
+		<title>{{ .group_name }}/repos/{{ .repo_name }} &ndash; {{ .global.forge_title }}</title>
 	</head>
 	<body class="repo-commit">
 		{{ template "header" . }}
@@ -11,7 +11,7 @@ 		<div class="padding-wrapper scroll">
 			<table id="commit-info-table">
 				<thead>
 					<tr class="title-row">
-						<th colspan="2">Commit Info</th>
+						<th colspan="2">Commit info</th>
 					</tr>
 				</thead>
 				<tbody>
@@ -24,7 +24,7 @@ 						<th scope="row">Author</th>
 						<td>{{ .commit_object.Author.Name }} &lt;<a href="mailto:{{ .commit_object.Author.Email }}">{{ .commit_object.Author.Email }}</a>&gt;</td>
 					</tr>
 					<tr>
-						<th scope="row">Author Date</th>
+						<th scope="row">Author date</th>
 						<td>{{ .commit_object.Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</td>
 					</tr>
 					<tr>
@@ -32,7 +32,7 @@ 						<th scope="row">Committer</th>
 						<td>{{ .commit_object.Committer.Name }} &lt;<a href="mailto:{{ .commit_object.Committer.Email }}">{{ .commit_object.Committer.Email }}</a>&gt;</td>
 					</tr>
 					<tr>
-						<th scope="row">Committer Date</th>
+						<th scope="row">Committer date</th>
 						<td>{{ .commit_object.Committer.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</td>
 					</tr>
 					<tr>
@@ -41,7 +41,7 @@ 						<td><pre>{{ .commit_object.Message }}</pre></td>
 					</tr>
 					<tr>
 						<th scope="row">Actions</th>
-						<td><pre><a href="{{ .commit_object.Hash }}.patch">Get as Patch</a></pre></td>
+						<td><pre><a href="{{ .commit_object.Hash }}.patch">Get patch</a></pre></td>
 					</tr>
 				</tbody>
 			</table>
diff --git a/templates/repo_index.html.tmpl b/templates/repo_index.html.tmpl
index 14d2a5d7b1ffc0de3e66bed7a2f9be7353c363ca..806ceda07730f75bf282d9d31f0b601a89565a9a 100644
--- a/templates/repo_index.html.tmpl
+++ b/templates/repo_index.html.tmpl
@@ -3,7 +3,7 @@ <!DOCTYPE html>
 <html lang="en">
 	<head>
 		{{ template "head_common" . }}
-		<title>{{ .group_name }}/repos/{{ .repo_name }} &ndash; Lindenii Forge</title>
+		<title>{{ .group_name }}/repos/{{ .repo_name }} &ndash; {{ .global.forge_title }}</title>
 	</head>
 	<body class="repo-index">
 		{{ template "header" . }}
@@ -11,7 +11,7 @@ 		<div class="padding-wrapper">
 			<table id="repo-info-table">
 				<thead>
 					<tr class="title-row">
-						<th colspan="2">Repo Info</th>
+						<th colspan="2">Repo info</th>
 					</tr>
 				</thead>
 				<tbody>
@@ -37,7 +37,7 @@ 			<input id="toggle-table-recent-commits" type="checkbox" class="toggle-table-off" />
 			<table id="recent-commits" class="wide">
 				<thead>
 					<tr class="title-row">
-						<th colspan="3"><label for="toggle-table-recent-commits">Recent Commits (<a href="log/{{ if .ref_type }}?{{ .ref_type }}={{ .ref_name }}{{ end }}">see all</a>)</label></th>
+						<th colspan="3"><label for="toggle-table-recent-commits">Recent commits (<a href="log/{{ if .ref_type }}?{{ .ref_type }}={{ .ref_name }}{{ end }}">see all</a>)</label></th>
 					</tr>
 				</thead>
 				<tbody>
diff --git a/templates/repo_log.html.tmpl b/templates/repo_log.html.tmpl
index fa29fa503f15e3f139b673abd741be183ce93054..6b89cdd58cb882731ff1f7c533c798460b57dc8e 100644
--- a/templates/repo_log.html.tmpl
+++ b/templates/repo_log.html.tmpl
@@ -3,7 +3,7 @@ <!DOCTYPE html>
 <html lang="en">
 	<head>
 		{{ template "head_common" . }}
-		<title>Log of {{ .group_name }}/repos/{{ .repo_name }} &ndash; Lindenii Forge</title>
+		<title>Log of {{ .group_name }}/repos/{{ .repo_name }} &ndash; {{ .global.forge_title }}</title>
 	</head>
 	<body class="repo-log">
 		{{ template "header" . }}
diff --git a/templates/repo_raw_dir.html.tmpl b/templates/repo_raw_dir.html.tmpl
index d306bbf315b935cdb7b8ecdcd7a704d9ff9ba205..d38731b310602f6287ed6d194e4954582d84fa98 100644
--- a/templates/repo_raw_dir.html.tmpl
+++ b/templates/repo_raw_dir.html.tmpl
@@ -3,7 +3,7 @@ <!DOCTYPE html>
 <html lang="en">
 	<head>
 		{{ template "head_common" . }}
-		<title>{{ .group_name }}/repos/{{ .repo_name }}/{{ .path_spec }}{{ if ne .path_spec "" }}/{{ end }} &ndash; Lindenii Forge</title>
+		<title>{{ .group_name }}/repos/{{ .repo_name }}/{{ .path_spec }}{{ if ne .path_spec "" }}/{{ end }} &ndash; {{ .global.forge_title }}</title>
 	</head>
 	<body class="repo-raw-dir">
 		{{ template "header" . }}
diff --git a/templates/repo_tree_dir.html.tmpl b/templates/repo_tree_dir.html.tmpl
index 34559da26b8802402aa72cc76f8e810297ba186e..5e0fdcc679baaf170308ed8ca1511d8bee5d935d 100644
--- a/templates/repo_tree_dir.html.tmpl
+++ b/templates/repo_tree_dir.html.tmpl
@@ -3,7 +3,7 @@ <!DOCTYPE html>
 <html lang="en">
 	<head>
 		{{ template "head_common" . }}
-		<title>{{ .group_name }}/repos/{{ .repo_name }}/{{ .path_spec }}{{ if ne .path_spec "" }}/{{ end }} &ndash; Lindenii Forge</title>
+		<title>{{ .group_name }}/repos/{{ .repo_name }}/{{ .path_spec }}{{ if ne .path_spec "" }}/{{ end }} &ndash; {{ .global.forge_title }}</title>
 	</head>
 	<body class="repo-tree-dir">
 		{{ template "header" . }}
diff --git a/templates/repo_tree_file.html.tmpl b/templates/repo_tree_file.html.tmpl
index 8eacd288c21565f9d4273d170d381ea1a9f6d535..7d5069c5bf0dcc304bec3d4c42472185f6600d65 100644
--- a/templates/repo_tree_file.html.tmpl
+++ b/templates/repo_tree_file.html.tmpl
@@ -4,7 +4,7 @@ <html lang="en">
 	<head>
 		{{ template "head_common" . }}
 		<link rel="stylesheet" href="/:/static/chroma.css" />
-		<title>{{ .group_name }}/repos/{{ .repo_name }}/{{ .path_spec }} &ndash; Lindenii Forge</title>
+		<title>{{ .group_name }}/repos/{{ .repo_name }}/{{ .path_spec }} &ndash; {{ .global.forge_title }}</title>
 	</head>
 	<body class="repo-tree-file">
 		{{ template "header" . }}

-- 
2.48.1