mirror of
https://github.com/facundoolano/jorge.git
synced 2025-01-13 20:03:26 +01:00
add support for page listing
This commit is contained in:
parent
88efad43db
commit
cea4ac7b1c
2 changed files with 48 additions and 3 deletions
|
@ -90,7 +90,7 @@ func (site *Site) loadTemplates(srcDir string) error {
|
|||
relPath, _ := filepath.Rel(srcDir, path)
|
||||
templ.Metadata["path"] = relPath
|
||||
templ.Metadata["url"] = "/" + strings.TrimSuffix(relPath, ".html")
|
||||
templ.Metadata["dir"] = "/" + filepath.Base(relPath)
|
||||
templ.Metadata["dir"] = "/" + filepath.Dir(relPath)
|
||||
|
||||
// posts are templates that can be chronologically sorted --that have a date.
|
||||
// the rest are pages.
|
||||
|
@ -106,7 +106,11 @@ func (site *Site) loadTemplates(srcDir string) error {
|
|||
}
|
||||
|
||||
} else {
|
||||
site.pages = append(site.pages, templ.Metadata)
|
||||
// the index pages should be skipped from the page directory
|
||||
filename := strings.TrimSuffix(entry.Name(), filepath.Ext(entry.Name()))
|
||||
if filename != "index" {
|
||||
site.pages = append(site.pages, templ.Metadata)
|
||||
}
|
||||
}
|
||||
site.Templates[path] = templ
|
||||
}
|
||||
|
|
|
@ -222,7 +222,48 @@ hello world!
|
|||
}
|
||||
|
||||
func TestRenderPagesInDir(t *testing.T) {
|
||||
// TODO
|
||||
root, layouts, src := newProject()
|
||||
defer os.RemoveAll(root)
|
||||
|
||||
content := `---
|
||||
title: "1. hello world!"
|
||||
---
|
||||
<p>Hello world!</p>`
|
||||
file := newFile(src, "01-hello.html", content)
|
||||
defer os.Remove(file.Name())
|
||||
|
||||
content = `---
|
||||
title: "3. goodbye!"
|
||||
---
|
||||
<p>goodbye world!</p>`
|
||||
file = newFile(src, "03-goodbye.html", content)
|
||||
defer os.Remove(file.Name())
|
||||
|
||||
content = `---
|
||||
title: "2. an oldie!"
|
||||
---
|
||||
<p>oldie</p>`
|
||||
file = newFile(src, "02-an-oldie.html", content)
|
||||
defer os.Remove(file.Name())
|
||||
|
||||
// add a page (no date)
|
||||
content = `---
|
||||
---
|
||||
<ul>{% for page in site.pages %}
|
||||
<li><a href="{{ page.url }}">{{page.title}}</a></li>{%endfor%}
|
||||
</ul>`
|
||||
|
||||
file = newFile(src, "index.html", content)
|
||||
defer os.Remove(file.Name())
|
||||
|
||||
site, err := Load(src, layouts)
|
||||
content, err = site.Render(site.Templates[file.Name()])
|
||||
assertEqual(t, err, nil)
|
||||
assertEqual(t, content, `<ul>
|
||||
<li><a href="/01-hello">1. hello world!</a></li>
|
||||
<li><a href="/02-an-oldie">2. an oldie!</a></li>
|
||||
<li><a href="/03-goodbye">3. goodbye!</a></li>
|
||||
</ul>`)
|
||||
}
|
||||
|
||||
func TestRenderArchiveWithExcerpts(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue