mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-10 23:02:56 +02:00
ShowcaseDetails component
This commit is contained in:
parent
7daa9a1d04
commit
c542c81cb8
4 changed files with 68 additions and 35 deletions
|
@ -16,6 +16,17 @@ import {contentAuthorsSchema} from './options';
|
|||
import type {LoadContext, Plugin} from '@docusaurus/types';
|
||||
import type {PluginOptions, Content} from '@docusaurus/plugin-showcase';
|
||||
|
||||
// https://stackoverflow.com/a/71166133
|
||||
const walk = async (dirPath: string): Promise<any[]> =>
|
||||
Promise.all(
|
||||
await fs.readdir(dirPath, {withFileTypes: true}).then((entries) =>
|
||||
entries.map((entry) => {
|
||||
const childPath = path.join(dirPath, entry.name);
|
||||
return entry.isDirectory() ? walk(childPath) : childPath;
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
export default function pluginContentShowcase(
|
||||
context: LoadContext,
|
||||
options: PluginOptions,
|
||||
|
@ -36,35 +47,33 @@ export default function pluginContentShowcase(
|
|||
// },
|
||||
|
||||
async loadContent(): Promise<Content> {
|
||||
const files = await fs.readdir(path.join(siteDir, options.path));
|
||||
const yamlFiles = files.filter((file) => file.endsWith('.yaml'));
|
||||
const files: string[] = await walk(path.join(siteDir, options.path));
|
||||
console.log('allFiles:', files.flat(Number.POSITIVE_INFINITY));
|
||||
const contentPromises = files
|
||||
.flat(Number.POSITIVE_INFINITY)
|
||||
.map(async (file) => {
|
||||
const rawYaml = await fs.readFile(path.join(file), 'utf-8');
|
||||
const yaml = Yaml.load(rawYaml);
|
||||
const parsedYaml = contentAuthorsSchema.validate(yaml);
|
||||
|
||||
const contentPromises = yamlFiles.map(async (file) => {
|
||||
const rawYaml = await fs.readFile(
|
||||
path.join(siteDir, options.path, file),
|
||||
'utf-8',
|
||||
);
|
||||
const yaml = Yaml.load(rawYaml);
|
||||
const parsedYaml = contentAuthorsSchema.validate(yaml);
|
||||
if (parsedYaml.error) {
|
||||
throw new Error(`Validation failed: ${parsedYaml.error.message}`, {
|
||||
cause: parsedYaml.error,
|
||||
});
|
||||
}
|
||||
|
||||
if (parsedYaml.error) {
|
||||
throw new Error(`Validation failed: ${parsedYaml.error.message}`, {
|
||||
cause: parsedYaml.error,
|
||||
});
|
||||
}
|
||||
const {title, description, preview, website, source, tags} =
|
||||
parsedYaml.value;
|
||||
|
||||
const {title, description, preview, website, source, tags} =
|
||||
parsedYaml.value;
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
preview,
|
||||
website,
|
||||
source,
|
||||
tags,
|
||||
};
|
||||
});
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
preview,
|
||||
website,
|
||||
source,
|
||||
tags,
|
||||
};
|
||||
});
|
||||
|
||||
const content = await Promise.all(contentPromises);
|
||||
return {
|
||||
|
@ -88,7 +97,7 @@ export default function pluginContentShowcase(
|
|||
|
||||
addRoute({
|
||||
path: `/showcaseAll/${item.title}`,
|
||||
component: '@theme/Showcase',
|
||||
component: '@theme/ShowcaseDetails',
|
||||
modules: {
|
||||
content: dataAuthor,
|
||||
},
|
||||
|
|
|
@ -247,10 +247,20 @@ declare module '@theme/BlogPostItems' {
|
|||
export default function BlogPostItem(props: Props): JSX.Element;
|
||||
}
|
||||
|
||||
declare module '@theme/Showcase' {
|
||||
declare module '@theme/ShowcaseDetails' {
|
||||
import type {Content} from '@docusaurus/plugin-showcase';
|
||||
|
||||
export function prepareUserState(): UserState | undefined;
|
||||
export type User = Content['website'][number];
|
||||
|
||||
export type Props = {
|
||||
content: User;
|
||||
};
|
||||
|
||||
export default function Showcase(props: Props): JSX.Element;
|
||||
}
|
||||
|
||||
declare module '@theme/Showcase' {
|
||||
import type {Content} from '@docusaurus/plugin-showcase';
|
||||
|
||||
export type User = Content['website'][number];
|
||||
|
||||
|
@ -296,16 +306,12 @@ declare module '@theme/Showcase/ShowcaseTagSelect' {
|
|||
tag: TagType;
|
||||
}
|
||||
|
||||
export function readSearchTags(search: string): TagType[];
|
||||
|
||||
export default function ShowcaseTagSelect(props: Props): JSX.Element;
|
||||
}
|
||||
declare module '@theme/Showcase/ShowcaseFilterToggle' {
|
||||
export type Operator = 'OR' | 'AND';
|
||||
export const OperatorQueryKey = 'operator';
|
||||
|
||||
export function readOperator(search: string): Operator;
|
||||
|
||||
export default function ShowcaseFilterToggle(): JSX.Element;
|
||||
}
|
||||
|
||||
|
|
|
@ -448,8 +448,7 @@ function ShowcaseCards({users}: {users: Users}) {
|
|||
}
|
||||
|
||||
export default function Showcase(props: Props): JSX.Element {
|
||||
// TODO remove temporary to test showcase specific page
|
||||
const users = Array.isArray(props.content) ? props.content : [props.content];
|
||||
const users = props.content;
|
||||
|
||||
return (
|
||||
<Layout title="Showcase">
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import type {Props} from '@theme/ShowcaseDetails';
|
||||
import Layout from '@theme/Layout';
|
||||
|
||||
export default function Showcase(props: Props): JSX.Element {
|
||||
const user = props.content;
|
||||
|
||||
return (
|
||||
<Layout title="Showcase Details">
|
||||
<div>{user.title}</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue