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 date to front matter when publishing draft #55

Closed
jandudulski opened this issue Nov 14, 2017 · 6 comments · Fixed by #92
Closed

Add date to front matter when publishing draft #55

jandudulski opened this issue Nov 14, 2017 · 6 comments · Fixed by #92

Comments

@jandudulski
Copy link
Contributor

Conceptually mostly the same thing as #54 but should add date to existing file when running jekyll publish path/to/draft

@pathawks pathawks added this to the 0.6.0 milestone Nov 14, 2017
@DirtyF DirtyF modified the milestones: 0.6.0, 0.7.0 Nov 14, 2017
@alzeih
Copy link
Contributor

alzeih commented Jan 12, 2018

I had a go at implementing this but I can't see a good way to solve this without introducing code that could destructively alter source files and cause unexpected behaviour with posting dates.

The easiest nearly fix would be to add a date to a draft when it is created, but this then causes problems publishing with the --date option as the two dates may disagree. Even having a unique sentinel like value to find and replace with the publish date wouldn't work if a post was published then unpublished.

Parsing source files and altering their contents seems like a recipe for breaking or losing posts. Maybe publishing could try to set the published date in the front matter and not remove the draft so the original isn't lost, but it could still cause lost or corrupted posts so would need to try to explain this to the user every time they published... yuck.

Do you have a better idea I've missed?

@jandudulski
Copy link
Contributor Author

My general idea was that the script would:

  • load draft file
  • split file into a front matter object and content
  • check if there is a date field already and prompt to verify if user wants to overwrite it
  • add date field to front matter object
  • create a new file with updated front matter and the content

But unfortunately, I haven't had time yet to take a look at how complicated it might be to implement.

@pathawks
Copy link
Member

My general idea was that the script would

I think this is the right approach

@alzeih
Copy link
Contributor

alzeih commented Jan 18, 2018

If you like, take a look at #63.

@alzeih
Copy link
Contributor

alzeih commented Jan 18, 2018

Hmm, instead of altering the file contents as well with publish and unpublish, what about a separate jekyll touch command?

It can alter any post, draft or not. Jekyll seems to prefer the yaml front matter over the filename for posts, so jekyll touch doesn't need to move the file for the new date to apply (and jekyll unpublish then jekyll publish would move the file to the current date).

All the logic for prompting the user and/or making backups before editing files would be handled by that command, and not mixed with publish and unpublish.

Downside: in some cases, more than one command is needed to publish a draft. Also, published posts with dates that are unpublished with a date must be touched to be correct.

Upside: simplifies publish and unpublish. Editing file front matter (or even contents) can then be used by another command and the prompting/backup behaviour can be shared. e.g: renaming posts, additional front matter, a edit command to open EDITOR?

@pathawks
Copy link
Member

Has PR #63

@jekyllbot jekyllbot removed the stale label Mar 18, 2018
@jekyll jekyll deleted a comment from jekyllbot Oct 7, 2018
@DirtyF DirtyF removed this from the 0.9.0 milestone Dec 9, 2018
@jekyll jekyll locked and limited conversation to collaborators Apr 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants