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(docs, blog): add support for tags.yml, predefined list of tags #10137

Merged
merged 145 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
145 commits
Select commit Hold shift + click to select a range
5e10d33
feat(docs): predefined tag list
OzakIOne May 14, 2024
5c915f9
refactor: split into functions
OzakIOne May 14, 2024
5f0c14e
refactor: apply lint autofix
OzakIOne May 14, 2024
fa572f8
wip
OzakIOne May 14, 2024
85e0bf4
refactor: apply lint autofix
OzakIOne May 14, 2024
307df02
wip: fix duplicated routes
OzakIOne May 14, 2024
0a822f3
wip
OzakIOne May 14, 2024
523c15a
wip tests
OzakIOne May 15, 2024
913b263
wip tests
OzakIOne May 15, 2024
335cbeb
wip tests
OzakIOne May 15, 2024
72cc7ad
better naming
OzakIOne May 15, 2024
257564e
wip
OzakIOne May 16, 2024
8260fed
wip
OzakIOne May 16, 2024
cff68ee
wip
OzakIOne May 16, 2024
c9b2f27
Revert "wip"
OzakIOne May 17, 2024
5145b45
Revert "wip"
OzakIOne May 17, 2024
217d4b0
Revert "wip"
OzakIOne May 17, 2024
4f3ca78
rename option name
OzakIOne May 17, 2024
f4cc3ce
read tags once per plugin
OzakIOne May 17, 2024
72fe1ec
refactor: apply lint autofix
OzakIOne May 17, 2024
1a41ef2
optin & allow false null for filepath
OzakIOne May 17, 2024
0f9b397
dogfood
OzakIOne May 17, 2024
c1961d9
check tags without joi
OzakIOne May 17, 2024
9a4c40b
add permalink support
OzakIOne May 17, 2024
4f24d5b
update test
OzakIOne May 17, 2024
a65beb8
remove processFileTagsPath async
slorber May 17, 2024
327dcd7
remove processFileTagsPath async
slorber May 17, 2024
4e30673
refactor: apply lint autofix
slorber May 17, 2024
4ed4e98
add null type
OzakIOne May 21, 2024
724b24e
add retro compatible code & update tests
OzakIOne May 21, 2024
82022c6
update tests
OzakIOne May 21, 2024
7a91499
update wip tests
OzakIOne May 21, 2024
c6580da
refactor: apply lint autofix
OzakIOne May 21, 2024
e64d48d
auto lint fix
OzakIOne May 21, 2024
2456a7f
refactor: apply lint autofix
OzakIOne May 21, 2024
fd9c966
wip
OzakIOne May 21, 2024
d0c3769
wip fix
OzakIOne May 22, 2024
4a63822
wip
OzakIOne May 22, 2024
89c14ac
wip more tests
OzakIOne May 22, 2024
d485fe5
ugly blog integration
OzakIOne May 22, 2024
6f9c7b3
shared code wip
OzakIOne May 22, 2024
dd1778d
remove dep
OzakIOne May 22, 2024
2944df6
remove useless change
OzakIOne May 22, 2024
6b03f2d
refactor code & update tests
OzakIOne May 23, 2024
f2d4584
chore: Add TagsFeature to docusaurus-types and use it in plugins
OzakIOne May 23, 2024
5af3918
fix ci ??
OzakIOne May 23, 2024
276d877
rename/move TagsFeature to TagsPluginOptions
slorber May 23, 2024
13c3e82
remove useless method
slorber May 23, 2024
f2e990c
refactor tags a bit + add todo
slorber May 23, 2024
9f7e89e
move getTagsFile to utils-validation
OzakIOne May 24, 2024
be4b7d0
refactor: apply lint autofix
OzakIOne May 24, 2024
834367c
wip
OzakIOne May 24, 2024
38d4934
wip
OzakIOne May 27, 2024
af278d4
wip
OzakIOne May 27, 2024
789574b
refactor unique permalinks
OzakIOne May 27, 2024
89affc8
remove unwanted change
OzakIOne May 27, 2024
13e8b32
renaming
OzakIOne May 27, 2024
c473da6
update config
OzakIOne May 27, 2024
44659c0
refactor feature behavior based on options
OzakIOne May 27, 2024
744bcbb
Merge branch 'main' into ozaki/tagsBlogDoc
OzakIOne May 27, 2024
fcef89c
TODO annotation for blog types
OzakIOne May 27, 2024
20ab63e
fix types
OzakIOne May 27, 2024
ecda5c0
refactor: apply lint autofix
OzakIOne May 27, 2024
095a391
fix behavior
OzakIOne May 28, 2024
7e5eb8e
wip tests
OzakIOne May 28, 2024
27fff19
wip tests
OzakIOne May 28, 2024
9769309
add docs
OzakIOne May 28, 2024
d32635f
refactor: apply lint autofix
OzakIOne May 28, 2024
da82abb
Merge branch 'main' into ozaki/tagsBlogDoc
OzakIOne May 28, 2024
08f7127
add tests
OzakIOne May 28, 2024
98d04f9
Update website/docs/api/plugins/plugin-content-blog.mdx
OzakIOne May 28, 2024
d5eba15
Update website/docs/api/plugins/plugin-content-blog.mdx
OzakIOne May 28, 2024
a7c1259
renaming
OzakIOne May 28, 2024
4b6369b
rename file
OzakIOne May 28, 2024
888f2cf
rename things
OzakIOne May 28, 2024
4c61ab6
behavior change
OzakIOne May 28, 2024
23dafc0
fix name
OzakIOne May 28, 2024
fb43efa
remove as
OzakIOne May 28, 2024
60e20c8
remove Partial
OzakIOne May 28, 2024
d725aa5
change description default to undefined
OzakIOne May 28, 2024
70f56db
remove useless check for ts
OzakIOne May 28, 2024
d53fb5c
refactor: apply lint autofix
OzakIOne May 28, 2024
04b2c09
use lodash mapValues
OzakIOne May 28, 2024
e24bc4f
do not kebab case user permalink
OzakIOne May 28, 2024
70a776f
improve error log
OzakIOne May 28, 2024
94bff22
use TagsFileInput for schemas
OzakIOne May 28, 2024
f1514c6
change behavior when oninlinetags is ignore
OzakIOne May 28, 2024
f5facae
use ternary
OzakIOne May 28, 2024
aeb3cf4
remove comments
OzakIOne May 28, 2024
450dcef
try remove function normalizeTags
OzakIOne May 28, 2024
a331746
rename processFileTagsPath to normalizeTags
OzakIOne May 28, 2024
54a6106
Update website/docs/api/plugins/plugin-content-docs.mdx
OzakIOne May 28, 2024
2ed5d9c
Update website/docs/api/plugins/plugin-content-docs.mdx
OzakIOne May 28, 2024
2a1821e
refactor logic
OzakIOne May 28, 2024
2d4f725
add tags.yml in template
OzakIOne May 29, 2024
b6e3449
refactor: apply lint autofix
OzakIOne May 29, 2024
cff6948
feat(theme): poc with description
OzakIOne May 29, 2024
b1e7c34
Remove unused code & fix tests
OzakIOne May 29, 2024
b351bc1
refactor test
OzakIOne May 30, 2024
6fa49d4
create doc
OzakIOne May 30, 2024
93865aa
update docs
OzakIOne May 30, 2024
1f3da01
update doc
OzakIOne May 30, 2024
dc8be49
put description in title
OzakIOne May 30, 2024
9dc5251
wire doc description to docs plugin UI
slorber May 30, 2024
850b0c9
Merge branch 'main' into ozaki/tagsBlogDoc
slorber May 30, 2024
29f81ec
cleanup package.json
slorber May 30, 2024
f465a75
Add tags descriptions to the init template
slorber May 30, 2024
8884806
TagsListInline should render tag description
slorber May 30, 2024
0b67e5f
dogfood add more docs tags attributes
slorber May 30, 2024
44bd575
fix DocTagDocListPage not showing doc tag description
slorber May 30, 2024
ecfe55f
Minor tags.ts refactors
slorber May 30, 2024
88096ff
fix snapshots
slorber May 30, 2024
8d80c74
refactor tags tests
slorber May 30, 2024
0a043c6
move comment
slorber May 30, 2024
e8cd65d
test normalizeTag() with tags from tagsFile
slorber May 30, 2024
8fa31c5
fix little typing issue
slorber May 30, 2024
0af6b86
add extra warn reportInlineTags test
slorber May 30, 2024
fa95a97
remove schema typo
slorber May 30, 2024
d105293
tagsFile refactor
slorber May 30, 2024
5ec16a6
Add proper getTagsFile() tests
slorber May 30, 2024
6451e8b
Add proper getTagsFile() tests
slorber May 30, 2024
e91e03c
fix getTagsFile usage in blog + docs
slorber May 30, 2024
11f1c31
refactor: apply lint autofix
slorber May 30, 2024
f36c468
DocTagDocListPageMetadata, add missing description seo meta
slorber May 31, 2024
bea279f
add docs plugin option tests for tags options
slorber May 31, 2024
7edec83
docs tests: make createTestUtils async
slorber May 31, 2024
c0b28ae
tests: ensure docs can read global tags
slorber May 31, 2024
a09f643
tests: ensure docs can read versioned tags
slorber May 31, 2024
b74f731
docs test, ensure tags file works with versioning and i18n
slorber May 31, 2024
68e5444
add blog options tests
slorber May 31, 2024
42723f8
tests: ensure blog can use tags files with i18n support
slorber May 31, 2024
b345c22
wire hot reload for tags file
slorber May 31, 2024
891755c
blog getPathsToWatch test
slorber May 31, 2024
58e24ce
update docs snapshots
slorber May 31, 2024
a70df92
fix blog RSS feed tests
slorber May 31, 2024
7018d6d
rename NormalizedTag to TagMetadata
slorber May 31, 2024
55ce8ce
blog/docsVersion tags aggregates should have TagMetadata type
slorber May 31, 2024
768fa68
api ref doc
slorber May 31, 2024
356f447
simplify docs tags guide
slorber May 31, 2024
3e1666b
simplify docs tags guide
slorber May 31, 2024
4032351
update snapshots
slorber May 31, 2024
eba218f
refactor: apply lint autofix
slorber May 31, 2024
979f3d3
empty
slorber May 31, 2024
7e6fe91
typo
slorber May 31, 2024
389e046
Use posix path join to make windows tests pass
slorber May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ exports[`blog plugin process blog posts load content 2`] = `
"source": "@site/blog/another-simple-slug-with-tags.md",
"tags": [
{
"description": undefined,
"inline": true,
"label": "tag1",
"permalink": "/blog/tags/tag-1",
},
Expand Down Expand Up @@ -189,10 +191,14 @@ exports[`blog plugin process blog posts load content 2`] = `
"source": "@site/blog/another-with-tags.md",
"tags": [
{
"description": undefined,
"inline": true,
"label": "tag1",
"permalink": "/blog/tags/tag-1",
},
{
"description": undefined,
"inline": true,
"label": "tag2",
"permalink": "/blog/tags/tag-2",
},
Expand Down Expand Up @@ -230,10 +236,14 @@ exports[`blog plugin process blog posts load content 2`] = `
"source": "@site/blog/another-with-tags2.md",
"tags": [
{
"description": undefined,
"inline": true,
"label": "tag1",
"permalink": "/blog/tags/tag-1",
},
{
"description": undefined,
"inline": true,
"label": "tag2",
"permalink": "/blog/tags/tag-2",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => {
readingTime: ({content, defaultReadingTime}) =>
defaultReadingTime({content}),
truncateMarker: /<!--\s*truncate\s*-->/,
onInlineTags: 'ignore',
tags: false,
} as PluginOptions,
);

Expand Down Expand Up @@ -141,6 +143,8 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => {
readingTime: ({content, defaultReadingTime}) =>
defaultReadingTime({content}),
truncateMarker: /<!--\s*truncate\s*-->/,
onInlineTags: 'ignore',
tags: false,
} as PluginOptions,
);

Expand Down Expand Up @@ -194,6 +198,8 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => {
readingTime: ({content, defaultReadingTime}) =>
defaultReadingTime({content}),
truncateMarker: /<!--\s*truncate\s*-->/,
onInlineTags: 'ignore',
tags: false,
} as PluginOptions,
);

Expand Down Expand Up @@ -238,6 +244,8 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => {
readingTime: ({content, defaultReadingTime}) =>
defaultReadingTime({content}),
truncateMarker: /<!--\s*truncate\s*-->/,
onInlineTags: 'ignore',
tags: false,
} as PluginOptions,
);

Expand Down Expand Up @@ -282,6 +290,8 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => {
readingTime: ({content, defaultReadingTime}) =>
defaultReadingTime({content}),
truncateMarker: /<!--\s*truncate\s*-->/,
onInlineTags: 'ignore',
tags: false,
} as PluginOptions,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ describe('blog plugin', () => {
prevItem: undefined,
tags: [
{
description: undefined,
inline: true,
label: 'date',
permalink: '/blog/tags/date',
},
Expand Down Expand Up @@ -269,10 +271,14 @@ describe('blog plugin', () => {
},
tags: [
{
description: undefined,
inline: true,
label: 'date',
permalink: '/blog/tags/date',
},
{
description: undefined,
inline: true,
label: 'complex',
permalink: '/blog/tags/complex',
},
Expand Down Expand Up @@ -516,6 +522,8 @@ describe('blog plugin', () => {
postsPerPage: 1,
processBlogPosts: async ({blogPosts}) =>
blogPosts.filter((blog) => blog.metadata.tags[0]?.label === 'tag1'),
onInlineTags: 'ignore',
tags: false,
},
DefaultI18N,
);
Expand Down
18 changes: 16 additions & 2 deletions packages/docusaurus-plugin-content-blog/src/blogUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ import {
getFolderContainingFile,
posixPath,
Globby,
normalizeFrontMatterTags,
groupTaggedItems,
getTagVisibility,
getFileCommitDate,
getContentPathList,
isUnlisted,
isDraft,
readLastUpdateData,
processFileTagsPath,
} from '@docusaurus/utils';
import {getTagsFile} from '@docusaurus/utils-validation';
import {validateBlogPostFrontMatter} from './frontMatter';
import {type AuthorsMap, getAuthorsMap, getBlogPostAuthors} from './authors';
import type {TagsFile} from '@docusaurus/utils';
import type {LoadContext, ParseFrontMatter} from '@docusaurus/types';
import type {
PluginOptions,
Expand Down Expand Up @@ -197,6 +199,7 @@ async function processBlogSourceFile(
contentPaths: BlogContentPaths,
context: LoadContext,
options: PluginOptions,
tagsFile: TagsFile | null,
authorsMap?: AuthorsMap,
): Promise<BlogPost | undefined> {
const {
Expand Down Expand Up @@ -322,6 +325,14 @@ async function processBlogSourceFile(
]);
const authors = getBlogPostAuthors({authorsMap, frontMatter, baseUrl});

const tags = processFileTagsPath({
options,
source: blogSourceRelative,
frontMatterTags: frontMatter.tags,
versionTagsPath: tagsBasePath,
tagsFile,
});

return {
id: slug,
metadata: {
Expand All @@ -331,7 +342,7 @@ async function processBlogSourceFile(
title,
description,
date,
tags: normalizeFrontMatterTags(tagsBasePath, frontMatter.tags),
tags,
readingTime: showReadingTime
? options.readingTime({
content,
Expand Down Expand Up @@ -371,13 +382,16 @@ export async function generateBlogPosts(
authorsMapPath: options.authorsMapPath,
});

const tagsFile = await getTagsFile(options, contentPaths.contentPath);

async function doProcessBlogSourceFile(blogSourceFile: string) {
try {
return await processBlogSourceFile(
blogSourceFile,
contentPaths,
context,
options,
tagsFile,
authorsMap,
);
} catch (err) {
Expand Down
18 changes: 17 additions & 1 deletion packages/docusaurus-plugin-content-blog/src/frontMatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {
FrontMatterLastUpdateSchema,
FrontMatterTOCHeadingLevels,
FrontMatterTagsSchema,
JoiFrontMatter as Joi, // Custom instance for front matter
Joi, // Custom instance for front matter
OzakIOne marked this conversation as resolved.
Show resolved Hide resolved
OzakIOne marked this conversation as resolved.
Show resolved Hide resolved
URISchema,
validateFrontMatter,
} from '@docusaurus/utils-validation';
import type {TagsFile} from '@docusaurus/utils';
import type {BlogPostFrontMatter} from '@docusaurus/plugin-content-blog';

const BlogPostFrontMatterAuthorSchema = Joi.object({
Expand Down Expand Up @@ -82,3 +83,18 @@ export function validateBlogPostFrontMatter(frontMatter: {
}): BlogPostFrontMatter {
return validateFrontMatter(frontMatter, BlogFrontMatterSchema);
}

export const tagDefinitionSchema = Joi.object<TagsFile>().pattern(
Joi.string(),
Joi.object({
label: Joi.string().required(),
description: Joi.string().required(),
permalink: Joi.string(),
}),
);

export function validateDefinedTags(
tags: unknown,
): Joi.ValidationResult<TagsFile> {
return tagDefinitionSchema.validate(tags);
}
OzakIOne marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions packages/docusaurus-plugin-content-blog/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export const DEFAULT_OPTIONS: PluginOptions = {
showLastUpdateTime: false,
showLastUpdateAuthor: false,
processBlogPosts: async () => undefined,
onInlineTags: 'warn',
tags: undefined,
};

const PluginOptionSchema = Joi.object<PluginOptions>({
Expand Down Expand Up @@ -144,6 +146,13 @@ const PluginOptionSchema = Joi.object<PluginOptions>({
processBlogPosts: Joi.function()
.optional()
.default(() => DEFAULT_OPTIONS.processBlogPosts),
onInlineTags: Joi.string()
.equal('ignore', 'log', 'warn', 'throw')
.default(DEFAULT_OPTIONS.onInlineTags),
tags: Joi.string()
.disallow('')
.allow(null, false)
.default(() => DEFAULT_OPTIONS.tags),
}).default(DEFAULT_OPTIONS);

export function validateOptions({
Expand Down
Loading