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

Option to set a own date format separate from the locale #82

Closed
Andre601 opened this issue Feb 6, 2022 · 8 comments
Closed

Option to set a own date format separate from the locale #82

Andre601 opened this issue Feb 6, 2022 · 8 comments
Labels
enhancement New feature or request

Comments

@Andre601
Copy link
Contributor

Andre601 commented Feb 6, 2022

It is surprising that there isn't a setting to set your own date format to use.

The only current way is to use the locale option which has unwanted side effects such as altering the displayed name of the month.

The reason why there should be such an option is the simple fact, that not everyone is actually using the same format for a date commonly used in that language.

As an example am I using English as my site's primary language, while using the german date format (01. January 2022) over the English one (January 01, 2022).
This causes an issue where the plugin is using the English format while I would like to use the german one instead. The issue here is that changing the locale to de would change January to Januar which is in conflict with my site's main language.

I would really appreciate it if such a setting could be added.

@timvink
Copy link
Owner

timvink commented Feb 6, 2022

It is surprising that there isn't a setting to set your own date format to use.

I guess it is. Maybe it's what happens when a plugin organically grows quite a bit.. I would probably design it differently if I would re-write it from scratch now.

The reason why there should be such an option is the simple fact, that not everyone is actually using the same format for a date commonly used in that language.

It makes sense, so let's design it :)

The format can be the format for strftime (cheatsheet), so you can use a format like %d. %B %Y (for 01. January 2022).

The format would apply to type: date, type: datetime, type: iso_date, type: iso_datetime, basically everything except timeago.

We could add a another type, name it custom, and add an extra option called custom_format. It can default to something simple like %Y-%m-%d (the only true date format, see https://xkcd.com/1179/ ;))

That way, we can also make the custom type available as extra variables available for overriding themes.

I am also planning on adding support for overriding settings on a per-page basis, using YAML frontmatter, to support use-cases like #73. You should then be able to override custom_format to change the format for a given page.

Thoughts?

@Andre601
Copy link
Contributor Author

Andre601 commented Feb 6, 2022

That sounds good.

I would be fine with a custom type with an extra setting... Tho, maybe to save effort, how about just have that separate option and if it is present, just override the type as a whole?

@timvink timvink added the enhancement New feature or request label Feb 6, 2022
@timvink
Copy link
Owner

timvink commented Feb 6, 2022

Because then you can do this:

plugins:
  - git-revision-date-localized:
      type: timeago
      custom_format: "%Y"

And on a specific, individual page, choose to change the type:

---
git-revision-date-localized--type: custom
---

# My page

I'll pick this up next time I find a chunk of time to work on the plugin :)

@Andre601
Copy link
Contributor Author

Andre601 commented Feb 6, 2022

Because then you can do this:

plugins:
  - git-revision-date-localized:
      type: timeago
      custom_format: "%Y"

And on a specific, individual page, choose to change the type:

---
git-revision-date-localized--type: custom
---

# My page

I'll pick this up next time I find a chunk of time to work on the plugin :)

Well... In that case could you just provide the custom date directly to the front matter for the same effect I would say.

timvink added a commit that referenced this issue Feb 21, 2022
@Andre601
Copy link
Contributor Author

Andre601 commented Feb 21, 2022

I'm not sure if that actually works?

I have this PR from Dependabot open that updates the plugin:
Andre601/blog#45

And I also updated the configuration within that branch itself:
https://github.com/Andre601/blog/blob/dependabot/pip/mkdocs-git-revision-date-localized-plugin-1.0.0/mkdocs.yml#L172-L174
https://github.com/Andre601/blog/blob/dependabot/pip/mkdocs-git-revision-date-localized-plugin-1.0.0/mkdocs.yml#L224
https://github.com/Andre601/blog/blob/dependabot/pip/mkdocs-git-revision-date-localized-plugin-1.0.0/mkdocs.yml#L227
https://github.com/Andre601/blog/blob/dependabot/pip/mkdocs-git-revision-date-localized-plugin-1.0.0/theme/partials/source-file.html#L13

Yet, when I check the preview of the PR, is the date not updated and still shows in the format %B %d, %Y

Example page (Date at the bottom): https://www.andre601.ch/blog/posts/2020/12-20-in-defense-of-spigotmc/

I also cleared the cache on netlify to make sure it's not an issue caused by that...

@timvink
Copy link
Owner

timvink commented Feb 22, 2022

Cool setup! Looks really good.

I cloned your repo, checked out the branch and previewed it locally:

image

That's the custom_format: '%d. %B %Y' configured in your mkdocs.yml. Changing it also changes the format correctly.

So I'm not sure what's going on tbh. I don't have any experience with netlify. I would guess indeed some kind of caching going on..

@timvink
Copy link
Owner

timvink commented Feb 24, 2022

Did you manage to fix it? Does it work for you locally as well?

@Andre601
Copy link
Contributor Author

Was indeed a caching issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants