Skip to content

Commit

Permalink
Fixed time sneaking into default post format string
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Apr 2, 2024
1 parent e741f80 commit 1041766
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 9 additions & 3 deletions material/plugins/blog/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import posixpath
import yaml

from babel.dates import format_datetime
from babel.dates import format_date, format_datetime
from datetime import datetime
from jinja2 import pass_context
from jinja2.runtime import Context
Expand Down Expand Up @@ -780,10 +780,16 @@ def _format_path_for_pagination(self, view: View, page: int):

# -------------------------------------------------------------------------

# Format date
# Format date - if the given format string refers to a predefined format,
# we format the date without a time component in order to keep sane default
# behavior, since authors will not expect time to be relevant for most posts
# as by our assumptions - see https://t.ly/Yi7ZC
def _format_date(self, date: datetime, format: str, config: MkDocsConfig):
locale: str = config.theme["language"].replace("-", "_")
return format_datetime(date, format = format, locale = locale)
if format in ["full", "long", "medium", "short"]:
return format_date(date, format = format, locale = locale)
else:
return format_datetime(date, format = format, locale = locale)

# Format date for post
def _format_date_for_post(self, date: datetime, config: MkDocsConfig):
Expand Down
12 changes: 9 additions & 3 deletions src/plugins/blog/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import posixpath
import yaml

from babel.dates import format_datetime
from babel.dates import format_date, format_datetime
from datetime import datetime
from jinja2 import pass_context
from jinja2.runtime import Context
Expand Down Expand Up @@ -780,10 +780,16 @@ def _format_path_for_pagination(self, view: View, page: int):

# -------------------------------------------------------------------------

# Format date
# Format date - if the given format string refers to a predefined format,
# we format the date without a time component in order to keep sane default
# behavior, since authors will not expect time to be relevant for most posts
# as by our assumptions - see https://t.ly/Yi7ZC
def _format_date(self, date: datetime, format: str, config: MkDocsConfig):
locale: str = config.theme["language"].replace("-", "_")
return format_datetime(date, format = format, locale = locale)
if format in ["full", "long", "medium", "short"]:
return format_date(date, format = format, locale = locale)
else:
return format_datetime(date, format = format, locale = locale)

# Format date for post
def _format_date_for_post(self, date: datetime, config: MkDocsConfig):
Expand Down

0 comments on commit 1041766

Please sign in to comment.