Pelican: Automatically set Date and Modified fields

Created on 21 Dec 2018  Â·  8Comments  Â·  Source: getpelican/pelican

1. Question

I don't find, what can I do, that Date and Modified would be determined automatically.

If it not possible at the time, it would be nice to have this feature.

2. Argumentation

I print in my articles and pages:

  • Date — date of file creation;
  • Modified — date of last file modification.

Kira__Pelican--ExampleDateAndModified

This is not hard to determine automatically in Python. But in Pelican I need to wrote 2 Metadata extra lines Date and Modified in every my article/page. I don't need manually write 2 extra lines when I can do it automatically.

3. Not helped

  1. Pelican documentation, issues, plugins.
  2. filetime_from_git can solve this issue, if I deploy a site from local machine. But for remote site deploying I have problems, see #813 for details.

    Kira__Pelican_&_filetime_from_git--SameDateAndModified

  3. On Stack Overflow I find this question about similar problem, but I don't understand, how I can accept it for each article/page, not for specific; see my comment.

Thanks.

All 8 comments

From this, you can auto-set the creation date with DEFAULT_DATE='fs', which collects a date from the current system timestamp.

Note that articles without a metadata creation date, if modified, will update this date to the new system timestamp.

I am unsure about automating the modification date at this time.

@Kristinita: I don't think it's advisable to rely upon the file creation date as supplied by the file system's ctime attribute. In my experience, that value can be "reset" all too easily to the current date, potentially misleading/confusing the audience and leaving you in a state where even you don't remember when the content was originally published. For this reason, I think it's best to at least record the original creation date in your content metadata.

The post date can already be determined from the mtime attribute, which means in theory you could do the following:

  1. Manually record the creation date in, say, a Created metadata field and modify your theme to use it as your "Posted" date.
  2. Set DEFAULT_DATE='fs' as @rask004 suggested and modify your theme to use date as your "Last modified" date.

That way, instead of entering two dates, you would only have to enter one date in your post metadata. Otherwise, you could submit a pull request that adds more flexible post creation/modification date handling. Alternatively, you could look at how some other date-related plugins work and develop one that adds date handling that more closely matches your desired use case.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your participation and understanding.

I would argue that the original issue is indeed present and that currently implemented logic is sub-optimal.

For example my workflow is the following:

  1. I create a new article or page - I can automate or manually add the date: metadata field since it is a one off
  2. Three weeks later, I discover that I need to amend something, so I have to do the change and also do not forget to introduce or update the modified: field.

I would argue that the creation date is a one time thing which describes when the artefact was created, while the modification date is a fluid thing that should be updated every time the artefact is touched, therefore I propose to implement the following logic instead of what we currently have:

  1. a new artefact is discovered by pelican
  2. if DEFAULT_DATE='fs' then get the mtime from the filesystem and set both 'date:' and 'modified:' meta fields to the retrieved timestamp
  3. if the artefact defines any of the fields (e.g. it defines 'date:' in the header), replace the corresponding metadata with the explicitly defined field.

This logic allows to serve everybody's needs:

  • if you want to have your articles to be fully dynamic, you don't need to introduce any fields in the header and both timestamps will match your filesystem timestamp;
  • if you want to dynamically track changes, then set date: in your header only (this will result in modified: being populated from the filesystem;
  • if you are old-school and do not trust your filesystem, you can set both fields explicitly in the header and you will get what you asked.

:)

@justinmayer , I can work on this logic and submit a PR, if you are interested (I cannot re-open the issue, though)

You can't (easily) get "creation date" from filesystem on some systems (ref).

If you're not using CACHE_*, "new" doesn't mean much to pelican. Or to say it differently, everything is "new" at each run.

But, sure you have an issue now @galaxy4public :).

I was not after detecting true creation time, all I wanted is to automate something everybody is silently hating :) as to manually update modified:. The PR is coming and it is just one line in readers.py.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rpmzandwijk picture rpmzandwijk  Â·  3Comments

karlcow picture karlcow  Â·  5Comments

Moini picture Moini  Â·  6Comments

kele14x picture kele14x  Â·  7Comments

iKevinY picture iKevinY  Â·  5Comments