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): warn duplicate and inline authors #10224

Merged
merged 23 commits into from
Jun 27, 2024
Merged

Conversation

OzakIOne
Copy link
Collaborator

@OzakIOne OzakIOne commented Jun 17, 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

Warn the user of inline authors and also if duplicated authors were found

MDX Blog Post

Test Plan

Unit test + ci

Test links

Unit tests and deploy

Deploy preview: https://deploy-preview-10224--docusaurus-2.netlify.app/

Related issues/PRs

Authors page

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jun 17, 2024
Copy link

netlify bot commented Jun 17, 2024

[V2]

Name Link
🔨 Latest commit 489c3e0
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/667c4f73cfb9240008daf626
😎 Deploy Preview https://deploy-preview-10224--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 Jun 17, 2024

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 64 🟢 98 🟢 96 🟢 100 🟠 88 Report
/docs/installation 🟠 57 🟢 96 🟢 100 🟢 100 🟠 88 Report
/docs/category/getting-started 🟠 75 🟢 100 🟢 100 🟢 90 🟠 88 Report
/blog 🟠 69 🟢 100 🟢 100 🟢 90 🟠 88 Report
/blog/preparing-your-site-for-docusaurus-v3 🟠 64 🟢 96 🟢 100 🟢 100 🟠 88 Report
/blog/tags/release 🟠 70 🟢 100 🟢 100 🟢 90 🟠 88 Report
/blog/tags 🟠 75 🟢 100 🟢 100 🟢 90 🟠 88 Report

Copy link

github-actions bot commented Jun 17, 2024

Size Change: +75 B (0%)

Total Size: 1.85 MB

Filename Size Change
website/.docusaurus/docusaurus.config.mjs 27.2 kB +168 B (+0.62%)
website/.docusaurus/registry.js 304 kB -51 B (-0.02%)
website/.docusaurus/routes.js 202 kB -34 B (-0.02%)
ℹ️ View Unchanged
Filename Size Change
website/.docusaurus/codeTranslations.json 2 B 0 B
website/.docusaurus/globalData.json 123 kB 0 B
website/.docusaurus/i18n.json 930 B 0 B
website/.docusaurus/routesChunkNames.json 130 kB -17 B (-0.01%)
website/.docusaurus/site-metadata.json 2.17 kB 0 B
website/build/assets/css/styles.********.css 112 kB 0 B
website/build/assets/js/main.********.js 906 kB +9 B (0%)
website/build/index.html 38.1 kB 0 B

compressed-size-action

);
}

// TODO need title check otherwise reports weird cases
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reports authors from changelog, maybe there is a better way to ignore that

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.

We'll need to handle and test the many edge cases and expose a onInlineAuthors option, similar to tags

Comment on lines 205 to 219
const inlineAuthors = updatedAuthors.filter((author) => author.inline);

const duplicateList = updatedAuthors.filter(
(author, index, self) =>
index !== self.findIndex((t) => t.name === author.name),
);

// TODO need title check otherwise reports weird cases
if (inlineAuthors.length > 0 && params.frontMatter.title) {
logger.warn(
`Inline authors found in blog [${
params.frontMatter.title
}] ${inlineAuthors.map((author) => author.name).join(', ')}`,
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need an option onInlineAuthors, it must be configurable because most blogs use inline authors atm.

// TODO need title check otherwise reports weird cases

What are those cases exactly? We need to handle those and cover with unit test edge cases

Overall the code should look quite similar to the tags code:

export function reportInlineTags({
  tags,
  source,
  options,
}: {
  tags: TagMetadata[];
  source: string;
  options: TagsPluginOptions;
}): void {
  if (options.onInlineTags === 'ignore') {
    return;
  }
  const inlineTags = tags.filter((tag) => tag.inline);
  if (inlineTags.length > 0) {
    const uniqueUnknownTags = [...new Set(inlineTags.map((tag) => tag.label))];
    const tagListString = uniqueUnknownTags.join(', ');
    logger.report(options.onInlineTags)(
      `Tags [${tagListString}] used in ${source} are not defined in ${
        options.tags ?? 'tags.yml'
      }`,
    );
  }
}

I'd prefer if the side effect (logging) wasn't performed inside getAuthors but as a separate standalone dedicated method, tested independently.

  const authors = getBlogPostAuthors({authorsMap, frontMatter, baseUrl});
  reportAuthorProblems(paramsYouNeed)

If logging requires more info about the blog (like the title/source/whatever) you can inject more as params.

packages/docusaurus-plugin-content-blog/src/authors.ts Outdated Show resolved Hide resolved
Comment on lines 225 to 229
`Duplicate authors found in blog post ${params.frontMatter.title} [${
params.frontMatter.slug
}] front matter: ${duplicateList
.map((author) => author.name)
.join(', ')}`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

front matter might have no title, no slug, and author might have no name

All these cases should be covered with unit tests

Comment on lines 207 to 210
const duplicateList = updatedAuthors.filter(
(author, index, self) =>
index !== self.findIndex((t) => t.name === author.name),
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Author might have no name

What happens if we have 2 authors with just an image? Are they considered as duplicate?

What happens if one predefined author has key "seb" and name "Seb", and there's another inline author named "Seb", are they considered as duplicate?

The current implementation is not good enough, and the method to detect duplicates is complex enough to deserve its own unit tests

Copy link
Collaborator

Choose a reason for hiding this comment

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

@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Jun 20, 2024
@slorber slorber marked this pull request as draft June 20, 2024 14:53
@ilg-ul
Copy link
Contributor

ilg-ul commented Jun 21, 2024

@OzakIOne, can you point me to the logic that computes the unique permalink for each author from the author name?

As I pointed you in another post, in my fork this logic required quite an elaborate code, to account for diacritics which must be replaced by latin letter and possible parenthesis like 'Liviu Ionescu (ilg)', which I would expect it transformed into 'liviu-ionescu-ilg'.

@OzakIOne
Copy link
Collaborator Author

@OzakIOne, can you point me to the logic that computes the unique permalink for each author from the author name?

As I pointed you in another post, in my fork this logic required quite an elaborate code, to account for diacritics which must be replaced by latin letter and possible parenthesis like 'Liviu Ionescu (ilg)', which I would expect it transformed into 'liviu-ionescu-ilg'.

For now the logic is very basic (just a check of name), I implemented it quickly in #10216 then extracted it in this PR, the logic of a duplicated author needs to be defined.

@ilg-ul
Copy link
Contributor

ilg-ul commented Jun 21, 2024

For now the logic is very basic

Ok, then I suggest you take a closer look at my implementation.

@ilg-ul
Copy link
Contributor

ilg-ul commented Jun 26, 2024

For now the logic is very basic

Or, could you consider making the logic that generates the permalink for authors configurable, for example via a hook?

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants