Navigation Menu

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

Formatting of dates and times in a DRY manner #60

Merged
merged 2 commits into from May 24, 2018

Conversation

alzeih
Copy link
Contributor

@alzeih alzeih commented Jan 12, 2018

May make it easier to make changes to the format, i.e: to match the default format suggested

"YYYY-MM-DD HH:MM:SS +/-TTTT" as from https://jekyllrb.com/docs/frontmatter/

or to make these configurable values.

@DirtyF DirtyF requested a review from a team January 14, 2018 20:19
@alzeih
Copy link
Contributor Author

alzeih commented Jan 15, 2018

n.b: The format is also assumed by jekyll unpublish

      def name
        File.basename(path).sub %r!\d{4}-\d{2}-\d{2}-!, ""
      end

So if any changes to Jekyll::Compose::DEFAULT_DATESTAMP_FORMAT are made, it will also need to be reflected there.

This could probably be done with something like this (if the format is configurable):

diff --git a/lib/jekyll/commands/unpublish.rb b/lib/jekyll/commands/unpublish.rb
index 528f9bf..03f9b17 100644
--- a/lib/jekyll/commands/unpublish.rb
+++ b/lib/jekyll/commands/unpublish.rb
@@ -35,7 +35,12 @@ module Jekyll
       end
 
       def name
-        File.basename(path).sub %r!\d{4}-\d{2}-\d{2}-!, ""
+       begin
+          date = Time.parse(File.basename(path)).strftime(Jekyll::Compose::DEFAULT_DATESTAMP_FORMAT)
+          File.basename(path).sub "#{date}-", ""
+       rescue
+         File.basename(path).sub %r!\d{4}-\d{2}-\d{2}-!, ""
+       end
       end
     end

Although a post's title in a filename that appears valid to Time.parse could be altered unexpectedly.

@DirtyF
Copy link
Member

DirtyF commented May 24, 2018

@jekyllbot: merge +dev

@jekyllbot jekyllbot merged commit eaee85f into jekyll:master May 24, 2018
jekyllbot added a commit that referenced this pull request May 24, 2018
@jekyll jekyll locked and limited conversation to collaborators May 24, 2019
@alzeih alzeih deleted the patch-1 branch September 2, 2019 23:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants