A Docusaurus v2 plugin that downloads content from remote sources.
With this plugin, you can write the Markdown for your content somewhere else, and use them on your Docusaurus site, without copying and pasting.
Run this in a terminal:
yarn add docusaurus-plugin-remote-content
This plugin has 2 modes, and you can choose which to use depending on your needs.
This is the default mode.
You will want to gitignore the docs/blog directory that the plugin downloads content to,
as every time you run docusaurus build
or docusaurus start
, the content is downloaded,
(and optionally but enabled by default, when it stops, the local copy of the content is deleted).
This is the secondary mode. You can use the Docusaurus CLI to update the content when needed.
All you need to do is run docusaurus download-remote-X
, where X is the name
option given to the plugin.
You can also use docusaurus clear-remote-X
to remove the downloaded files.
Okay. Assuming you want to use constant sync, follow these steps:
- In your
docusaurus.config.js
, if you don't already, create a plugin array, and add this plugin. For example:
module.exports = {
// ...
plugins: [
[
"docusaurus-plugin-remote-content",
{
// options here
name: "some-content", // used by CLI, must be path safe
sourceBaseUrl: "https://my-site.com/content/", // the base url for the markdown (gets prepended to all of the documents when fetching)
outDir: "docs", // the base directory to output to.
documents: ["my-file.md", "README.md"], // the file names to download
},
],
],
}
- Configure the plugin - see the list of options below.
name
: (required)string
- The name of this plugin instance. Set tocontent
if you aren't sure what this does. (used by CLI)sourceBaseUrl
: (required)string
- The base URL that your remote docs are located. All the IDs specified in thedocuments
option will be resolved relative to this. For example, if you have 2 docs located at https://example.com/content/hello.md and https://example.com/content/thing.md, thesourceBaseUrl
would need to be set to https://example.com/content/.outDir
: (required)string
- The subfolder to emit the downloaded content to.documents
: (required)string[]
orPromise<string[]>
- The documents to fetch. Must be file names (e.g. end in.md
) Following the previous example, if you had setsourceBaseUrl
to https://example.com/content/, and wanted to fetch thing.md and hello.md, you would just setdocuments
to["hello", "thing"]
performCleanup
: (optional)boolean
- If the documents downloaded should be deleted after the build is completed. Defaults to true.noRuntimeDownloads
: (optional)boolean
- If you only want to use the CLI to download the remote content, you should change this to true.
It isn't really that hard. Follow these simple steps!:
- Clone a fork of this repository locally using your IDE of choice.
- Edit the source.
- Run
yarn build
. - Open a second terminal, and make the working directory the
testsite
. - Start the test site (
yarn start
). - You now have the test site running the plugin.
When you update the plugin, in order to preview your changes on the test site, you need to:
- Use the first shell you opened to re-run
yarn build
(in the repository's root directory). - In the second shell,
Control+C
the running Docusaurus dev server, and re-runyarn start
.