diff --git a/README.md b/README.md index a197455..7609910 100644 --- a/README.md +++ b/README.md @@ -75,12 +75,26 @@ can be used as a standalone program as well. ## Site configuration -For RSS feeds to use correct URLs, you should define `geminiBaseURL` in -Hugo's configuration file (`config.toml`, `config.yaml`, or -`config.json`). +gmnhg will pick up some attributes such as site title, base URL, and +language code from your Hugo configuration file (`config.toml`, +`config.yaml`, or `config.json`). Presently these are used in the +default RSS template. -Other attributes from this file, such as site title, will also be used -during RSS feed generation if they are defined. +gmnhg provides a way to override these attributes by defining a +`gmnhg` section in the configuration file and nesting the attributes +to override underneath this section. Presently you can override both +`baseUrl` and `title` in this manner. + +For example, you could add the following to your `config.toml` to +override your `baseUrl`: + +``` +[gmnhg] +baseUrl = "gemini://mysite.com" +``` + +This is recommended, as it will ensure that RSS links on your Gemini +site use the correct URL. ## License diff --git a/cmd/gmnhg/main.go b/cmd/gmnhg/main.go index 34e3a92..6abf3d8 100644 --- a/cmd/gmnhg/main.go +++ b/cmd/gmnhg/main.go @@ -83,10 +83,12 @@ // loaded from the Hugo configuration file (config.toml, config.yaml, // or config.json). // -// A new setting, geminiBaseURL, should be added to the Hugo -// configuration file to ensure that RSS paths are correct. This is -// more or less the same as Hugo's baseURL, but is separate in case -// your Gemini site is deployed to a different server. +// gmnhg provides a way to override these attributes by defining a +// "gmnhg" section in the configuration file and nesting the attributes +// to override underneath this section. Presently you can override both +// "baseUrl" and "title" in this manner. It is recommended to override +// at least "baseUrl" unless your site uses a protocol-relative base +// URL (beginning with a double slash instead of https://). // // RSS templates can be overriden by defining a template in one of // several places: @@ -148,10 +150,16 @@ var ( var hugoConfigFiles = []string{"config.toml", "config.yaml", "config.json"} type SiteConfig struct { - GeminiBaseURL string `yaml:"geminiBaseURL"` - Title string `yaml:"title"` - Copyright string `yaml:"copyright"` - LanguageCode string `yaml:"languageCode"` + BaseURL string `yaml:"baseURL"` + Title string `yaml:"title"` + Copyright string `yaml:"copyright"` + LanguageCode string `yaml:"languageCode"` + Gmnhg GmnhgConfig `yaml:"gmnhg"` +} + +type GmnhgConfig struct { + BaseURL string `yaml:"baseURL"` + Title string `yaml:"title"` } func copyFile(dst, src string) error { @@ -476,10 +484,12 @@ func main() { } } sc := map[string]interface{}{ - "GeminiBaseURL": siteConf.GeminiBaseURL, - "Title": siteConf.Title, - "Copyright": siteConf.Copyright, - "LanguageCode": siteConf.LanguageCode, + "BaseURL": siteConf.BaseURL, + "GmnhgBaseURL": siteConf.Gmnhg.BaseURL, + "Title": siteConf.Title, + "GmnhgTitle": siteConf.Gmnhg.Title, + "Copyright": siteConf.Copyright, + "LanguageCode": siteConf.LanguageCode, } cnt := map[string]interface{}{ "Posts": posts, diff --git a/cmd/gmnhg/templates.go b/cmd/gmnhg/templates.go index 6ce1c50..dc0db2f 100644 --- a/cmd/gmnhg/templates.go +++ b/cmd/gmnhg/templates.go @@ -52,26 +52,30 @@ Index of {{ trimPrefix "/" $dir }}: `) var defaultRssTemplate = mustParseTmpl("rss", `{{- $Site := .Site -}} -{{- $Dirname := trimPrefix "/" .Dirname -}} -{{- $DirLink := list (trimSuffix "/" $Site.GeminiBaseURL) $Dirname | join "/" | html -}} -{{- $RssLink := list (trimSuffix "/" $Site.GeminiBaseURL) (trimPrefix "/" .Link) | join "/" | html -}} +{{- $SiteTitle := or $Site.GmnhgTitle $Site.Title | html -}} +{{- $SiteBaseURL := or $Site.GmnhgBaseURL $Site.BaseURL | trimSuffix "/" | html -}} +{{- $Dirname := .Dirname | trimPrefix "/" | html -}} +{{- $DirURL := list $SiteBaseURL $Dirname | join "/" | html -}} +{{- $RssURL := list $SiteBaseURL (trimPrefix "/" .Link) | join "/" | html -}} +{{- $RssTitle := printf "%s%s" (or $SiteTitle "Site feed") (and $Dirname (printf " - %s" $Dirname)) | html -}} - {{ if $Site.Title }}{{ html $Site.Title }}{{ else }}Site feed{{ with $Dirname }} for {{ html . }}{{end}}{{end}} - {{ $DirLink }} - Recent content{{ with $Dirname }} in {{ html . }}{{end}}{{ with $Site.Title }} on {{ html . }}{{end}} + {{ $RssTitle }} + {{ $DirURL }} + Recent content{{ with $Dirname }} in {{ . }}{{end}}{{ with $SiteTitle }} on {{ . }}{{end}} gmnhg{{ with $Site.LanguageCode }} {{ html .}}{{end}}{{ with $Site.Author.email }} {{ html . }}{{ with $Site.Author.name }} ({{ html . }}){{end}} {{ html . }}{{ with $Site.Author.name }} ({{ html . }}){{end}}{{end}}{{ with $Site.Copyright }} {{ html . }}{{end}} {{ now.Format "Mon, 02 Jan 2006 15:04:05 -0700" }} - {{ printf "" $RssLink }} + {{ printf "" $RssURL }} {{ range $i, $p := .Posts | sortPosts }}{{ if lt $i 25 }} - {{- $AbsURL := list (trimSuffix "/" $Site.GeminiBaseURL) (trimPrefix "/" $p.Link) | join "/" | html }} + {{- $RelURL := trimPrefix "/" $p.Link | html -}} + {{- $AbsURL := list $SiteBaseURL $RelURL | join "/" }} - {{ if $p.Metadata.Title }}{{ html $p.Metadata.Title }}{{ else }}{{ trimPrefix "/" $p.Link | html }}{{end}} + {{ if $p.Metadata.Title }}{{ html $p.Metadata.Title }}{{ else }}{{ $RelURL }}{{end}} {{ $AbsURL }} {{ $p.Metadata.Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" }} {{ $AbsURL }}