From 0da5389cbbf620eaec383f2346ea9c94b85ed180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20P=C3=A4per?= Date: Fri, 22 Mar 2019 01:42:36 +0100 Subject: [PATCH] ISO week date drops (#5981) Merge pull request 5981 --- docs/_docs/permalinks.md | 102 ++++++++++++++++++++++++++++------- lib/jekyll/configuration.rb | 2 + lib/jekyll/drops/url_drop.rb | 43 +++++++++++++++ 3 files changed, 128 insertions(+), 19 deletions(-) diff --git a/docs/_docs/permalinks.md b/docs/_docs/permalinks.md index 8aa9b0540..e67d850ab 100644 --- a/docs/_docs/permalinks.md +++ b/docs/_docs/permalinks.md @@ -61,8 +61,19 @@ Here's the full list of placeholders available:

- Year from the post's filename. May be overridden via the document’s - date front matter + Year from the post’s filename with four digits. + May be overridden via the document’s date front matter. +

+ + + + +

short_year

+ + +

+ Year from the post’s filename without the century. (00..99) + May be overridden via the document’s date front matter.

@@ -72,8 +83,8 @@ Here's the full list of placeholders available:

- Month from the post's filename. May be overridden via the document’s - date front matter + Month from the post’s filename. (01..12) + May be overridden via the document’s date front matter.

@@ -83,19 +94,35 @@ Here's the full list of placeholders available:

- Month without leading zeros from the post's filename. May be - overridden via the document’s date front matter + Month without leading zeros from the post’s filename. May be + overridden via the document’s date front matter.

+ + +

short_month

+ + +

Three-letter month abbreviation, e.g. “Jan”.

+ + + + +

long_month

+ + +

Full month name, e.g. “January”.

+ +

day

- Day from the post's filename. May be overridden via the document’s - date front matter + Day of the month from the post’s filename. (01..31) + May be overridden via the document’s date front matter.

@@ -105,8 +132,8 @@ Here's the full list of placeholders available:

- Day without leading zeros from the post's filename. May be overridden - via the document’s date front matter + Day of the month without leading zeros from the post’s filename. + May be overridden via the document’s date front matter.

@@ -115,18 +142,47 @@ Here's the full list of placeholders available:

y_day

-

Day of the year from the post's filename, with leading zeros.

+

Ordinal day of the year from the post’s filename, with leading zeros. (001..366)

-

short_year

+

w_year

-

- Year without the century from the post's filename. May be overridden - via the document’s date front matter -

+

Week year which may differ from the month year for up to three days at the start of January and end of December

+ + + + +

week

+ + +

Week number of the current year, starting with the first week having a majority of its days in January. (01..53)

+ + + + +

w_day

+ + +

Day of the week, starting with Monday. (1..7)

+ + + + +

short_day

+ + +

Three-letter weekday abbreviation, e.g. “Sun”.

+ + + + +

long_day

+ + +

Weekday name, e.g. “Sunday”.

@@ -135,7 +191,7 @@ Here's the full list of placeholders available:

- Hour of the day, 24-hour clock, zero-padded from the post's + Hour of the day, 24-hour clock, zero-padded from the post’s date front matter. (00..23)

@@ -146,7 +202,7 @@ Here's the full list of placeholders available:

- Minute of the hour from the post's date front matter. (00..59) + Minute of the hour from the post’s date front matter. (00..59)

@@ -156,7 +212,7 @@ Here's the full list of placeholders available:

- Second of the minute from the post's date front matter. (00..59) + Second of the minute from the post’s date front matter. (00..59)

@@ -237,6 +293,14 @@ For posts, Jekyll also provides the following built-in styles for convenience:

/:categories/:year/:y_day/:title:output_ext

+ + +

weekdate

+ + +

/:categories/:year/W:week/:short_day/:title.html

+ +

none

diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 08d09fc8c..d7e00d32f 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -305,6 +305,8 @@ module Jekyll "/:categories/:year/:month/:day/:title:output_ext" when :ordinal "/:categories/:year/:y_day/:title:output_ext" + when :weekdate + "/:categories/:year/W:week/:short_day/:title:output_ext" else permalink_style.to_s end diff --git a/lib/jekyll/drops/url_drop.rb b/lib/jekyll/drops/url_drop.rb index f0641e23c..6edb7d64d 100644 --- a/lib/jekyll/drops/url_drop.rb +++ b/lib/jekyll/drops/url_drop.rb @@ -35,46 +35,89 @@ module Jekyll category_set.to_a.join("/") end + # CCYY def year @obj.date.strftime("%Y") end + # MM: 01..12 def month @obj.date.strftime("%m") end + # DD: 01..31 def day @obj.date.strftime("%d") end + # hh: 00..23 def hour @obj.date.strftime("%H") end + # mm: 00..59 def minute @obj.date.strftime("%M") end + # ss: 00..59 def second @obj.date.strftime("%S") end + # D: 1..31 def i_day @obj.date.strftime("%-d") end + # M: 1..12 def i_month @obj.date.strftime("%-m") end + # MMM: Jan..Dec def short_month @obj.date.strftime("%b") end + # MMMM: January..December + def long_month + @obj.date.strftime("%B") + end + + # YY: 00..99 def short_year @obj.date.strftime("%y") end + # CCYYw, ISO week year + # may differ from CCYY for the first days of January and last days of December + def w_year + @obj.date.strftime("%G") + end + + # WW: 01..53 + # %W and %U do not comply with ISO 8601-1 + def week + @obj.date.strftime("%V") + end + + # d: 1..7 (Monday..Sunday) + def w_day + @obj.date.strftime("%u") + end + + # dd: Mon..Sun + def short_day + @obj.date.strftime("%a") + end + + # ddd: Monday..Sunday + def long_day + @obj.date.strftime("%A") + end + + # DDD: 001..366 def y_day @obj.date.strftime("%j") end