From b0b15146f9489208225d04b68aa185e4dbc09e90 Mon Sep 17 00:00:00 2001 From: Adnan Maolood Date: Fri, 21 May 2021 17:08:36 -0400 Subject: [PATCH] Rename Path fields to Permalink --- config.toml | 2 +- dir.go | 70 ++++++++++++++++++------------------ docs/kiln.1.scd | 10 +++--- main.go | 2 +- templates/_default/atom.xml | 10 +++--- templates/_default/index.gmi | 2 +- 6 files changed, 48 insertions(+), 48 deletions(-) diff --git a/config.toml b/config.toml index 575437d..7fd55af 100644 --- a/config.toml +++ b/config.toml @@ -5,7 +5,7 @@ urls = ["gemini://example.com"] "/" = "Example feed" [permalinks] -"/" = '/{{ .Date.Format "2006/01/02" }}/{{ path.Base .Path }}/' +"/" = "/{{ .Date.Format `2006/01/02` }}/{{ path.Base .Permalink }}/" [[tasks]] input = [".gmi"] diff --git a/dir.go b/dir.go index 078a773..b3bac5e 100644 --- a/dir.go +++ b/dir.go @@ -18,24 +18,24 @@ import ( // Dir represents a directory. type Dir struct { - Path string - Pages []*Page - Dirs []*Dir - index *Page // The index page. - feed []byte // Atom feed. + Permalink string + Pages []*Page + Dirs []*Dir + index *Page // The index page. + feed []byte // Atom feed. } // Page represents a page. type Page struct { - Title string - Date time.Time - Weight int - Path string `yaml:"-"` - FilePath string `yaml:"-"` - Content string `yaml:"-"` - Params map[string]interface{} - Prev *Page `yaml:"-"` - Next *Page `yaml:"-"` + Title string + Date time.Time + Weight int + Permalink string `yaml:"-"` + FilePath string `yaml:"-"` + Content string `yaml:"-"` + Params map[string]interface{} + Prev *Page `yaml:"-"` + Next *Page `yaml:"-"` } // read reads from a directory and indexes the files and directories within it. @@ -57,7 +57,7 @@ func (d *Dir) _read(srcDir, path string, task *Task, cfg *Site) error { continue } // Gather directory data - dir := &Dir{Path: "/" + path + "/"} + dir := &Dir{Permalink: "/" + path + "/"} if err := dir._read(srcDir, path, task, cfg); err != nil { return err } @@ -121,7 +121,7 @@ func (d *Dir) _read(srcDir, path string, task *Task, cfg *Site) error { page.FilePath = path if namePrefix == "_index" { - page.Path = d.Path + page.Permalink = d.Permalink d.index = page } else { if namePrefix == "index" { @@ -134,11 +134,11 @@ func (d *Dir) _read(srcDir, path string, task *Task, cfg *Site) error { path += "/" } } - page.Path = path - if permalink, ok := cfg.permalinks[d.Path]; ok { + page.Permalink = path + if permalink, ok := cfg.permalinks[d.Permalink]; ok { var b strings.Builder permalink.Execute(&b, page) - page.Path = b.String() + page.Permalink = b.String() } d.Pages = append(d.Pages, page) } @@ -152,7 +152,7 @@ func (d *Dir) process(cfg *Site, task *Task) error { if task.TemplateExt != "" { // Create index if d.index != nil { - tmpl, ok := cfg.templates.FindTemplate(d.Path, "index"+task.TemplateExt) + tmpl, ok := cfg.templates.FindTemplate(d.Permalink, "index"+task.TemplateExt) if ok { var b strings.Builder if err := tmpl.Execute(&b, d); err != nil { @@ -165,7 +165,7 @@ func (d *Dir) process(cfg *Site, task *Task) error { // Process pages for i := range d.Pages { var b strings.Builder - tmpl, ok := cfg.templates.FindTemplate(d.Path, "page"+task.TemplateExt) + tmpl, ok := cfg.templates.FindTemplate(d.Permalink, "page"+task.TemplateExt) if ok { if err := tmpl.Execute(&b, d.Pages[i]); err != nil { return err @@ -177,22 +177,22 @@ func (d *Dir) process(cfg *Site, task *Task) error { // Feed represents a feed. type Feed struct { - Title string // Feed title. - Path string // Feed path. - Updated time.Time // Last updated time. - Entries []*Page // Feed entries. + Title string // Feed title. + Permalink string // Feed permalink. + Updated time.Time // Last updated time. + Entries []*Page // Feed entries. } // Create feeds - if title, ok := cfg.Feeds[d.Path]; ok { + if title, ok := cfg.Feeds[d.Permalink]; ok { var b bytes.Buffer feed := &Feed{ - Title: title, - Path: d.Path, - Updated: time.Now(), - Entries: d.Pages, + Title: title, + Permalink: d.Permalink, + Updated: time.Now(), + Entries: d.Pages, } - tmpl, ok := cfg.templates.FindTemplate(d.Path, "atom.xml") + tmpl, ok := cfg.templates.FindTemplate(d.Permalink, "atom.xml") if ok { if err := tmpl.Execute(&b, feed); err != nil { return err @@ -214,7 +214,7 @@ func (d *Dir) process(cfg *Site, task *Task) error { // write writes the directory's contents to the provided destination path. func (d *Dir) write(dstDir string, task *Task) error { - dirPath := pathpkg.Join(dstDir, d.Path) + dirPath := pathpkg.Join(dstDir, d.Permalink) // Write pages pages := d.Pages @@ -222,7 +222,7 @@ func (d *Dir) write(dstDir string, task *Task) error { pages = append(pages, d.index) } for _, page := range pages { - path := page.Path + path := page.Permalink if !task.UglyURLs || page == d.index { path = pathpkg.Join(path, "index"+task.OutputExt) } @@ -321,11 +321,11 @@ func (d *Dir) Params() map[string]interface{} { func (d *Dir) getDir(path string) *Dir { // XXX: This is inefficient - if d.Path == path { + if d.Permalink == path { return d } for _, dir := range d.Dirs { - if dir.Path == path { + if dir.Permalink == path { return dir } } diff --git a/docs/kiln.1.scd b/docs/kiln.1.scd index 427f9ba..01a9ae6 100644 --- a/docs/kiln.1.scd +++ b/docs/kiln.1.scd @@ -214,7 +214,7 @@ content/blog/2021-05-12-hello-world.gmi will have a path of ``` [permalinks] - "/blog/" = "/{{ .Date.Format `2006/01/02` }}/{{ path.Base .Path }}" + "/blog/" = "/{{ .Date.Format `2006/01/02` }}/{{ path.Base .Permalink }}" ``` For more information on templates, see *TEMPLATES*. @@ -627,8 +627,8 @@ Page templates are provided with the following data: : The title of the page | Date : The date of the page -| Path -: Path to the page +| Permalink +: The permanent link to this page | Content : The contents of the page | Params @@ -654,8 +654,8 @@ Feed templates are provided with the following data: :[ *Description* | Title : Title of the feed -| Path -: Path to the feed directory +| Permalink +: The permanent link to the feed directory | Entries : List of pages in this feed diff --git a/main.go b/main.go index 24d37a6..39fb70c 100644 --- a/main.go +++ b/main.go @@ -71,7 +71,7 @@ func (site *Site) run() error { func (s *Site) runTask(task *Task) error { // Read content - s.root = &Dir{Path: "/"} + s.root = &Dir{Permalink: "/"} if err := s.root.read("content", task, s); err != nil { return err } diff --git a/templates/_default/atom.xml b/templates/_default/atom.xml index c836ac4..89cdd2a 100644 --- a/templates/_default/atom.xml +++ b/templates/_default/atom.xml @@ -1,16 +1,16 @@ {{ `` | safeHTML }} -{{ index site.URLs 0 }}{{ .Path }} +{{ index site.URLs 0 }}{{ .Permalink }} {{ .Title }} {{ .Updated.Format "2006-01-02T15:04:05Z07:00" }} - + {{ range .Entries }} - {{ index site.URLs 0 }}{{ .Path }} + {{ index site.URLs 0 }}{{ .Permalink }} {{ .Title }} {{ .Date.Format "2006-01-02T15:04:05Z07:00" }} - {{- $path := .Path }} + {{- $permalink := .Permalink }} {{- range site.URLs }} - + {{- end }} {{ end -}} diff --git a/templates/_default/index.gmi b/templates/_default/index.gmi index 6b661b0..2716f1c 100644 --- a/templates/_default/index.gmi +++ b/templates/_default/index.gmi @@ -1,6 +1,6 @@ # {{ .Title }} {{ if .Content }} {{ .Content }}{{ end }} -{{ range .Pages }}=> {{ .Path }} {{ if not .Date.IsZero -}} +{{ range .Pages }}=> {{ .Permalink }} {{ if not .Date.IsZero -}} {{.Date.Format "2006-01-02"}} {{end}}{{.Title}} {{ end -}}