This commit is contained in:
ozakione 2024-04-01 18:06:14 +02:00
parent c3f32ab781
commit 8ab6ddac54
5 changed files with 38 additions and 19 deletions

View file

@ -0,0 +1,12 @@
opensource:
label: "Open-Source"
description:
message: "Open-Source Docusaurus sites can be useful for inspiration!"
id: "showcase.tag.opensource.description"
color: "#39ca30"
meta:
label: "Meta"
description:
message: "Docusaurus sites of Meta (formerly Facebook) projects"
id: "showcase.tag.meta.description"
color: "#4267b2"

View file

@ -24,6 +24,7 @@ describe('docusaurus-plugin-content-showcase', () => {
validateOptions({
validate: normalizePluginOptions,
options: {
// todo broken because we use aliasedPaths
path: 'src/showcase',
},
}),

View file

@ -83,25 +83,25 @@ describe('normalizeShowcasePluginOptions', () => {
userOptions,
),
).toThrowErrorMatchingInlineSnapshot(
`""tags" must be one of [string, array]"`,
`""tags" must be one of [string, object]"`,
);
});
it('accepts correctly defined tags object options', () => {
const userOptions = {
tags: [
{
foo: {
label: 'foo',
tags: {
favorite: {
label: 'Favorite',
description: {
message: 'bar',
id: 'baz',
message:
'Our favorite Docusaurus sites that you must absolutely check out!',
id: 'showcase.tag.favorite.description',
},
color: 'red',
color: '#e9669e',
},
},
],
};
// todo fix ts error
expect(testValidate(userOptions)).toEqual({
...defaultOptions,
...userOptions,
@ -110,22 +110,25 @@ describe('normalizeShowcasePluginOptions', () => {
it('reject bedly defined tags object options', () => {
const userOptions = {
tags: [
{
label: 'foo',
tags: {
favorite: {
label: 32,
description: {
message: 'bar',
id: 'baz',
message:
'Our favorite Docusaurus sites that you must absolutely check out!',
id: 'showcase.tag.favorite.description',
},
color: '#e9669e',
},
color: 42,
},
],
};
expect(() =>
testValidate(
// @ts-expect-error: bad attributes
userOptions,
),
).toThrowErrorMatchingInlineSnapshot(`""tags[0].color" must be a string"`);
).toThrowErrorMatchingInlineSnapshot(
`""tags.favorite.label" must be a string"`,
);
});
});

View file

@ -48,6 +48,8 @@ async function getTagsList(filePath: string | TagOption[]): Promise<string[]> {
}
const rawYaml = await fs.readFile(
// todo should we use aliasedPath ?
// because it breaks tests showcase/index.test.ts#L27-L28
aliasedSitePathToRelativePath(filePath),
'utf-8',
);
@ -95,6 +97,7 @@ export default function pluginContentShowcase(
if (!(await fs.pathExists(contentPaths.contentPath))) {
return null;
}
console.log('contentPaths:', contentPaths);
const {include} = options;