mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-05 13:17:23 +02:00
wip init
This commit is contained in:
parent
9017fb9b1d
commit
2b37b51b36
12 changed files with 221 additions and 0 deletions
3
packages/docusaurus-plugin-showcase/.npmignore
Normal file
3
packages/docusaurus-plugin-showcase/.npmignore
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.tsbuildinfo*
|
||||||
|
tsconfig*
|
||||||
|
__tests__
|
7
packages/docusaurus-plugin-showcase/README.md
Normal file
7
packages/docusaurus-plugin-showcase/README.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# `@docusaurus/plugin-showcase`
|
||||||
|
|
||||||
|
Showcase plugin for Docusaurus.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
See [plugin-showcase documentation](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-showcase).
|
36
packages/docusaurus-plugin-showcase/package.json
Normal file
36
packages/docusaurus-plugin-showcase/package.json
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
{
|
||||||
|
"name": "@docusaurus/plugin-showcase",
|
||||||
|
"version": "3.0.0",
|
||||||
|
"description": "Showcase plugin for Docusaurus.",
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"types": "src/plugin-showcase.d.ts",
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
|
"watch": "tsc --watch"
|
||||||
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/facebook/docusaurus.git",
|
||||||
|
"directory": "packages/docusaurus-plugin-showcase"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@docusaurus/core": "3.0.0",
|
||||||
|
"@docusaurus/types": "3.0.0",
|
||||||
|
"@docusaurus/utils": "3.0.0",
|
||||||
|
"@docusaurus/utils-validation": "3.0.0",
|
||||||
|
"fs-extra": "^11.1.1",
|
||||||
|
"tslib": "^2.6.0",
|
||||||
|
"webpack": "^5.88.1"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^18.0.0",
|
||||||
|
"react-dom": "^18.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0"
|
||||||
|
}
|
||||||
|
}
|
64
packages/docusaurus-plugin-showcase/src/index.ts
Normal file
64
packages/docusaurus-plugin-showcase/src/index.ts
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
|
|
||||||
|
import fs from 'fs-extra';
|
||||||
|
import path from 'path';
|
||||||
|
import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
|
||||||
|
|
||||||
|
import type {LoadContext, Plugin} from '@docusaurus/types';
|
||||||
|
import type {PluginOptions, Content} from '@docusaurus/plugin-showcase';
|
||||||
|
|
||||||
|
export default function pluginContentShowcase(
|
||||||
|
context: LoadContext,
|
||||||
|
options: PluginOptions,
|
||||||
|
): Plugin<Content> {
|
||||||
|
const {siteConfig, siteDir, generatedFilesDir} = context;
|
||||||
|
|
||||||
|
const pluginDataDirRoot = path.join(
|
||||||
|
generatedFilesDir,
|
||||||
|
'docusaurus-plugin-showcase',
|
||||||
|
);
|
||||||
|
const dataDir = path.join(pluginDataDirRoot, options.id ?? DEFAULT_PLUGIN_ID);
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: 'docusaurus-plugin-showcase',
|
||||||
|
|
||||||
|
async loadContent() {
|
||||||
|
const authors = await fs.readJson(
|
||||||
|
path.join(siteDir, options.path, 'authors.json'),
|
||||||
|
);
|
||||||
|
return authors;
|
||||||
|
},
|
||||||
|
|
||||||
|
async contentLoaded({content, actions}) {
|
||||||
|
if (!content) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const {addRoute, createData} = actions;
|
||||||
|
|
||||||
|
const dataAuthor = await createData(
|
||||||
|
'authors.json', // what is this?
|
||||||
|
JSON.stringify(content),
|
||||||
|
);
|
||||||
|
|
||||||
|
addRoute({
|
||||||
|
path: '/showcasetes',
|
||||||
|
// component: '@site/src/components/Showcase.js',
|
||||||
|
component: '@theme/Showcase',
|
||||||
|
modules: {
|
||||||
|
content: dataAuthor,
|
||||||
|
},
|
||||||
|
exact: true,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export {validateOptions} from './options';
|
29
packages/docusaurus-plugin-showcase/src/options.ts
Normal file
29
packages/docusaurus-plugin-showcase/src/options.ts
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
* 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 {Joi, RouteBasePathSchema} from '@docusaurus/utils-validation';
|
||||||
|
import type {OptionValidationContext} from '@docusaurus/types';
|
||||||
|
import type {PluginOptions, Options} from '@docusaurus/plugin-showcase';
|
||||||
|
|
||||||
|
export const DEFAULT_OPTIONS: PluginOptions = {
|
||||||
|
id: 'showcase',
|
||||||
|
path: 'src/showcase', // Path to data on filesystem, relative to site dir.
|
||||||
|
routeBasePath: '/', // URL Route.
|
||||||
|
};
|
||||||
|
|
||||||
|
const PluginOptionSchema = Joi.object<PluginOptions>({
|
||||||
|
path: Joi.string().default(DEFAULT_OPTIONS.path),
|
||||||
|
routeBasePath: RouteBasePathSchema.default(DEFAULT_OPTIONS.routeBasePath),
|
||||||
|
});
|
||||||
|
|
||||||
|
export function validateOptions({
|
||||||
|
validate,
|
||||||
|
options,
|
||||||
|
}: OptionValidationContext<Options, PluginOptions>): PluginOptions {
|
||||||
|
const validatedOptions = validate(PluginOptionSchema, options);
|
||||||
|
return validatedOptions;
|
||||||
|
}
|
32
packages/docusaurus-plugin-showcase/src/plugin-showcase.d.ts
vendored
Normal file
32
packages/docusaurus-plugin-showcase/src/plugin-showcase.d.ts
vendored
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare module '@docusaurus/plugin-showcase' {
|
||||||
|
import type {LoadContext, Plugin} from '@docusaurus/types';
|
||||||
|
|
||||||
|
export type Assets = {
|
||||||
|
image?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type PluginOptions = {
|
||||||
|
id?: string;
|
||||||
|
path: string;
|
||||||
|
routeBasePath: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Content = {
|
||||||
|
title: string;
|
||||||
|
author: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Options = Partial<PluginOptions>;
|
||||||
|
|
||||||
|
export default function pluginShowcase(
|
||||||
|
context: LoadContext,
|
||||||
|
options: PluginOptions,
|
||||||
|
): Promise<Plugin<LoadedContent | null>>;
|
||||||
|
}
|
12
packages/docusaurus-plugin-showcase/tsconfig.json
Normal file
12
packages/docusaurus-plugin-showcase/tsconfig.json
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"noEmit": false,
|
||||||
|
"incremental": true,
|
||||||
|
"tsBuildInfoFile": "./lib/.tsbuildinfo",
|
||||||
|
"rootDir": "src",
|
||||||
|
"outDir": "lib"
|
||||||
|
},
|
||||||
|
"include": ["src"],
|
||||||
|
"exclude": ["**/__tests__/**"]
|
||||||
|
}
|
|
@ -247,6 +247,14 @@ declare module '@theme/BlogPostItems' {
|
||||||
export default function BlogPostItem(props: Props): JSX.Element;
|
export default function BlogPostItem(props: Props): JSX.Element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module '@theme/Showcase' {
|
||||||
|
export interface Props {
|
||||||
|
[key: string]: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Showcase(props: Props): JSX.Element;
|
||||||
|
}
|
||||||
|
|
||||||
declare module '@theme/BlogPostItem/Container' {
|
declare module '@theme/BlogPostItem/Container' {
|
||||||
import type {ReactNode} from 'react';
|
import type {ReactNode} from 'react';
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
/**
|
||||||
|
* 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 React from 'react';
|
||||||
|
import type {Props} from '@theme/Showcase';
|
||||||
|
|
||||||
|
export default function Showcase(props: Props): JSX.Element {
|
||||||
|
return <div>{props.author}</div>;
|
||||||
|
}
|
|
@ -239,6 +239,7 @@ export default async function createConfigAsync() {
|
||||||
],
|
],
|
||||||
themes: ['live-codeblock', ...dogfoodingThemeInstances],
|
themes: ['live-codeblock', ...dogfoodingThemeInstances],
|
||||||
plugins: [
|
plugins: [
|
||||||
|
'showcase',
|
||||||
[
|
[
|
||||||
'./src/plugins/changelog/index.js',
|
'./src/plugins/changelog/index.js',
|
||||||
{
|
{
|
||||||
|
|
12
website/src/components/Showcase.js
Normal file
12
website/src/components/Showcase.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
/* eslint-disable @docusaurus/no-untranslated-text */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
export default function ShowcaseComponent(props) {
|
||||||
|
return <div>Your friends are : {props.content.author}</div>;
|
||||||
|
}
|
4
website/src/showcase/authors.json
Normal file
4
website/src/showcase/authors.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"author": "John Doe",
|
||||||
|
"title": "My first blog post"
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue