我想使用“docs”插件和自定义 (JavaScript) 插件将文档填充到我的 Docusaurus 项目中,以将其连接到无头 CMS。目前,我正在使用loadContent Lifecycle API 事件来调用我的 Headless CMS API,然后使用fs.writeFileSync在“/docs”中创建物理降价文件并覆盖 ./sidebars.js 文件,以便出现“docs”插件与经典的预设作品。
./my-plugin/index.js:
module.exports = function (context, options) {
return {
name: 'my-docusaurus-plugin',
async loadContent() {
//calls to Headless CMS API for documentation content
let response = await fetchArticles('documentation');
// Adds the markdown files for 'docs' plugin using fs.writeFileSync
await buildArticles(response)
//fetch homepage and navigation sections from CMS API
let homepage = await fetchPages('homepage');
let sidebarSection = await fetchPages('page');
//overwrite ./sidebars.js with API navigation data …Run Code Online (Sandbox Code Playgroud)