Skip to content

Commit

Permalink
Merge branch 'main' into slorber/tem-fix-source-to-permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber authored May 31, 2024
2 parents d4a55c4 + 0eb7b64 commit 1ee7f64
Show file tree
Hide file tree
Showing 63 changed files with 2,385 additions and 510 deletions.
16 changes: 16 additions & 0 deletions packages/create-docusaurus/templates/shared/blog/tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
facebook:
label: Facebook
permalink: /facebook
description: Facebook tag description
hello:
label: Hello
permalink: /hello
description: Hello tag description
docusaurus:
label: Docusaurus
permalink: /docusaurus
description: Docusaurus tag description
hola:
label: Hola
permalink: /hola
description: Hola tag description

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
exports[`blog plugin process blog posts load content 1`] = `
{
"/blog/tags/tag-1": {
"description": undefined,
"inline": true,
"items": [
"/simple/slug/another",
"/another/tags",
Expand Down Expand Up @@ -63,6 +65,8 @@ exports[`blog plugin process blog posts load content 1`] = `
"unlisted": false,
},
"/blog/tags/tag-2": {
"description": undefined,
"inline": true,
"items": [
"/another/tags",
"/another/tags2",
Expand Down Expand Up @@ -148,6 +152,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 +195,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 +240,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 All @@ -248,6 +262,8 @@ exports[`blog plugin process blog posts load content 2`] = `
exports[`blog plugin works on blog tags without pagination 1`] = `
{
"/blog/tags/tag-1": {
"description": undefined,
"inline": true,
"items": [
"/simple/slug/another",
"/another/tags",
Expand Down Expand Up @@ -278,6 +294,8 @@ exports[`blog plugin works on blog tags without pagination 1`] = `
"unlisted": false,
},
"/blog/tags/tag-2": {
"description": undefined,
"inline": true,
"items": [
"/another/tags",
"/another/tags2",
Expand Down Expand Up @@ -306,6 +324,8 @@ exports[`blog plugin works on blog tags without pagination 1`] = `
"unlisted": false,
},
"/blog/tags/unlisted": {
"description": undefined,
"inline": true,
"items": [
"/another/blog-with-tags-unlisted",
],
Expand Down Expand Up @@ -337,6 +357,8 @@ exports[`blog plugin works on blog tags without pagination 1`] = `
exports[`blog plugin works with blog tags 1`] = `
{
"/blog/tags/tag-1": {
"description": undefined,
"inline": true,
"items": [
"/simple/slug/another",
"/another/tags",
Expand Down Expand Up @@ -382,6 +404,8 @@ exports[`blog plugin works with blog tags 1`] = `
"unlisted": false,
},
"/blog/tags/tag-2": {
"description": undefined,
"inline": true,
"items": [
"/another/tags",
"/another/tags2",
Expand Down Expand Up @@ -410,6 +434,8 @@ exports[`blog plugin works with blog tags 1`] = `
"unlisted": false,
},
"/blog/tags/unlisted": {
"description": undefined,
"inline": true,
"items": [
"/another/blog-with-tags-unlisted",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => {
readingTime: ({content, defaultReadingTime}) =>
defaultReadingTime({content}),
truncateMarker: /<!--\s*truncate\s*-->/,
onInlineTags: 'ignore',
} as PluginOptions,
);

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ describe('blog plugin', () => {
);
expect(relativePathsToWatch).toEqual([
'i18n/en/docusaurus-plugin-content-blog/authors.yml',
'i18n/en/docusaurus-plugin-content-blog/tags.yml',
'blog/tags.yml',
'i18n/en/docusaurus-plugin-content-blog/**/*.{md,mdx}',
'blog/**/*.{md,mdx}',
]);
Expand Down Expand Up @@ -188,6 +190,8 @@ describe('blog plugin', () => {
prevItem: undefined,
tags: [
{
description: undefined,
inline: true,
label: 'date',
permalink: '/blog/tags/date',
},
Expand Down Expand Up @@ -232,9 +236,23 @@ describe('blog plugin', () => {
},
'slorber',
],
tags: ['inlineTag', 'globalTag'],
title: 'Happy 1st Birthday Slash! (translated)',
},
tags: [],
tags: [
{
description: undefined,
inline: true,
label: 'inlineTag',
permalink: '/blog/tags/inline-tag',
},
{
description: 'Global Tag description (en)',
inline: false,
label: 'Global Tag label (en)',
permalink: '/blog/tags/global-tag-permalink (en)',
},
],
prevItem: {
permalink: '/blog/date-matter',
title: 'date-matter',
Expand Down Expand Up @@ -269,10 +287,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 +538,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
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ describe('validateOptions', () => {
});

it('accepts correctly defined user options', () => {
const userOptions = {
const userOptions: Options = {
...defaultOptions,
feedOptions: {type: 'rss' as const, title: 'myTitle'},
path: 'not_blog',
routeBasePath: '/myBlog',
postsPerPage: 5,
include: ['api/*', 'docs/*'],
tags: 'customTags.yml',
onInlineTags: 'warn',
};
expect(testValidate(userOptions)).toEqual({
...userOptions,
Expand Down Expand Up @@ -172,4 +174,68 @@ describe('validateOptions', () => {
`""blogSidebarTitle" must be a string"`,
);
});

describe('tags', () => {
it('accepts tags - undefined', () => {
expect(testValidate({tags: undefined}).tags).toBeUndefined();
});

it('accepts tags - null', () => {
expect(testValidate({tags: null}).tags).toBeNull();
});

it('accepts tags - false', () => {
expect(testValidate({tags: false}).tags).toBeFalsy();
});

it('accepts tags - customTags.yml', () => {
expect(testValidate({tags: 'customTags.yml'}).tags).toBe(
'customTags.yml',
);
});

it('rejects tags - 42', () => {
// @ts-expect-error: test
expect(() => testValidate({tags: 42})).toThrowErrorMatchingInlineSnapshot(
`""tags" must be a string"`,
);
});
});

describe('onInlineTags', () => {
it('accepts onInlineTags - undefined', () => {
expect(testValidate({onInlineTags: undefined}).onInlineTags).toBe('warn');
});

it('accepts onInlineTags - "throw"', () => {
expect(testValidate({onInlineTags: 'throw'}).onInlineTags).toBe('throw');
});

it('rejects onInlineTags - "trace"', () => {
expect(() =>
// @ts-expect-error: test
testValidate({onInlineTags: 'trace'}),
).toThrowErrorMatchingInlineSnapshot(
`""onInlineTags" must be one of [ignore, log, warn, throw]"`,
);
});

it('rejects onInlineTags - null', () => {
expect(() =>
// @ts-expect-error: test
testValidate({onInlineTags: 42}),
).toThrowErrorMatchingInlineSnapshot(
`""onInlineTags" must be one of [ignore, log, warn, throw]"`,
);
});

it('rejects onInlineTags - 42', () => {
expect(() =>
// @ts-expect-error: test
testValidate({onInlineTags: 42}),
).toThrowErrorMatchingInlineSnapshot(
`""onInlineTags" must be one of [ignore, log, warn, throw]"`,
);
});
});
});
Loading

0 comments on commit 1ee7f64

Please sign in to comment.