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

feat(blog): add LastUpdateAuthor & LastUpdateTime #9912

Merged
merged 45 commits into from
Mar 15, 2024

Conversation

OzakIOne
Copy link
Contributor

@OzakIOne OzakIOne commented Mar 5, 2024

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

Provide two options in blog showLastUpdateAuthor and showLastUpdateTime which like in docs, show the time the blog was last updated and also who updated it

blog: {
  path: 'blog',
  showLastUpdateAuthor: true,
  showLastUpdateTime: true,
}

Test Plan

  • docusaurus-utils-validation/validationSchemas.test.ts => frontMatterLastUpdateSchema schema
  • docusaurus-plugin-content-blog/index.test.ts => last update
  • docusaurus-utils/lastUpdateUtils.test.ts => readLastUpdateData

Test links

Blog preview
Blog Content Documentation

Related issues/PRs

Fix #8657

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 5, 2024
Copy link

netlify bot commented Mar 5, 2024

[V2]

Name Link
🔨 Latest commit cb7a7ee
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/65f43055928d500008e834ca
😎 Deploy Preview https://deploy-preview-9912--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

github-actions bot commented Mar 5, 2024

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 73 🟢 98 🟢 96 🟢 100 🟠 88 Report
/docs/installation 🟠 67 🟢 96 🟢 100 🟢 100 🟠 88 Report
/docs/category/getting-started 🟠 75 🟢 100 🟢 100 🟢 90 🟠 88 Report
/blog 🟠 66 🟢 100 🟢 100 🟢 90 🟠 88 Report
/blog/preparing-your-site-for-docusaurus-v3 🟠 59 🟢 96 🟢 100 🟢 100 🟠 88 Report
/blog/tags/release 🟠 71 🟢 100 🟢 100 🟠 80 🟠 88 Report
/blog/tags 🟠 75 🟢 100 🟢 100 🟢 90 🟠 88 Report

Copy link

github-actions bot commented Mar 5, 2024

Size Change: +130 B (0%)

Total Size: 992 kB

Filename Size Change
website/build/assets/css/styles.********.css 114 kB -64 B (0%)
website/build/assets/js/main.********.js 765 kB +194 B (0%)
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 75.4 kB
website/build/index.html 37.9 kB

compressed-size-action

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good start 👍

We still need to:

packages/docusaurus-plugin-content-blog/src/blogUtils.ts Outdated Show resolved Hide resolved
packages/docusaurus-plugin-content-blog/src/lastUpdate.ts Outdated Show resolved Hide resolved
@@ -28,6 +28,9 @@ const BlogPostFrontMatterAuthorSchema = Joi.object({
const FrontMatterAuthorErrorMessage =
'{{#label}} does not look like a valid blog post author. Please use an author key or an author object (with a key and/or name).';

const FrontMatterLastUpdateErrorMessage =
'{{#label}} does not look like a valid front matter FileChange object. Please use a FileChange object (with an author and/or date).';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is the historical message, but honestly, I doubt users will understand it 😅

Not sure mentioning FileChange is super useful, we just need users to know they should provide a date or an author attribute.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type FrontMatterLastUpdate = {
  author?: string;
  date?: Date | string;
};

As author seems to be only a string I wonder removing author key or an author object (with a key and/or name)

So it would be something like this :

const FrontMatterAuthorErrorMessage =
  '{{#label}} does not look like a valid blog post author. Please use a string (maybe insert example?).';

const FrontMatterLastUpdateErrorMessage =
  '{{#label}} does not look like a valid front matter date. Please use a string or date (maybe insert example?).';

Copy link
Collaborator

@slorber slorber Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As author seems to be only a string I wonder removing author key or an author object (with a key and/or name)

const FrontMatterAuthorErrorMessage =
 '{{#label}} does not look like a valid blog post author. Please use a string (maybe insert example?).';

I think you mislead blog post authors and last update author: those are different concepts

https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-blog#authors

Blog post authors (not just a single one) can be objects, strings (keys)

  export type BlogPostFrontMatterAuthor = Author & {
    /**
     * Will be normalized into the `imageURL` prop.
     */
    image_url?: string;
    /**
     * References an existing author in the authors map.
     */
    key?: string;
  };

  export type BlogPostFrontMatterAuthors =
    | string
    | BlogPostFrontMatterAuthor
    | (string | BlogPostFrontMatterAuthor)[];

Only the last update author is just a string, so your new validation error message proposal is not good.


const FrontMatterLastUpdateErrorMessage =
  '{{#label}} does not look like a valid front matter date. Please use a string or > date (maybe insert example?).';

Not good either, the last update is not a "date", but an object that can have either (or both) a date attribute (Date | string) and an author (string) attribute.

The message doesn't have to explain the types IMHO, just mention that the overall object shape is wrong and valid attribute names. Yaml will auto-convert strings to Dates depending on the format so mentioning it accept both Date + string is kind of overkill.

@OzakIOne OzakIOne marked this pull request as ready for review March 6, 2024 15:50
@OzakIOne OzakIOne requested a review from Josh-Cena as a code owner March 6, 2024 15:50
@OzakIOne OzakIOne added the pr: new feature This PR adds a new API or behavior. label Mar 6, 2024
@slorber slorber added the to backport This PR is planned to be backported to a stable version of Docusaurus label Mar 7, 2024
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good progress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Argos Add this label to run UI visual regression tests. See argos.yml GH action. CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior. to backport This PR is planned to be backported to a stable version of Docusaurus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blog posts should be able to display last update date
5 participants