Skip to content

Commit 4c02a52

Browse files
jmooringbep
authored andcommitted
resources/page: Validate predefined front matter dates
Closes #10717
1 parent 578442f commit 4c02a52

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

hugolib/content_map_test.go

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func TestContentMapSite(t *testing.T) {
2828
pageTempl := `
2929
---
3030
title: "Page %d"
31-
date: "2019-06-0%d"
32-
lastMod: "2019-06-0%d"
31+
date: "2019-06-%02d"
32+
lastMod: "2019-06-%02d"
3333
categories: [%q]
3434
---
3535
@@ -55,7 +55,6 @@ draft: true
5555
title: "Hugo Home"
5656
cascade:
5757
description: "Common Description"
58-
5958
---
6059
6160
Home Content.
@@ -64,24 +63,24 @@ Home Content.
6463
b.WithContent("blog/page1.md", createPage(1))
6564
b.WithContent("blog/page2.md", createPage(2))
6665
b.WithContent("blog/page3.md", createPage(3))
67-
b.WithContent("blog/bundle/index.md", createPage(12))
66+
b.WithContent("blog/bundle/index.md", createPage(4))
6867
b.WithContent("blog/bundle/data.json", "data")
69-
b.WithContent("blog/bundle/page.md", createPage(99))
70-
b.WithContent("blog/subsection/_index.md", createPage(3))
68+
b.WithContent("blog/bundle/page.md", createPage(5))
69+
b.WithContent("blog/subsection/_index.md", createPage(6))
7170
b.WithContent("blog/subsection/subdata.json", "data")
72-
b.WithContent("blog/subsection/page4.md", createPage(8))
73-
b.WithContent("blog/subsection/page5.md", createPage(10))
71+
b.WithContent("blog/subsection/page4.md", createPage(7))
72+
b.WithContent("blog/subsection/page5.md", createPage(8))
7473
b.WithContent("blog/subsection/draft/index.md", draftTemplate)
7574
b.WithContent("blog/subsection/draft/data.json", "data")
7675
b.WithContent("blog/draftsection/_index.md", draftTemplate)
77-
b.WithContent("blog/draftsection/page/index.md", createPage(12))
76+
b.WithContent("blog/draftsection/page/index.md", createPage(9))
7877
b.WithContent("blog/draftsection/page/folder/data.json", "data")
79-
b.WithContent("blog/draftsection/sub/_index.md", createPage(12))
80-
b.WithContent("blog/draftsection/sub/page.md", createPage(13))
81-
b.WithContent("docs/page6.md", createPage(11))
82-
b.WithContent("tags/_index.md", createPageInCategory(32, "sad"))
83-
b.WithContent("overlap/_index.md", createPageInCategory(33, "sad"))
84-
b.WithContent("overlap2/_index.md", createPage(34))
78+
b.WithContent("blog/draftsection/sub/_index.md", createPage(10))
79+
b.WithContent("blog/draftsection/sub/page.md", createPage(11))
80+
b.WithContent("docs/page6.md", createPage(12))
81+
b.WithContent("tags/_index.md", createPageInCategory(13, "sad"))
82+
b.WithContent("overlap/_index.md", createPageInCategory(14, "sad"))
83+
b.WithContent("overlap2/_index.md", createPage(15))
8584

8685
b.WithTemplatesAdded("layouts/index.html", `
8786
Num Regular: {{ len .Site.RegularPages }}|{{ range .Site.RegularPages }}{{ .RelPermalink }}|{{ end }}$
@@ -118,7 +117,7 @@ Pages: {{ range $blog.Pages }}{{ .RelPermalink }}|{{ end }}
118117
Sections: {{ range $home.Sections }}{{ .RelPermalink }}|{{ end }}:END
119118
Categories: {{ range .Site.Taxonomies.categories }}{{ .Page.RelPermalink }}; {{ .Page.Title }}; {{ .Count }}|{{ end }}:END
120119
Category Terms: {{ $categories.Kind}}: {{ range $categories.Data.Terms.Alphabetical }}{{ .Page.RelPermalink }}; {{ .Page.Title }}; {{ .Count }}|{{ end }}:END
121-
Category Funny: {{ $funny.Kind}}; {{ $funny.Data.Term }}: {{ range $funny.Pages }}{{ .RelPermalink }};|{{ end }}:END
120+
Category Funny: {{ $funny.Kind}}; {{ $funny.Data.Term }}: {{ range $funny.Pages }}{{ .RelPermalink }}|{{ end }}:END
122121
Pag Num Pages: {{ len .Paginator.Pages }}
123122
Pag Blog Num Pages: {{ len $blog.Paginator.Pages }}
124123
Blog Num RegularPages: {{ len $blog.RegularPages }}|{{ range $blog.RegularPages }}P: {{ .RelPermalink }}|{{ end }}
@@ -142,11 +141,11 @@ Draft5: {{ if (.Site.GetPage "blog/draftsection/sub/page") }}FOUND{{ end }}|
142141
Main Sections: [blog]
143142
Pag Num Pages: 9
144143
145-
Home: Hugo Home|/|2019-06-08|Current Section: /|Resources:
146-
Blog Section: Blogs|/blog/|2019-06-08|Current Section: /blog|Resources:
147-
Blog Sub Section: Page 3|/blog/subsection/|2019-06-03|Current Section: /blog/subsection|Resources: application: /blog/subsection/subdata.json|
144+
Home: Hugo Home|/|2019-06-15|Current Section: /|Resources:
145+
Blog Section: Blogs|/blog/|2019-06-11|Current Section: /blog|Resources:
146+
Blog Sub Section: Page 6|/blog/subsection/|2019-06-06|Current Section: /blog/subsection|Resources: application: /blog/subsection/subdata.json|
148147
Page: Page 1|/blog/page1/|2019-06-01|Current Section: /blog|Resources:
149-
Bundle: Page 12|/blog/bundle/|0001-01-01|Current Section: /blog|Resources: application: /blog/bundle/data.json|page: |
148+
Bundle: Page 4|/blog/bundle/|2019-06-04|Current Section: /blog|Resources: application: /blog/bundle/data.json|page: |
150149
IsDescendant: true: true true: true true: true true: true true: true false: false false: false
151150
IsAncestor: true: true true: true true: true true: true true: true true: true false: false false: false false: false false: false
152151
IsDescendant overlap1: false: false
@@ -157,11 +156,11 @@ Draft5: {{ if (.Site.GetPage "blog/draftsection/sub/page") }}FOUND{{ end }}|
157156
InSection: true: true false: false
158157
Next: /blog/page3/
159158
NextInSection: /blog/page3/
160-
Pages: /blog/page3/|/blog/subsection/|/blog/page2/|/blog/page1/|/blog/bundle/|
161-
Sections: /blog/|/docs/|/overlap/|/overlap2/|:END
159+
Pages: /blog/subsection/|/blog/bundle/|/blog/page3/|/blog/page2/|/blog/page1/|
160+
Sections: /overlap2/|/overlap/|/docs/|/blog/|:END
162161
Categories: /categories/funny/; Funny; 12|/categories/sad/; Sad; 2|:END
163162
Category Terms: taxonomy: /categories/funny/; Funny; 12|/categories/sad/; Sad; 2|:END
164-
Category Funny: term; funny: /blog/subsection/page4/;|/blog/page3/;|/blog/subsection/;|/blog/page2/;|/blog/page1/;|/blog/subsection/page5/;|/docs/page6/;|/blog/bundle/;|/blog/draftsection/page/;|/blog/draftsection/sub/;|/blog/draftsection/sub/page/;|/overlap2/;|:END
163+
Category Funny: term; funny: /overlap2/|/docs/page6/|/blog/draftsection/sub/page/|/blog/draftsection/sub/|/blog/draftsection/page/|/blog/subsection/page5/|/blog/subsection/page4/|/blog/subsection/|/blog/bundle/|/blog/page3/|/blog/page2/|/blog/page1/|:END
165164
Pag Num Pages: 9
166165
Pag Blog Num Pages: 4
167166
Blog Num RegularPages: 4

hugolib/page__meta.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ func (p *pageState) setMetaPostParams() error {
425425
ModTime: mtime,
426426
GitAuthorDate: gitAuthorDate,
427427
Location: langs.GetLocation(pm.s.Language()),
428+
PathOrTitle: p.pathOrTitle(),
428429
}
429430

430431
// Handle the date separately

resources/page/pagemeta/page_frontmatter.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ type FrontMatterDescriptor struct {
330330
// if page is a leaf bundle, the bundle folder name (ContentBaseName).
331331
BaseFilename string
332332

333+
// The Page's path if the page is backed by a file, else its title.
334+
PathOrTitle string
335+
333336
// The content file's mod time.
334337
ModTime time.Time
335338

@@ -736,7 +739,7 @@ func (f *frontmatterFieldHandlers) newDateFieldHandler(key string, setter func(d
736739
var err error
737740
date, err = htime.ToTimeInDefaultLocationE(v, d.Location)
738741
if err != nil {
739-
return false, nil
742+
return false, fmt.Errorf("invalid front matter: %s: %s: see %s", key, v, d.PathOrTitle)
740743
}
741744
d.PageConfig.Params[key] = date
742745
}

0 commit comments

Comments
 (0)