From 3571ef67c114f2f99d7687bbdef15624303ad4c0 Mon Sep 17 00:00:00 2001 From: Adnan Maolood Date: Wed, 12 May 2021 15:20:14 -0400 Subject: [PATCH] Use _index for index pages Pages with the name "index" will use the page template, and pages with the name "_index" will use the index template. --- dir.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/dir.go b/dir.go index 52d66ce..f5c5a3b 100644 --- a/dir.go +++ b/dir.go @@ -60,12 +60,12 @@ func (d *Dir) _read(srcDir, path string, task *Task, cfg *Config) error { } for _, entry := range entries { name := entry.Name() - // Ignore names that start with "_" - if strings.HasPrefix(name, "_") { - continue - } path := pathpkg.Join(path, name) if entry.IsDir() { + // Ignore directories beginning with "_" + if strings.HasPrefix(name, "_") { + continue + } // Gather directory data dir := NewDir(path) if err := dir._read(srcDir, path, task, cfg); err != nil { @@ -73,6 +73,12 @@ func (d *Dir) _read(srcDir, path string, task *Task, cfg *Config) error { } d.Dirs = append(d.Dirs, dir) } else if ext := pathpkg.Ext(name); task.Match(ext) { + // Ignore pages beginning with "_" with the exception of _index pages + namePrefix := strings.TrimSuffix(name, ext) + if strings.HasPrefix(name, "_") && namePrefix != "_index" { + continue + } + srcPath := pathpkg.Join(srcDir, path) content, err := ioutil.ReadFile(srcPath) if err != nil { @@ -122,11 +128,15 @@ func (d *Dir) _read(srcDir, path string, task *Task, cfg *Config) error { } page.Content = string(content) - if strings.TrimSuffix(name, ext) == "index" { + if namePrefix == "_index" { page.Path = d.Path d.index = page } else { - path = "/" + strings.TrimSuffix(path, ext) + if namePrefix == "index" { + path = "/" + strings.TrimSuffix(path, name) + } else { + path = "/" + strings.TrimSuffix(path, ext) + } if task.UglyURLs { path += task.OutputExt } else {