Skip to content
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

Add option to auto-add the lastmod variable to front-matter #66

Closed
titaniumbones opened this issue Sep 8, 2017 · 12 comments
Closed

Add option to auto-add the lastmod variable to front-matter #66

titaniumbones opened this issue Sep 8, 2017 · 12 comments

Comments

@titaniumbones
Copy link
Contributor

At present, if the EXPORT_DATE and DATE properties are empty, Hugo reports the date of posts as "Updated on January 01, 0000". Instead, actual date up update should be reported. (or a more sophisticated system should be used).

@kaushalmodi
Copy link
Owner

This counters a requirement that all posts need not have dates. See #59.

Can you provide an example where the date is reported as: Updated on January 01, 0000?

@kaushalmodi
Copy link
Owner

This commit d53b557 specifically prevented that from happening.

If a date is absent for a post, you can prevent the false date stamps in HTML by having something like below in your theme:

{{ with .Params.date }}
    <span class="post-date">{{ dateFormat "Mon Jan 2, 2006" . }}</span>
{{ end }}

@titaniumbones
Copy link
Contributor Author

Can you provide an example where the date is reported as: Updated on January 01, 0000?
http://wildwater.hackinghistory.ca/article/

If a date is absent for a post, you can prevent the false date stamps in HTML by having something like below in your theme:

Hmm, I'm not sure this is a better solution -- it means I need to have a static post-date in my theme, right?

I'm not sure my hack is the right way to solve hte problem, but it seems to me that one oughtn't to be required to enter the date evry time one updates a post or page. What do you think?

@kaushalmodi
Copy link
Owner

it means I need to have a static post-date in my theme, right?

I didn't follow that. The date is derived from the front-matter.

In

{{ with .Params.date }}
    <span class="post-date">{{ dateFormat "Mon Jan 2, 2006" . }}</span>
{{ end }}
  • .Params.date is the value of date field in the front-matter.
  • If that date field is absent, that span block won't be inserted in the HTML.
  • The post-date is just a class name I gave in that example.. you don't necessarily need to assign a class name.. but having a name is useful if you want to customize the formatting of that date using CSS.
  • And "Mon Jan 2, 2006" is a standard way of specifying date formats in a Hugo template.. it's not a static date (if that's what you meant).

one oughtn't to be required to enter the date evry time one updates a post or page

Hmm, that's a different use case.. For instance, I wouldn't want to update the date meta-data each time I update an old post to fix a typo or correct some facts.

So this has to be a separate feature.. that does not change the current understanding of a the date in the front-matter.

I looked through Hugo Discourse forum and this might be something that you need: https://discourse.gohugo.io/t/how-to-use-modified-timestamp-from-file-as-lastmod/3576/15

You need to use .Param.lastmod instead of .Param.date.. and again you need to set that lastmod variable in your front matter. Now we only need to automate that lastmod frontmatter insertion.

Another option discussed in that thread is using EnableGitInfo option, also which I haven't yet used.

@kaushalmodi
Copy link
Owner

kaushalmodi commented Sep 8, 2017

See this commit.. 3a1b67a .GitInfo.AuthorDate looks like the cleanest solution.

@titaniumbones
Copy link
Contributor Author

titaniumbones commented Sep 8, 2017

I didn't follow that. The date is derived from the front-matter.

Thanks, I didn't understand the hugo date formatting functions, the clarification helps.

Hmm, that's a different use case.. For instance, I wouldn't want to update the date meta-data each time I update an old post to fix a typo or correct some facts.

yes good point. Though I think my patch will only add the date if there's no date embedded in the post.

org2blog/wp sort of solves this issue by adding a date property to the exported tree automatically if it's not present. One could do that. I personally like using the mod date as I am always revising these documents over the course of a semester, though of course since I export subtrees it's a bit hard to do that.

Now we only need to automate that lastmod frontmatter insertion.

yes, that seems like a good idea to me actually. Am only slowly figuring out what you're telling me as I write my responses!

See this commit.. 9b644f4 .GitInfo.AuthorDate looks like the cleanest solution.

looks cool but for me it's a bit tough as I am not currently saving the md files to git at all -- so I don't think that solution would work for me personally (and probably not for a lot of potential ox-hugo users, since most of us are probably only registering the osurce files in git, right?

@kaushalmodi
Copy link
Owner

and probably not for a lot of potential ox-hugo users, since most of us are probably only registering the osurce files in git, right?

The .md files need to be registered to git too if you plan to use services like Gitlab CI or Netlify. Because the job of ox-hugo is to do org -> md conversion.. then the hugo binary run by Gitlab CI or Netlify (or similar) will take care of md -> html conversion. For instance, for my https://scripter.co blog, I commit both md and org here, and the site is published using Netlify.com.

Now it's a different story if you plan to run ox-hugo + hugo both in Gitlab CI or Netlify..

I am not currently saving the md files to git at all -- so I don't think that solution would work for me personally

That's understood if you don't want to commit the .md files.. How are you publishing your site at the moment?


In the meanwhile, let me rename this Issue to a feature request for addition of auto-setting of the lastmod frontmatter variable if HUGO_LASTMOD option is non-nil.

@kaushalmodi kaushalmodi changed the title Add current date if missing EXPORT_DATE property Add option to auto-add the lastmod variable to front-matter Sep 8, 2017
@kaushalmodi
Copy link
Owner

I think my patch will only add the date if there's no date embedded in the post.

That's exactly the issue raised in #59.

Think about it.. all posts do not need to have a date stamp. If a user wants no date association with a post, they can skip the date variable in the front-matter (i.e. skip inserting the EXPORT_DATE property). Then ox-hugo shouldn't go against that will and still insert the current date.

We can instead have a feature that if HUGO_LASTMOD option is set to non-nil, ox-hugo will always insert lastmod = <CURRENT DATE STAMP> to the front matter. How does that sound?

@titaniumbones
Copy link
Contributor Author

That's understood if you don't want to commit the .md files.. How are you publishing your site at the moment?

My method right now is very clumsy. my source files are local in Dropbox and also exposed on Github (https://github.com/titaniumbones/Hacking-History/tree/2017). To publish I run hugo -s and then rsync -azvbP public/ ... to a self-hosted webserver. My preference would be to use a deploy script as described here, but I haven't set up the the git branches yet and I'm running a bit ragged...

@titaniumbones
Copy link
Contributor Author

hink about it.. all posts do not need to have a date stamp. If a user wants no date association with a post, they can skip the date variable in the front-matter (i.e. skip inserting the EXPORT_DATE property). Then ox-hugo shouldn't go against that will and still insert the current date.

We can instead have a feature that if HUGO_LASTMOD option is set to non-nil, ox-hugo will always insert lastmod = to the front matter. How does that sound?

Yeah, that sounds way better. It's a far superior option.

@kaushalmodi
Copy link
Owner

kaushalmodi commented Sep 8, 2017

My preference would be to use a deploy script as described here,

That looks too complicated :P

I can suggest Netlify (it's free, and provides https for free too). The only setting I need to build the site is in this little screenshot:

image

The build command looks complicated because I want to build the site using my self-built development version of Hugo. If you want to build using stable releases of hugo, simply set that Build Command to hugo and set something like this in a netlify.toml in your repo root (source):

[context.production.environment]
  HUGO_VERSION = "0.26"

@kaushalmodi
Copy link
Owner

@titaniumbones Try out the latest commit. See example-site/content-org/auto-set-lastmod.org for example. And here's the output .md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants