mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
feat: doc tags (same as blog tags) (#3646)
* [v2] tags to doc, same as tags to blog - [IN PROGRESS] - Addition of plugin-content-docs - Addition of DocTagsListPage in `docusaurus-theme-classic` ! Error exists for this commit towards the theme aspect and help required. Commit towards #3434 * docs: make tags list page work * temp: disable onBrokenLinks * theme bootstrap: create DocTagsListPage * DocTagsPage added and functionality too - individual doc tag page added to show docs for that specific tag * Added all Docs Tags Link * add some shared tag utils * move tag tests to _dogfooding * fix type * fix some tests * fix blog test * refactor blog post tags handling * better yaml tag examples * better dogfood md files * refactor and factorize theme tag components * finish DocTagDocListPage * Extract DocItemFooter + add inline tag list * minor fix * better typings * fix versions.test.ts tests * add tests for doc tags * fix tests * test toTagDocListProp * move shared theme code to tagUtils * Add new theme translation keys * move common theme code to tagUtils + add tests * update-code-translations should handle theme-common * update french translation * revert add translation * fix pluralization problem in theme.docs.tagDocListPageTitle * add theme component configuration options * add more tags tests * add documentation for docs tagging Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
f666de7e59
commit
f9c79cbd58
81 changed files with 1874 additions and 381 deletions
|
@ -16,6 +16,7 @@ import {
|
|||
BlogPost,
|
||||
BlogContentPaths,
|
||||
BlogMarkdownLoaderOptions,
|
||||
BlogTags,
|
||||
} from './types';
|
||||
import {
|
||||
parseMarkdownFile,
|
||||
|
@ -26,6 +27,8 @@ import {
|
|||
posixPath,
|
||||
replaceMarkdownLinks,
|
||||
Globby,
|
||||
normalizeFrontMatterTags,
|
||||
groupTaggedItems,
|
||||
} from '@docusaurus/utils';
|
||||
import {LoadContext} from '@docusaurus/types';
|
||||
import {validateBlogPostFrontMatter} from './blogFrontMatter';
|
||||
|
@ -43,6 +46,20 @@ export function getSourceToPermalink(
|
|||
);
|
||||
}
|
||||
|
||||
export function getBlogTags(blogPosts: BlogPost[]): BlogTags {
|
||||
const groups = groupTaggedItems(
|
||||
blogPosts,
|
||||
(blogPost) => blogPost.metadata.tags,
|
||||
);
|
||||
return mapValues(groups, (group) => {
|
||||
return {
|
||||
name: group.tag.label,
|
||||
items: group.items.map((item) => item.id),
|
||||
permalink: group.tag.permalink,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const DATE_FILENAME_REGEX = /^(?<date>\d{4}[-/]\d{1,2}[-/]\d{1,2})[-/]?(?<text>.*?)(\/index)?.mdx?$/;
|
||||
|
||||
type ParsedBlogFileName = {
|
||||
|
@ -240,6 +257,8 @@ async function processBlogSourceFile(
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const tagsBasePath = normalizeUrl([baseUrl, options.routeBasePath, 'tags']); // make this configurable?
|
||||
|
||||
return {
|
||||
id: frontMatter.slug ?? title,
|
||||
metadata: {
|
||||
|
@ -250,7 +269,7 @@ async function processBlogSourceFile(
|
|||
description,
|
||||
date,
|
||||
formattedDate,
|
||||
tags: frontMatter.tags ?? [],
|
||||
tags: normalizeFrontMatterTags(tagsBasePath, frontMatter.tags),
|
||||
readingTime: showReadingTime ? readingTime(content).minutes : undefined,
|
||||
truncated: truncateMarker?.test(content) || false,
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue