From 2b37b51b36efa7bd066f092887804299b128c58a Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:39:55 +0100 Subject: [PATCH] wip init --- .../docusaurus-plugin-showcase/.npmignore | 3 + packages/docusaurus-plugin-showcase/README.md | 7 ++ .../docusaurus-plugin-showcase/package.json | 36 +++++++++++ .../docusaurus-plugin-showcase/src/index.ts | 64 +++++++++++++++++++ .../docusaurus-plugin-showcase/src/options.ts | 29 +++++++++ .../src/plugin-showcase.d.ts | 32 ++++++++++ .../docusaurus-plugin-showcase/tsconfig.json | 12 ++++ .../src/theme-classic.d.ts | 8 +++ .../src/theme/Showcase/index.tsx | 13 ++++ website/docusaurus.config.ts | 1 + website/src/components/Showcase.js | 12 ++++ website/src/showcase/authors.json | 4 ++ 12 files changed, 221 insertions(+) create mode 100644 packages/docusaurus-plugin-showcase/.npmignore create mode 100644 packages/docusaurus-plugin-showcase/README.md create mode 100644 packages/docusaurus-plugin-showcase/package.json create mode 100644 packages/docusaurus-plugin-showcase/src/index.ts create mode 100644 packages/docusaurus-plugin-showcase/src/options.ts create mode 100644 packages/docusaurus-plugin-showcase/src/plugin-showcase.d.ts create mode 100644 packages/docusaurus-plugin-showcase/tsconfig.json create mode 100644 packages/docusaurus-theme-classic/src/theme/Showcase/index.tsx create mode 100644 website/src/components/Showcase.js create mode 100644 website/src/showcase/authors.json diff --git a/packages/docusaurus-plugin-showcase/.npmignore b/packages/docusaurus-plugin-showcase/.npmignore new file mode 100644 index 0000000000..03c9ae1e1b --- /dev/null +++ b/packages/docusaurus-plugin-showcase/.npmignore @@ -0,0 +1,3 @@ +.tsbuildinfo* +tsconfig* +__tests__ diff --git a/packages/docusaurus-plugin-showcase/README.md b/packages/docusaurus-plugin-showcase/README.md new file mode 100644 index 0000000000..1d075c625a --- /dev/null +++ b/packages/docusaurus-plugin-showcase/README.md @@ -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). diff --git a/packages/docusaurus-plugin-showcase/package.json b/packages/docusaurus-plugin-showcase/package.json new file mode 100644 index 0000000000..bfc1d93741 --- /dev/null +++ b/packages/docusaurus-plugin-showcase/package.json @@ -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" + } +} diff --git a/packages/docusaurus-plugin-showcase/src/index.ts b/packages/docusaurus-plugin-showcase/src/index.ts new file mode 100644 index 0000000000..b0b5f1e283 --- /dev/null +++ b/packages/docusaurus-plugin-showcase/src/index.ts @@ -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 { + 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'; diff --git a/packages/docusaurus-plugin-showcase/src/options.ts b/packages/docusaurus-plugin-showcase/src/options.ts new file mode 100644 index 0000000000..137c73c11e --- /dev/null +++ b/packages/docusaurus-plugin-showcase/src/options.ts @@ -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({ + path: Joi.string().default(DEFAULT_OPTIONS.path), + routeBasePath: RouteBasePathSchema.default(DEFAULT_OPTIONS.routeBasePath), +}); + +export function validateOptions({ + validate, + options, +}: OptionValidationContext): PluginOptions { + const validatedOptions = validate(PluginOptionSchema, options); + return validatedOptions; +} diff --git a/packages/docusaurus-plugin-showcase/src/plugin-showcase.d.ts b/packages/docusaurus-plugin-showcase/src/plugin-showcase.d.ts new file mode 100644 index 0000000000..8c4335253f --- /dev/null +++ b/packages/docusaurus-plugin-showcase/src/plugin-showcase.d.ts @@ -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; + + export default function pluginShowcase( + context: LoadContext, + options: PluginOptions, + ): Promise>; +} diff --git a/packages/docusaurus-plugin-showcase/tsconfig.json b/packages/docusaurus-plugin-showcase/tsconfig.json new file mode 100644 index 0000000000..e16d5c2c5d --- /dev/null +++ b/packages/docusaurus-plugin-showcase/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "noEmit": false, + "incremental": true, + "tsBuildInfoFile": "./lib/.tsbuildinfo", + "rootDir": "src", + "outDir": "lib" + }, + "include": ["src"], + "exclude": ["**/__tests__/**"] +} diff --git a/packages/docusaurus-theme-classic/src/theme-classic.d.ts b/packages/docusaurus-theme-classic/src/theme-classic.d.ts index 39e7195893..4cde56068d 100644 --- a/packages/docusaurus-theme-classic/src/theme-classic.d.ts +++ b/packages/docusaurus-theme-classic/src/theme-classic.d.ts @@ -247,6 +247,14 @@ declare module '@theme/BlogPostItems' { 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' { import type {ReactNode} from 'react'; diff --git a/packages/docusaurus-theme-classic/src/theme/Showcase/index.tsx b/packages/docusaurus-theme-classic/src/theme/Showcase/index.tsx new file mode 100644 index 0000000000..9373a680c7 --- /dev/null +++ b/packages/docusaurus-theme-classic/src/theme/Showcase/index.tsx @@ -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
{props.author}
; +} diff --git a/website/docusaurus.config.ts b/website/docusaurus.config.ts index bfe47fedd5..ac82efa218 100644 --- a/website/docusaurus.config.ts +++ b/website/docusaurus.config.ts @@ -239,6 +239,7 @@ export default async function createConfigAsync() { ], themes: ['live-codeblock', ...dogfoodingThemeInstances], plugins: [ + 'showcase', [ './src/plugins/changelog/index.js', { diff --git a/website/src/components/Showcase.js b/website/src/components/Showcase.js new file mode 100644 index 0000000000..1db5612879 --- /dev/null +++ b/website/src/components/Showcase.js @@ -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
Your friends are : {props.content.author}
; +} diff --git a/website/src/showcase/authors.json b/website/src/showcase/authors.json new file mode 100644 index 0000000000..5998be2ef2 --- /dev/null +++ b/website/src/showcase/authors.json @@ -0,0 +1,4 @@ +{ + "author": "John Doe", + "title": "My first blog post" +}