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 -}}@{{- .EmailDomain -}}) +{{- 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" . }}