New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up Date vs PublishDate #3854

Closed
bep opened this Issue Sep 2, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@bep
Member

bep commented Sep 2, 2017

Make sure that both Date and PublishDate is always set to a value if one of them is available.

See Page.update. This method extracts front matter into params and the Page struct. There are logic there to handle different "date scenarios", but there are still some cases where a page ends up without a Date or a PublishedDate.

I suggest that we before the if p.Date.IsZero() && p.s.Cfg.GetBool("useModTimeAsFallback") { in this method adds some checks:

  • If Date.IsZero then set it to PublishedDate
  • If PublishedDate.IsZero then set it to Date

To create a test for this, the simplest is probably to create something similar to TestWordCountWithAllCJKRunesWithoutHasCJKLanguage in page_test.go.

@hholi

This comment has been minimized.

Show comment
Hide comment
@hholi

hholi Sep 28, 2017

Contributor

I will have a look at it.

Contributor

hholi commented Sep 28, 2017

I will have a look at it.

@jfo

This comment has been minimized.

Show comment
Hide comment
@jfo

jfo Oct 8, 2017

Is this bug available? Do you mean in your comment something like this?

diff --git a/hugolib/page.go b/hugolib/page.go
index 306d3373..2f7ebec8 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -1147,6 +1147,14 @@ func (p *Page) update(f interface{}) error {
 	}
 	p.Params["draft"] = p.Draft
 
+	if p.Date.IsZero() {
+            p.Date = p.PublishDate
+        }
+
+	if p.PublishDate.IsZero() {
+            p.PublishDate = p.Date
+        }
+
 	if p.Date.IsZero() && p.s.Cfg.GetBool("useModTimeAsFallback") {
 		fi, err := p.s.Fs.Source.Stat(filepath.Join(p.s.PathSpec.AbsPathify(p.s.Cfg.GetString("contentDir")), p.File.Path()))
 		if err == nil {

As written, breaks the build but wanted to see if it's the right ballpark for what you mean.

jfo commented Oct 8, 2017

Is this bug available? Do you mean in your comment something like this?

diff --git a/hugolib/page.go b/hugolib/page.go
index 306d3373..2f7ebec8 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -1147,6 +1147,14 @@ func (p *Page) update(f interface{}) error {
 	}
 	p.Params["draft"] = p.Draft
 
+	if p.Date.IsZero() {
+            p.Date = p.PublishDate
+        }
+
+	if p.PublishDate.IsZero() {
+            p.PublishDate = p.Date
+        }
+
 	if p.Date.IsZero() && p.s.Cfg.GetBool("useModTimeAsFallback") {
 		fi, err := p.s.Fs.Source.Stat(filepath.Join(p.s.PathSpec.AbsPathify(p.s.Cfg.GetString("contentDir")), p.File.Path()))
 		if err == nil {

As written, breaks the build but wanted to see if it's the right ballpark for what you mean.

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Oct 8, 2017

Member

Is this bug available?

Look at @hholi 's comment. So, no.

Member

bep commented Oct 8, 2017

Is this bug available?

Look at @hholi 's comment. So, no.

@jfo

This comment has been minimized.

Show comment
Hide comment
@jfo

jfo Oct 8, 2017

Ok np! I just didn't see any activity and it sparked my interest so I thought I would ask.

@hholi lmk if you'd like any help! I will look for something else for now. 😄

jfo commented Oct 8, 2017

Ok np! I just didn't see any activity and it sparked my interest so I thought I would ask.

@hholi lmk if you'd like any help! I will look for something else for now. 😄

@bep bep added this to the v0.30 milestone Oct 13, 2017

bep added a commit to bep/hugo that referenced this issue Oct 13, 2017

bep added a commit to bep/hugo that referenced this issue Oct 13, 2017

@bep bep closed this in #3965 Oct 13, 2017

bep added a commit that referenced this issue Oct 13, 2017

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Oct 13, 2017

Member

@hholi I needed a fix for it sooner rather than later, so I added a fix myself.

Member

bep commented Oct 13, 2017

@hholi I needed a fix for it sooner rather than later, so I added a fix myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment