├── .gitignore ├── .npmignore ├── .prettierignore ├── .yarn └── releases │ └── yarn-4.0.2.cjs ├── .yarnrc.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── package.json ├── src ├── index.ts ├── types.ts └── utils.ts ├── testsite ├── .gitignore ├── README.md ├── babel.config.js ├── docusaurus.config.js ├── package.json ├── sidebars.js ├── src │ └── css │ │ └── custom.css └── static │ ├── .nojekyll │ └── img │ ├── favicon.ico │ ├── logo.svg │ ├── undraw_docusaurus_mountain.svg │ ├── undraw_docusaurus_react.svg │ └── undraw_docusaurus_tree.svg ├── tsconfig.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | build 106 | 107 | .yarn/cache 108 | .yarn/install-state.gz 109 | 110 | testsite/docs 111 | .pnp.cjs 112 | .pnp.loader.mjs 113 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | build/tsconfig.tsbuildinfo 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | testsite/.docusaurus 2 | build 3 | testsite/docs 4 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | compressionLevel: mixed 2 | 3 | enableGlobalCache: false 4 | 5 | nodeLinker: node-modules 6 | 7 | yarnPath: .yarn/releases/yarn-4.0.2.cjs 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## v4.0.0 4 | 5 | Breaking changes: 6 | 7 | - Dropped support for Docusaurus `<2.0.0`. 8 | - Dropped support for Node.js `<16.14` (what Docusaurus requires now). 9 | - Update axios to `^1.6.0`. 10 | 11 | New features: 12 | 13 | - Add explicit support for Docusaurus v3. 14 | 15 | ## v3.1.0 - 4/12/2022 16 | 17 | New features: 18 | 19 | - Add option for modifying output file names and contents dynamically. 20 | 21 | ## v3.0.0 - 2/9/2022 22 | 23 | Breaking changes: 24 | 25 | - Docusaurus v2.0.0-beta.15 or newer is now required. 26 | 27 | Bug fixes: 28 | 29 | - Fix issue with multiple slashes in the URL (fixed by @essential-randomness in #31). 30 | 31 | ## v2.1.0 - 1/6/2022 32 | 33 | Features: 34 | 35 | - Added the ability to customize the Axios request configuration (fixes #26). 36 | - Replaced `chalk` with `picocolors`, which has a smaller install size and faster API. 37 | - Improved the readability of the options section in the readme. 38 | - Reduced install size by excluding TypeScript build metadata. 39 | 40 | Bug fixes: 41 | 42 | - Removed the optional marker from the type of the `documents` option. 43 | 44 | ## v2.0.0 - 12/02/2021 45 | 46 | Breaking changes: 47 | 48 | - `docsIntegration` and `blogIntegration` have been removed in favor of just setting `outDir` (which is a lot more flexible). 49 | - `outputDirectory` has been renamed to `outDir`. 50 | - `name` is now a required option (dictates CLI command name). 51 | - Documents now must have proper file extensions, `.md` is no longer added by default. 52 | 53 | Other changes: 54 | 55 | - Switch to yarn v3.1.1. 56 | - Updated dependencies. 57 | - Updated code style to use 4 spaces instead of 2. 58 | - Bug fix: documents with subdirectories in their paths will now automatically ensure the subdirectories are created (reported by @fill-the-fill). 59 | 60 | ## v1.2.0 - 8/10/2021 61 | 62 | - Update Axios to prevent security warnings 63 | - Require Node.js v12 64 | - Added `outputDirectory` option to control which folder the downloaded content is put in 65 | - Updated TypeScript compiler target to reduce polyfill bloat 66 | 67 | ## v1.1.0 - 2/3/2021 68 | 69 | - Internal refactoring to simplify code 70 | - Add more documentation and metadata 71 | - Throw an error if both integrations are enabled at the same time 72 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021-2022 Reece Dunham. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docusaurus-plugin-remote-content 2 | 3 | A Docusaurus plugin that downloads content from remote sources. 4 | 5 | With this plugin, you can write the Markdown for your content somewhere else, and use them on your Docusaurus site, without copying and pasting. 6 | 7 | ## Installing 8 | 9 | Run this in a terminal: 10 | 11 | ```bash 12 | yarn add docusaurus-plugin-remote-content 13 | ``` 14 | 15 | ## Choosing a Mode 16 | 17 | This plugin has 2 modes, and you can choose which to use depending on your needs. 18 | 19 | ### Constant Sync 20 | 21 | This is the default mode. 22 | You will want to gitignore the docs/blog directory that the plugin downloads content to, 23 | as every time you run `docusaurus build` or `docusaurus start`, the content is downloaded, 24 | (and when it stops, the local copy of the content is deleted - this is configurable). 25 | 26 | ### CLI Sync 27 | 28 | This is the secondary mode. You can use the Docusaurus CLI to update the content when needed. 29 | All you need to do is run `docusaurus download-remote-X`, where X is the `name` option given to the plugin. 30 | You can also use `docusaurus clear-remote-X` to remove the downloaded files. 31 | 32 | To enable CLI Sync set `noRuntimeDownloads: true` in the options. 33 | 34 | ## Alright, so how do I use this?? 35 | 36 | Okay. Assuming you want to use constant sync, follow these steps: 37 | 38 | 1. In your `docusaurus.config.js`, if you don't already, create a plugin array, and add this plugin. For example: 39 | 40 | ```javascript 41 | module.exports = { 42 | // ... 43 | plugins: [ 44 | [ 45 | "docusaurus-plugin-remote-content", 46 | { 47 | // options here 48 | name: "some-content", // used by CLI, must be path safe 49 | sourceBaseUrl: "https://my-site.com/content/", // the base url for the markdown (gets prepended to all of the documents when fetching) 50 | outDir: "docs", // the base directory to output to. 51 | documents: ["my-file.md", "README.md"], // the file names to download 52 | }, 53 | ], 54 | ], 55 | } 56 | ``` 57 | 58 | 2. Configure the plugin - see the list of options below. 59 | 60 | ## Options 61 | 62 | ### `name` 63 | 64 | (_Required_) `string` 65 | 66 | The name of this plugin instance. Set to `content` if you aren't sure what this does. (used by CLI) 67 | 68 | ### `sourceBaseUrl` 69 | 70 | (_Required_) `string` 71 | 72 | The base URL that your remote docs are located. 73 | All the IDs specified in the `documents` option will be resolved relative to this. 74 | For example, if you have 2 docs located at https://example.com/content/hello.md and https://example.com/content/thing.md, 75 | the `sourceBaseUrl` would need to be set to https://example.com/content/. 76 | 77 | ### `outDir` 78 | 79 | (_Required_) `string` 80 | 81 | The folder to emit the downloaded content to. 82 | 83 | ### `documents` 84 | 85 | (_Required_) `string[]` or `Promise` 86 | 87 | The documents to fetch. Must be file names (e.g. end in `.md`) 88 | Following the previous example, if you had set `sourceBaseUrl` to https://example.com/content/, 89 | and wanted to fetch thing.md and hello.md, you would just set `documents` to `["hello.md", "thing.md"]` 90 | 91 | ### `performCleanup` 92 | 93 | (Optional) `boolean` - default = `true` 94 | 95 | If the documents downloaded should be deleted after the build is completed. Defaults to true. 96 | 97 | ### `noRuntimeDownloads` 98 | 99 | (Optional) `boolean` - default = `false` 100 | 101 | If you only want to use the Docusaurus CLI to download the remote content, you should change this to true. 102 | 103 | ### `requestConfig` 104 | 105 | (optional) [`AxiosRequestConfig`](https://axios-http.com/docs/req_config) 106 | 107 | Additional configuration options for the network requests that fetch the content. 108 | See the documentation for details: https://axios-http.com/docs/req_config 109 | 110 | ### `modifyContent` 111 | 112 | (optional) `(filename: string, content: string) => { filename?: string, content?: string }}` 113 | 114 | This option accepts a function that gets the name of the output file and the content of it as a string, 115 | and can return a modified version of either. The return value must be either undefined (which means "skip modifying this thing"), 116 | or an object containing the keys `filename` and/or `content`, containing the values you want to use. 117 | 118 | For example, this would add front matter to files that have the word "README" in their names: 119 | 120 | ```js 121 | // in the plugin's options: 122 | modifyContent(filename, content) { 123 | if (filename.includes("README")) { 124 | return { 125 | content: `--- 126 | description: We are now adding a front matter field to any README files! 127 | --- 128 | 129 | ${content}`, // <-- this last part adds in the rest of the content, which would otherwise be discarded 130 | } 131 | } 132 | 133 | // we don't want to modify this item, since it doesn't contain "README" in the name 134 | return undefined 135 | }, 136 | ``` 137 | 138 | ## Fetching Images 139 | To fetch images you need to have 2 instances of the plugin - 1 for markdown, and the other for images. With the images one, you would add `requestConfig: { responseType: "arraybuffer" }` 140 | 141 | ### Example 142 | ```javascript 143 | module.exports = { 144 | // ... 145 | plugins: [ 146 | [ 147 | "docusaurus-plugin-remote-content", 148 | { 149 | // options here 150 | name: "markdown-content", // used by CLI, must be path safe 151 | sourceBaseUrl: "https://my-site.com/content/", // the base url for the markdown (gets prepended to all of the documents when fetching) 152 | outDir: "docs", // the base directory to output to. 153 | documents: ["my-file.md", "README.md"], // the file names to download 154 | }, 155 | ], 156 | [ 157 | "docusaurus-plugin-remote-content", 158 | { 159 | // options here 160 | name: "images-content", // used by CLI, must be path safe 161 | sourceBaseUrl: "https://my-site.com/content/", // the base url for the markdown (gets prepended to all of the documents when fetching) 162 | outDir: "docs", // the base directory to output to. 163 | documents: ["my-image.png", "cool.gif"], // the file names to download 164 | requestConfig: { responseType: "arraybuffer" } 165 | }, 166 | ], 167 | ], 168 | } 169 | ``` 170 | 171 | 172 | ## Contributing 173 | 174 | It isn't really that hard. Follow these simple steps!: 175 | 176 | 1. Clone a fork of this repository locally using your IDE of choice. 177 | 2. Edit the source. 178 | 3. Run `yarn build`. 179 | 4. Start the test site (`yarn testsite:start`). 180 | 5. You now have the test site running the plugin. 181 | 182 | When you update the plugin, in order to preview your changes on the test site, you need to: 183 | 184 | 1. Quit the dev server. 185 | 2. Make your changes. 186 | 3. Rerun `yarn build`. 187 | 4. Restart the test site (`yarn testsite:start`). 188 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docusaurus-plugin-remote-content", 3 | "version": "4.0.0", 4 | "description": "A Docusaurus v2+ plugin that allows you to fetch content from remote sources!", 5 | "main": "build/index.js", 6 | "repository": "https://github.com/rdilweb/docusaurus-plugin-remote-content.git", 7 | "author": "Reece Dunham ", 8 | "license": "MIT", 9 | "types": "build/index.d.ts", 10 | "scripts": { 11 | "build": "tsc && rimraf build/tsconfig.tsbuildinfo", 12 | "prettier": "prettier --write \"**/*.{js,ts,md,json}\"" 13 | }, 14 | "prettier": { 15 | "semi": false, 16 | "tabWidth": 4 17 | }, 18 | "devDependencies": { 19 | "@docusaurus/types": "3.0.0", 20 | "@types/react": "^18.2.37", 21 | "@types/react-dom": "^18.2.15", 22 | "prettier": "^3.1.0", 23 | "typescript": "^5.3.2" 24 | }, 25 | "peerDependencies": { 26 | "@docusaurus/core": "2.x || 3.x" 27 | }, 28 | "bugs": { 29 | "url": "https://github.com/rdilweb/docusaurus-plugin-remote-content/issues" 30 | }, 31 | "dependencies": { 32 | "axios": "^1.6.0", 33 | "picocolors": "^1.0.0", 34 | "pretty-ms": "^7.0.1", 35 | "rimraf": "^5.0.5" 36 | }, 37 | "files": [ 38 | "build/*", 39 | "src", 40 | "CHANGELOG.md" 41 | ], 42 | "directories": { 43 | "example": "testsite", 44 | "lib": "src" 45 | }, 46 | "homepage": "https://github.com/rdilweb/docusaurus-plugin-remote-content", 47 | "keywords": [ 48 | "docusaurus", 49 | "v2", 50 | "plugin", 51 | "remote", 52 | "content" 53 | ], 54 | "engines": { 55 | "node": ">=18" 56 | }, 57 | "workspaces": [ 58 | "testsite" 59 | ], 60 | "packageManager": "yarn@4.0.2" 61 | } 62 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import type { LoadContext, Plugin } from "@docusaurus/types" 2 | import axios, { AxiosRequestConfig } from "axios" 3 | import { existsSync, writeFileSync, mkdirSync } from "fs" 4 | import { join } from "path" 5 | import { sync as delFile } from "rimraf" 6 | import { timeIt } from "./utils" 7 | import { Fetchable, ModifyContentFunction, RemoteContentPluginOptions } from "./types" 8 | 9 | async function runModifications(sourceBaseUrl: string, id: string, requestConfig: AxiosRequestConfig, modifyContent: ModifyContentFunction | undefined) { 10 | let content = ( 11 | await axios({ 12 | baseURL: sourceBaseUrl, 13 | url: id, 14 | ...requestConfig 15 | }) 16 | ).data 17 | let newIdent = id 18 | 19 | const called = modifyContent?.(newIdent, content) 20 | 21 | let cont = called?.content 22 | if (cont && typeof cont === "string") { 23 | content = cont 24 | } 25 | 26 | let fn 27 | if ((fn = called?.filename) && typeof fn === "string") { 28 | newIdent = fn 29 | } 30 | 31 | return { content, newIdent } 32 | } 33 | 34 | // noinspection JSUnusedGlobalSymbols 35 | export default async function pluginRemoteContent( 36 | context: LoadContext, 37 | options: RemoteContentPluginOptions 38 | ): Promise> { 39 | let { 40 | name, 41 | sourceBaseUrl, 42 | outDir, 43 | documents, 44 | noRuntimeDownloads = false, 45 | performCleanup = true, 46 | requestConfig = {}, 47 | modifyContent = () => undefined 48 | } = options 49 | 50 | if (!name) { 51 | throw new Error( 52 | "I need a name to work with! Please make sure it is path-safe." 53 | ) 54 | } 55 | 56 | if (!outDir) { 57 | throw new Error( 58 | "No output directory specified! Please specify one in your docusaurus-plugin-remote-content config (e.g. to download to the 'docs' folder, set outDir to docs.)" 59 | ) 60 | } 61 | 62 | if (!documents) { 63 | throw new Error( 64 | "The documents field is undefined, so I don't know what to fetch! It should be a string array, function that returns a string array, or promise that resolves with a string array." 65 | ) 66 | } 67 | 68 | if (!sourceBaseUrl) { 69 | throw new Error( 70 | "The sourceBaseUrl field is undefined, so I don't know where to fetch from!" 71 | ) 72 | } 73 | 74 | async function findRemoteItems(): Promise { 75 | const a: Fetchable[] = [] 76 | 77 | const resolvedDocs = 78 | typeof documents === "function" 79 | ? documents() 80 | : ((await documents) as string[]) 81 | 82 | for (const id of resolvedDocs) { 83 | a.push({ id }) 84 | } 85 | 86 | return a 87 | } 88 | 89 | async function getTargetDirectory(): Promise { 90 | const returnValue = join(context.siteDir, outDir) 91 | 92 | if (!existsSync(returnValue)) { 93 | mkdirSync(returnValue, { recursive: true }) 94 | } 95 | 96 | return returnValue 97 | } 98 | 99 | async function fetchContent(): Promise { 100 | const c = await findRemoteItems() 101 | 102 | for (const { id } of c) { 103 | let { content, newIdent } = await runModifications(sourceBaseUrl, id, requestConfig, modifyContent) 104 | 105 | const checkIdent = newIdent.split("/").filter((seg) => seg !== "") 106 | checkIdent.pop() 107 | 108 | // if we are outputting to a subdirectory, make sure it exists 109 | if (checkIdent.length > 0) { 110 | mkdirSync( 111 | join(await getTargetDirectory(), checkIdent.join("/")), 112 | { recursive: true } 113 | ) 114 | } 115 | 116 | writeFileSync(join(await getTargetDirectory(), newIdent), content) 117 | } 118 | } 119 | 120 | async function cleanContent(): Promise { 121 | const c = await findRemoteItems() 122 | 123 | for (const { id } of c) { 124 | delFile(join(await getTargetDirectory(), id)) 125 | } 126 | } 127 | 128 | if (!noRuntimeDownloads) { 129 | await fetchContent() 130 | } 131 | 132 | // noinspection JSUnusedGlobalSymbols 133 | return { 134 | name: `docusaurus-plugin-remote-content-${name}`, 135 | 136 | async postBuild(): Promise { 137 | if (performCleanup) { 138 | return await cleanContent() 139 | } 140 | }, 141 | 142 | extendCli(cli): void { 143 | cli.command(`download-remote-${name}`) 144 | .description(`Downloads the remote ${name} data.`) 145 | .action(async () => await timeIt(`fetch ${name}`, fetchContent)) 146 | 147 | cli.command(`clear-remote-${name}`) 148 | .description( 149 | `Removes the local copy of the remote ${name} data.` 150 | ) 151 | .action(async () => await timeIt(`clear ${name}`, cleanContent)) 152 | } 153 | } 154 | } 155 | 156 | export * from "./types" 157 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | import { AxiosRequestConfig } from "axios" 2 | 3 | /** 4 | * An optional function that modifies the file name and content of a downloaded file. 5 | * 6 | * @param filename The file's name. 7 | * @param content The file's content. 8 | * @returns undefined to leave the content/name as is, or an object containing the filename and the content. 9 | */ 10 | export type ModifyContentFunction = ( 11 | filename: string, 12 | content: string 13 | ) => { filename?: string; content?: string } | undefined 14 | 15 | /** 16 | * The plugin's options. 17 | */ 18 | export interface RemoteContentPluginOptions { 19 | /** 20 | * Delete local content after everything? 21 | */ 22 | performCleanup?: boolean 23 | 24 | /** 25 | * CLI only mode. 26 | */ 27 | noRuntimeDownloads?: boolean 28 | 29 | /** 30 | * The base URL for the source of the content. 31 | */ 32 | sourceBaseUrl: string 33 | 34 | /** 35 | * The name you want to give to the data. Used by the CLI, and *must* be path safe. 36 | */ 37 | name: string 38 | 39 | /** 40 | * The base output directory (e.g. "docs" or "blog"). 41 | */ 42 | outDir: string 43 | 44 | /** 45 | * Specify the document paths from the sourceBaseUrl 46 | * in a string array or function that returns a string array. 47 | */ 48 | documents: string[] | Promise | (() => string[]) 49 | 50 | /** 51 | * Additional options for Axios. 52 | * 53 | * @see https://axios-http.com/docs/req_config 54 | */ 55 | requestConfig?: Partial 56 | 57 | /** 58 | * An optional function that modifies the file name and content of a downloaded file. 59 | * 60 | * @param filename The file's name. 61 | * @param content The file's content. 62 | * @returns undefined to leave the content/name as is, or an object containing the filename and the content. 63 | */ 64 | modifyContent?: ModifyContentFunction 65 | } 66 | 67 | // noinspection SpellCheckingInspection 68 | /** 69 | * Some piece of content that can be fetched. 70 | */ 71 | export interface Fetchable { 72 | id: string 73 | } 74 | -------------------------------------------------------------------------------- /src/utils.ts: -------------------------------------------------------------------------------- 1 | import picocolors from "picocolors" 2 | import milli from "pretty-ms" 3 | 4 | export async function timeIt( 5 | name: string, 6 | action: () => Promise 7 | ): Promise { 8 | const startTime = new Date() 9 | await action() 10 | console.log( 11 | `${picocolors.green(`Task ${name} done (took `)} ${picocolors.white( 12 | milli((new Date() as any) - (startTime as any)) 13 | )}${picocolors.green(`)`)}` 14 | ) 15 | } 16 | -------------------------------------------------------------------------------- /testsite/.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | /node_modules 3 | 4 | # Production 5 | /build 6 | 7 | # Generated files 8 | .docusaurus 9 | .cache-loader 10 | 11 | # Misc 12 | .DS_Store 13 | .env.local 14 | .env.development.local 15 | .env.test.local 16 | .env.production.local 17 | 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* 21 | 22 | docs/api.md 23 | -------------------------------------------------------------------------------- /testsite/README.md: -------------------------------------------------------------------------------- 1 | # Website 2 | 3 | This website is built using [Docusaurus 2](https://v2.docusaurus.io/), a modern static website generator. 4 | 5 | ## Installation 6 | 7 | ```console 8 | yarn install 9 | ``` 10 | 11 | ## Local Development 12 | 13 | ```console 14 | yarn testsite:start 15 | ``` 16 | 17 | This command starts a local development server and open up a browser window. Most changes are reflected live without having to restart the server. 18 | 19 | ## Build 20 | 21 | ```console 22 | yarn testsite:build 23 | ``` 24 | 25 | This command generates static content into the `build` directory and can be served using any static contents hosting service. 26 | 27 | ## Deployment 28 | 29 | ```console 30 | GIT_USER= USE_SSH=true yarn deploy 31 | ``` 32 | 33 | If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. 34 | -------------------------------------------------------------------------------- /testsite/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [require.resolve("@docusaurus/core/lib/babel/preset")], 3 | } 4 | -------------------------------------------------------------------------------- /testsite/docusaurus.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import("@docusaurus/types").DocusaurusConfig} */ 2 | module.exports = { 3 | title: "My Site", 4 | tagline: "The tagline of my site", 5 | url: "https://your-docusaurus-test-site.com", 6 | baseUrl: "/", 7 | onBrokenLinks: "log", 8 | onBrokenMarkdownLinks: "log", 9 | favicon: "img/favicon.ico", 10 | organizationName: "rdilweb", // Usually your GitHub org/user name. 11 | projectName: "docusaurus-plugin-remote-content", // Usually your repo name. 12 | themeConfig: { 13 | navbar: { 14 | title: "My Site", 15 | logo: { 16 | alt: "My Site Logo", 17 | src: "img/logo.svg", 18 | }, 19 | }, 20 | }, 21 | presets: [ 22 | [ 23 | "@docusaurus/preset-classic", 24 | { 25 | docs: { 26 | sidebarPath: require.resolve("./sidebars.js"), 27 | }, 28 | blog: { 29 | showReadingTime: true, 30 | }, 31 | theme: { 32 | customCss: require.resolve("./src/css/custom.css"), 33 | }, 34 | }, 35 | ], 36 | ], 37 | plugins: [ 38 | [ 39 | require.resolve("docusaurus-plugin-remote-content"), 40 | { 41 | name: "docs", 42 | id: "basicTest", 43 | outDir: "docs", 44 | sourceBaseUrl: 45 | "https://raw.githubusercontent.com/PowerShell/PowerShell/master/docs", 46 | documents: ["FAQ.md"], 47 | }, 48 | ], 49 | [ 50 | require.resolve("docusaurus-plugin-remote-content"), 51 | { 52 | name: "powershell-docs", 53 | id: "outputDirectoryTest", 54 | sourceBaseUrl: 55 | "https://raw.githubusercontent.com/PowerShell/PowerShell/master", 56 | documents: ["README.md", "CODE_OF_CONDUCT.md"], 57 | outDir: "docs/output-dir-testing", 58 | requestConfig: { 59 | headers: { 60 | "Hello-World": "ThisIsAHeader", 61 | }, 62 | }, 63 | modifyContent(filename, content) { 64 | if (filename.includes("CODE_OF_CONDUCT")) { 65 | return { 66 | filename, 67 | content: `--- 68 | title: Code of Conduct with Front Matter 69 | --- 70 | 71 | ${content}`, 72 | } 73 | } 74 | 75 | return undefined 76 | }, 77 | }, 78 | ], 79 | [ 80 | require.resolve("docusaurus-plugin-remote-content"), 81 | { 82 | name: "github-labels", 83 | id: "pathSlashesTest", 84 | sourceBaseUrl: 85 | "https://api.github.com/repos/rdilweb/docusaurus-plugin-remote-content", 86 | documents: ["labels"], 87 | outDir: "docs/output-dir-testing/_data", 88 | requestConfig: { 89 | responseType: "arraybuffer", 90 | }, 91 | }, 92 | ], 93 | ], 94 | } 95 | -------------------------------------------------------------------------------- /testsite/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "testsite", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "testsite:docusaurus": "docusaurus", 7 | "testsite:start": "docusaurus start", 8 | "testsite:build": "docusaurus build", 9 | "testsite:swizzle": "docusaurus swizzle", 10 | "testsite:serve": "docusaurus serve", 11 | "testsite:clear": "docusaurus clear" 12 | }, 13 | "dependencies": { 14 | "@docusaurus/core": "3.0.0", 15 | "@docusaurus/preset-classic": "3.0.0", 16 | "@mdx-js/react": "^3.0.0", 17 | "clsx": "^2.0.0", 18 | "docusaurus-plugin-remote-content": "link:../", 19 | "react": "18.x", 20 | "react-dom": "18.x" 21 | }, 22 | "browserslist": { 23 | "production": [ 24 | ">0.5%", 25 | "not dead", 26 | "not op_mini all" 27 | ], 28 | "development": [ 29 | "last 1 chrome version", 30 | "last 1 firefox version", 31 | "last 1 safari version" 32 | ] 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /testsite/sidebars.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | someSidebar: { 3 | Docusaurus: ["FAQ", "output-dir-testing/CODE_OF_CONDUCT", "output-dir-testing/README"], 4 | }, 5 | } 6 | -------------------------------------------------------------------------------- /testsite/src/css/custom.css: -------------------------------------------------------------------------------- 1 | /* stylelint-disable docusaurus/copyright-header */ 2 | /** 3 | * Any CSS included here will be global. The classic template 4 | * bundles Infima by default. Infima is a CSS framework designed to 5 | * work well for content-centric websites. 6 | */ 7 | 8 | /* You can override the default Infima variables here. */ 9 | :root { 10 | --ifm-color-primary: #25c2a0; 11 | --ifm-color-primary-dark: rgb(33, 175, 144); 12 | --ifm-color-primary-darker: rgb(31, 165, 136); 13 | --ifm-color-primary-darkest: rgb(26, 136, 112); 14 | --ifm-color-primary-light: rgb(70, 203, 174); 15 | --ifm-color-primary-lighter: rgb(102, 212, 189); 16 | --ifm-color-primary-lightest: rgb(146, 224, 208); 17 | --ifm-code-font-size: 95%; 18 | } 19 | 20 | .docusaurus-highlight-code-line { 21 | background-color: rgb(72, 77, 91); 22 | display: block; 23 | margin: 0 calc(-1 * var(--ifm-pre-padding)); 24 | padding: 0 var(--ifm-pre-padding); 25 | } 26 | -------------------------------------------------------------------------------- /testsite/static/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdilweb/docusaurus-plugin-remote-content/7b7d0e9b9880871eace61d0b724ef12a72459da9/testsite/static/.nojekyll -------------------------------------------------------------------------------- /testsite/static/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdilweb/docusaurus-plugin-remote-content/7b7d0e9b9880871eace61d0b724ef12a72459da9/testsite/static/img/favicon.ico -------------------------------------------------------------------------------- /testsite/static/img/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testsite/static/img/undraw_docusaurus_mountain.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /testsite/static/img/undraw_docusaurus_react.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /testsite/static/img/undraw_docusaurus_tree.svg: -------------------------------------------------------------------------------- 1 | docu_tree -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "incremental": true, 4 | "target": "ES2021", 5 | "module": "commonjs", 6 | "lib": ["ESNext"], 7 | "jsx": "react", 8 | "skipLibCheck": true, 9 | "declaration": true, 10 | "declarationMap": true, 11 | "sourceMap": true, 12 | "outDir": "./build", 13 | "isolatedModules": true, 14 | "strict": true, 15 | "noImplicitAny": true, 16 | "strictNullChecks": true, 17 | "strictFunctionTypes": true, 18 | "strictBindCallApply": true, 19 | "strictPropertyInitialization": true, 20 | "noImplicitThis": true, 21 | "alwaysStrict": true, 22 | "noUnusedLocals": true, 23 | "noUnusedParameters": true, 24 | "noImplicitReturns": true, 25 | "noFallthroughCasesInSwitch": true, 26 | "noUncheckedIndexedAccess": true, 27 | "moduleResolution": "node", 28 | "esModuleInterop": true, 29 | "forceConsistentCasingInFileNames": true 30 | } 31 | } 32 | --------------------------------------------------------------------------------