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(content-docs, content-blog): global tags list file & better validation #6025

Closed
wants to merge 9 commits into from

Conversation

mambax
Copy link

@mambax mambax commented Nov 27, 2021

Addresses #5913

Motivation

#5913

Have you read the Contributing Guidelines on pull requests?

Yes.

Test Plan

@facebook-github-bot

This comment has been minimized.

- Tests missing yet
- Logic is not 100% as Josh-Cena asked for (its too complex for me tbh)
- Some code duplicates can be refactored
- Docs missing?
@netlify
Copy link

netlify bot commented Nov 27, 2021

✔️ [V2]
Built without sensitive environment variables

🔨 Explore the source changes: b611ce1

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/61a288bbe9c51b0007be8fda

😎 Browse the preview: https://deploy-preview-6025--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Nov 27, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟢 Performance 93
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-6025--docusaurus-2.netlify.app/

@netlify

This comment has been minimized.

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Nov 27, 2021
@facebook-github-bot

This comment has been minimized.

@Josh-Cena Josh-Cena changed the title DRAFT: Predefined tag list feat(content-docs, content-blog): global tags list file & better validation Dec 3, 2021
@Josh-Cena Josh-Cena added the pr: new feature This PR adds a new API or behavior. label Dec 3, 2021
@Josh-Cena Josh-Cena linked an issue Dec 3, 2021 that may be closed by this pull request
2 tasks
@Josh-Cena
Copy link
Collaborator

Josh-Cena commented Dec 31, 2021

Hey, I'll work on this for the coming week and hopefully make it ready for merge

@mambax
Copy link
Author

mambax commented Jan 11, 2022

After discussion with @Josh-Cena I set this to Ready for review.

@mambax mambax marked this pull request as ready for review January 11, 2022 10:22
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.

Thanks, that looks like a great first working version 👍

I left a few comments and a few changes that we should probably discuss

The PR mention docs but I don't see any impl for the docs plugin yet: it's probably better to do the impl in both plugins at once for consistency.

Also need some documentation :)

return Joi.attempt(content, TagsMapSchema);
}

export async function getTagsMap(params: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't this be in "utils" if we want it for docs too?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I't fine. It's a very lightweight wrapper around a utils function anyways.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I meant we'd need this in the docs plugin too?

return {
label: tagString,
permalink: kebabCase(tagString),
};
}

function normalizeTagObject(tag: Partial<Tag>) {
return {
label: tag.label!,
Copy link
Collaborator

Choose a reason for hiding this comment

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

in which case there's no label here? maybe the type is wrong?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, the label is the only required value. I just don't feel like it's useful to override one key to required🤦‍♂️


export type Tag = {
label: string;
permalink: string;
};

export type FrontMatterTag = string | Tag;
export type FrontMatterTag = string | Partial<Tag>;
export type TagsMap = Record<string, Partial<Tag>>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMHO the Tag object shouldn't be partial.

Maybe we should normalize the tagsMap on load so that referenced tags contain at least a label

Maybe create a type like "TagConfig" ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The problem is that we may add more stuff in the future like description, permalink, etc. I feel like it's valuable to make it remain partial, because maybe not everything makes sense to have a default?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Josh-Cena I don't imagine any case where a tag without label make sense.

At the end of the day, we must display that tag somewhere in the UI, so there should always be at least a label

@@ -4,7 +4,7 @@ author: Christine Abernathy
authorURL: http://twitter.com/abernathyca
authorImageURL: https://github.com/caabernathy.png
authorTwitter: abernathyca
tags: [profilo, adoption]
tags: [{label: profilo}, adoption]
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we really want to enable such syntax?

IMHO the ability to pass a permalink inline (and any other shred config that we might introduce later) does not make much sense as it leads to potential non-deterministic behavior when 2 tags are using 2 different inline configs due to bad copy-pasting.

IMHO we should deprecate (or breaking change) the usage of permalink and just support a simple array: (Label | Key)[]

I know that we support inline blog authors with config, but unlike inline authors, tags always have a dedicated page (inline or not) so we probably always force enforce a unique tag config here.

@Josh-Cena
Copy link
Collaborator

@slorber The current design is like: there are two modes, I would call them "lax mode" and "strict mode". If there isn't a tags.yml file, the app is in "lax mode" (the legacy mode) and every string is a tag label. If there is a tags map file, every string is a tag key and non-recognized keys will cause errors.

However, I'd like to retain the ability to have inline tags in case it's not worth to declare a special key for this, maybe because the tag will only ever be used once. If you don't think this feature is worth keeping I'm fine to remove it, but then we would have a too bloated tags.yml file.

@slorber
Copy link
Collaborator

slorber commented Jan 27, 2022

However, I'd like to retain the ability to have inline tags in case it's not worth to declare a special key for this, maybe because the tag will only ever be used once. If you don't think this feature is worth keeping I'm fine to remove it, but then we would have a too bloated tags.yml file.

I don't like this idea, particularly because 2 inline tags with the same key can have conflicting data

I'd rather be strict by default but fail-safe: emit a warning for tags not found in the yml file, and convert them to {label: tagKey} so that it can still render


Unlike blog posts and inline authors, tags always have a page with a permalink and SEO data.

It's fine for a blog post to have the same author twice with different descriptions, maybe because the role or image of the author is updated over time and it's a snapshot.

I don't think it's the case for tags where you'd rather be consistent. Reconciling/merging data for 2 similar inline tags seems risky and non-deterministic.

You may ask: what if we later introduce a page for each blog author => Similarly, I think we'll only create pages for declared authors, not inline ones

@mambax mambax closed this by deleting the head repository Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Predefined tag lists per plugin/preset
4 participants