Comments (9)
Thank you!
from docusaurus.
👍 looks like a good change
Not sure about the proposed solution though, adding an option does not seem to be ideal considering it's a reasonable default and user can swizzle.
IMHO we should move this function to theme-common instead of having a blogPost.metadata.formattedDate
.
function formatBlogPostDate(
locale: string,
date: Date,
calendar: string,
): string {
try {
return new Intl.DateTimeFormat(locale, {
day: 'numeric',
month: 'long',
year: 'numeric',
timeZone: 'UTC',
calendar,
}).format(date);
} catch (err) {
logger.error`Can't format blog post date "${String(date)}"`;
throw err;
}
}
from docusaurus.
adding an option does not seem to be ideal considering it's a reasonable default and user can swizzle
I'm not sure I understand your proposal, do you mean to make the default hide the year?
If so, that's fine with me, I used options everywhere exactly because I wanted to preserve compatibility with the current behaviour, but this might not be the best solution.
from docusaurus.
Yes, the year is already displayed above so it's fine to not add it again on every single line IMHO.
If the formatting of the date is in the React code (instead of Node), users who do not like this change could revert with swizzle, so it's not risky to ship.
from docusaurus.
it's fine to not add it again on every single line
Ok, agree.
... formatting of the date is in the React code ...
I guess this is possible, but probably requires another hook to accommodate for special formatting cases.
In my case, when using event dates with partial content, for example only the year, the formatted date is empty, and the post title should be rendered at the beginning of the line; similarly, event dates with year and month only (no day), should have only the month name shown before the title.
So, regardless of the solution, if it can accommodate custom front matter properties like my event dates, it'll probably be ok.
from docusaurus.
I guess this is possible, but probably requires another hook to accommodate for special formatting cases.
If the formatting is done on the React code, someone that wants to format the date differently can simply swizzle our code.
We'd likely expose a theme-common
blog date formatting helper, that we would use in date components. However, the user remain free to swizzle and use their own code to format the dates if they don't like the defaults we provide.
If you swizzle the archive page, you can render the blog posts the way you want (including dates), and also re-order them and group them the way you want, using official metadata or custom front matter. So technically nothing is impossible as long as you have access to the data you need here, which is already the case.
Afaik when this Node.js formatting was added we didn't have a theme-common
package so it was probably used on the Node.js side to avoid some frontend theme code duplication. Now we have a place to share code between the many blog components that render dates so we can move it back to the frontend side.
from docusaurus.
Ok, in this case I guess it is better to ignore my proposed implementation and use your solution.
from docusaurus.
Thank @OzakIOne :)
Now you can swizzle the blog archive component and choose how to format the date yourself
from docusaurus.
Thank you both, @OzakIOne and @slorber !
Now you can swizzle the blog archive component and choose how to format the date yourself
Sure. I'll wait for the other issues to be closed (especially the lastUpdateTime for blogs and Authors pages), and then I'll try to rework my site. If I'll no longer need the fork, I'll consider it a success.
from docusaurus.
Related Issues (20)
- Updating to 3.2 breaks tailwind integration in production HOT 17
- Usage of polyfill configuration throws error HOT 6
- Code block highlighting in combination with showLineNumbers not rendering correctly HOT 1
- TOC items don't show words when they come from components HOT 2
- TOC shows comments in headings HOT 2
- HTML email addresses get rendered as nested links, ignoring `href` attribute HOT 2
- Allow codeblocks to show only part of the content HOT 2
- Broken anchors: page not scroll to the right section HOT 8
- Index pages cannot be generated with an automatically generated siderbar HOT 1
- Document solution to "docs last update" date being rendered incorrectly when published through Vercel
- Customizing admonitions not work HOT 3
- When testing on StrictMode, the bar remains on the top HOT 1
- Node.js building getting stuck HOT 2
- Updating to @mdx-js/react 3.0.1 causes admonition blocks to stop rendering colored box HOT 8
- The <!--truncate--> line in my long blog post on the initialized website is not causing the blog post size to be limited. HOT 1
- Add trailing slash to auto generated sitemap.xml for directories only HOT 3
- blogTitle not working HOT 4
- Using partial props in links causes false positive `onBrokenLinks` HOT 2
- SPA opt-out: make prefetching/preloading and routing configurable HOT 8
- The MDX compiler encounters an error when a listitem element appears directly before the closing </tab> tag without proper indentation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docusaurus.