From 5f04f059da147dfadd282c2a89600fd4aca5f5d3 Mon Sep 17 00:00:00 2001 From: Shota FUJI Date: Sun, 16 Aug 2026 15:03:04 +0900 Subject: [PATCH] Add "ui.email" option and obfuscate emails by default https://tangled.org/pocka.jp/legit/issues/28 To block most of email scrapers. If the world changed and majority of email scrapers are equipped with JavaScript and CSS, one can change the option to "none" without changing the program source code. That's last resort, but it works. A legit legit user can get email addresses by cloning the repository then running git-show or git-log. I think "mailto-js" is sensible default because 1) it does not change user interface for majority of visitors and 2) provides protection to self-hosters from surprising email spams. At very least neither template pipeline data nor config structure has breaking change. --- config.yaml | 12 +++++++ config/config.go | 20 +++++++++++ .../commit-signature-script.html.tmpl | 24 +++++++++++++ embed/templates/commit-signature.html.tmpl | 26 ++++++++++++++ embed/templates/repo-commit.html.tmpl | 9 ++--- embed/templates/repo-log-ref.html.tmpl | 10 +++--- embed/templates/repo-top.html.tmpl | 6 ++-- templates/data.go | 34 +++++++++++++++++++ 8 files changed, 126 insertions(+), 15 deletions(-) create mode 100644 embed/templates/commit-signature-script.html.tmpl create mode 100644 embed/templates/commit-signature.html.tmpl diff --git a/config.yaml b/config.yaml index 1c59a90..f6fd12d 100644 --- a/config.yaml +++ b/config.yaml @@ -107,6 +107,18 @@ ui: # Setting 0 disables the hiding mechanism. Default value is 0. hideThresholdLines: 1000 + # Display of author and committer email addresses. This does not affect the rendering of email links + # inside Markdown previews and footer links. The purpose of obfuscation is to prevent email scrapers + # from scraping email addresses, under the assumption most of the scrapers are low-effort ones. + # + # Available values: + # "mailto" ... Simply place an email address into "mailto:" link. + # "mailto-js" ... Render without email address, then replace with "mailto:" link using JavaScript. (default) + # Display obfuscated email address next to author / committer name if JS is unavailable. + # "obfuscate" ... Display obfuscated email address next to author / committer name. + # "none" ... Do not output committer / author email address at all. + email: "mailto-js" + # You can set repository's category by creating `category` file in $GIT_DIR or # setting `gitweb.category` git config. # https://git-scm.com/docs/gitweb#Documentation/gitweb.txt-categoryorgitwebcategory diff --git a/config/config.go b/config/config.go index 4423fb3..5aca4ae 100644 --- a/config/config.go +++ b/config/config.go @@ -10,6 +10,10 @@ import ( "gopkg.in/yaml.v3" ) +const ( + defaultEmailFormat = "mailto-js" +) + var staticDirRevision string type Config struct { @@ -49,6 +53,7 @@ type Config struct { Default string `yaml:"default"` Order []string `yaml:"order"` } + Email string `yaml:"email"` Footer struct { Links []struct { Text string `yaml:"text"` @@ -85,6 +90,8 @@ func NewWithDefaults() *Config { c.Meta.Title = "Repositories" c.StaticDirRevision = staticDirRevision + c.UI.Email = defaultEmailFormat + return &c } @@ -148,6 +155,19 @@ func (c *Config) Resolve(cwd string) error { c.UI.CommitsPageSize = 30 } + if c.UI.Email == "" { + c.UI.Email = defaultEmailFormat + } + + switch c.UI.Email { + case "mailto": + case "mailto-js": + case "obfuscate": + case "none": + default: + return fmt.Errorf("\"%s\" is not a valid email display format, choose from [mailto, mailto-js, obfuscate, none]", c.UI.Email) + } + if c.Server.Host == "" { c.Server.Host = "localhost" } diff --git a/embed/templates/commit-signature-script.html.tmpl b/embed/templates/commit-signature-script.html.tmpl new file mode 100644 index 0000000..5b0632b --- /dev/null +++ b/embed/templates/commit-signature-script.html.tmpl @@ -0,0 +1,24 @@ + +{{ define "commit-signature-script" -}} +{{- if eq .Config.UI.Email "mailto-js" -}} + +{{- end -}} +{{- end -}} diff --git a/embed/templates/commit-signature.html.tmpl b/embed/templates/commit-signature.html.tmpl new file mode 100644 index 0000000..5e9d2fc --- /dev/null +++ b/embed/templates/commit-signature.html.tmpl @@ -0,0 +1,26 @@ + +{{ define "commit-signature" -}} +{{- if eq .Config.UI.Email "none" -}} + {{- .Signature.Name -}} +{{- else if eq .Config.UI.Email "mailto" -}} + + {{- .Signature.Name -}} + +{{- else if eq .Config.UI.Email "obfuscate" -}} + {{- .Signature.Name }} + ({{- .EmailUsername -}}@example.com
{{- .EmailDomain -}}@example.com) +{{- else -}} + + {{- .Signature.Name -}} + + +{{- end -}} +{{- end -}} diff --git a/embed/templates/repo-commit.html.tmpl b/embed/templates/repo-commit.html.tmpl index 7205ddb..5b30629 100644 --- a/embed/templates/repo-commit.html.tmpl +++ b/embed/templates/repo-commit.html.tmpl @@ -14,6 +14,7 @@ SPDX-License-Identifier: MIT + {{ template "commit-signature-script" . }}
@@ -39,9 +40,7 @@ SPDX-License-Identifier: MIT