GithubHelp home page GithubHelp logo

Comments (9)

ilg-ul avatar ilg-ul commented on May 1, 2024 1

Thank you!

from docusaurus.

slorber avatar slorber commented on May 1, 2024

👍 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.

ilg-ul avatar ilg-ul commented on May 1, 2024

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.

slorber avatar slorber commented on May 1, 2024

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.

ilg-ul avatar ilg-ul commented on May 1, 2024

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.

slorber avatar slorber commented on May 1, 2024

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.

ilg-ul avatar ilg-ul commented on May 1, 2024

Ok, in this case I guess it is better to ignore my proposed implementation and use your solution.

from docusaurus.

slorber avatar slorber commented on May 1, 2024

Thank @OzakIOne :)

Now you can swizzle the blog archive component and choose how to format the date yourself

from docusaurus.

ilg-ul avatar ilg-ul commented on May 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.