mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-31 23:40:39 +02:00
feat(docs, blog): add support for tags.yml
, predefined list of tags (#10137)
Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com> Co-authored-by: OzakIOne <OzakIOne@users.noreply.github.com> Co-authored-by: sebastien <lorber.sebastien@gmail.com> Co-authored-by: slorber <slorber@users.noreply.github.com>
This commit is contained in:
parent
1049294ba6
commit
0eb7b64aac
63 changed files with 2597 additions and 722 deletions
packages/docusaurus-plugin-content-blog/src
|
@ -18,7 +18,6 @@ import {
|
|||
getFolderContainingFile,
|
||||
posixPath,
|
||||
Globby,
|
||||
normalizeFrontMatterTags,
|
||||
groupTaggedItems,
|
||||
getTagVisibility,
|
||||
getFileCommitDate,
|
||||
|
@ -26,9 +25,12 @@ import {
|
|||
isUnlisted,
|
||||
isDraft,
|
||||
readLastUpdateData,
|
||||
normalizeTags,
|
||||
} 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,
|
||||
|
@ -125,9 +127,11 @@ export function getBlogTags({
|
|||
isUnlisted: (item) => item.metadata.unlisted,
|
||||
});
|
||||
return {
|
||||
inline: tag.inline,
|
||||
label: tag.label,
|
||||
items: tagVisibility.listedItems.map((item) => item.id),
|
||||
permalink: tag.permalink,
|
||||
description: tag.description,
|
||||
items: tagVisibility.listedItems.map((item) => item.id),
|
||||
pages: paginateBlogPosts({
|
||||
blogPosts: tagVisibility.listedItems,
|
||||
basePageUrl: tag.permalink,
|
||||
|
@ -197,6 +201,7 @@ async function processBlogSourceFile(
|
|||
contentPaths: BlogContentPaths,
|
||||
context: LoadContext,
|
||||
options: PluginOptions,
|
||||
tagsFile: TagsFile | null,
|
||||
authorsMap?: AuthorsMap,
|
||||
): Promise<BlogPost | undefined> {
|
||||
const {
|
||||
|
@ -315,13 +320,21 @@ async function processBlogSourceFile(
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const tagsBasePath = normalizeUrl([
|
||||
const tagsBaseRoutePath = normalizeUrl([
|
||||
baseUrl,
|
||||
routeBasePath,
|
||||
tagsRouteBasePath,
|
||||
]);
|
||||
const authors = getBlogPostAuthors({authorsMap, frontMatter, baseUrl});
|
||||
|
||||
const tags = normalizeTags({
|
||||
options,
|
||||
source: blogSourceRelative,
|
||||
frontMatterTags: frontMatter.tags,
|
||||
tagsBaseRoutePath,
|
||||
tagsFile,
|
||||
});
|
||||
|
||||
return {
|
||||
id: slug,
|
||||
metadata: {
|
||||
|
@ -331,7 +344,7 @@ async function processBlogSourceFile(
|
|||
title,
|
||||
description,
|
||||
date,
|
||||
tags: normalizeFrontMatterTags(tagsBasePath, frontMatter.tags),
|
||||
tags,
|
||||
readingTime: showReadingTime
|
||||
? options.readingTime({
|
||||
content,
|
||||
|
@ -371,6 +384,8 @@ export async function generateBlogPosts(
|
|||
authorsMapPath: options.authorsMapPath,
|
||||
});
|
||||
|
||||
const tagsFile = await getTagsFile({contentPaths, tags: options.tags});
|
||||
|
||||
async function doProcessBlogSourceFile(blogSourceFile: string) {
|
||||
try {
|
||||
return await processBlogSourceFile(
|
||||
|
@ -378,6 +393,7 @@ export async function generateBlogPosts(
|
|||
contentPaths,
|
||||
context,
|
||||
options,
|
||||
tagsFile,
|
||||
authorsMap,
|
||||
);
|
||||
} catch (err) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue