typedoc-plugin-markdown icon indicating copy to clipboard operation
typedoc-plugin-markdown copied to clipboard

Copy referenced markdown and assets in the README.md

Open blessanm86 opened this issue 2 years ago • 2 comments

Im using the docusaurus plugin within a monorepo. So I use a single instance of the plugin for each library in the repo. So libraries link to other markdown files and images inside their respective libs folder.

The problem is the docusaurus plugin only copied the README file to the out folder. I think it would be great if the plugin had an option like files where you could pass a glob pattern that would be copied to the out folder.

{
  plugins: [
    [
      'docusaurus-plugin-typedoc',
      {
        id: 'sugar',
        out: 'libs/sugar',
        entryPoints: ['../../libs/sugar/src/index.ts'],
        tsconfig: '../../libs/sugar/tsconfig.lib.json',
        sidebar: {
          categoryLabel: 'sugar',
          indexLabel: 'API',
        },
        cleanOutputDir: true,
        files: [
          ''!../../libs/sugar/**/README.md'',
          '../../libs/sugar/**/*.md',
          '../../libs/sugar/**/*.png',
        ]
      },
    ],
}

blessanm86 avatar Nov 06 '22 09:11 blessanm86

I tried creating a local plugin that does the copy and I see the files getting copied, but I still get 404 page even I go to the URL. I also notice that I go into an infinite loop at times during development.

The docs plugin some how doesn't pick the new files. Some sort of race condition?

docusaurus.config.js

[
  './plugins/api-docs-generator',
  {
    id: 'sugar',
    out: 'libs/personio-web/sugar',
    entryPoints: ['../../libs/utils/sugar/src/index.ts'],
    tsconfig: '../../libs/utils/sugar/tsconfig.lib.json',
    sidebar: {
      categoryLabel: 'sugar',
      indexLabel: 'API',
    },
    files: [
      // '!../../../libs/utils/sugar/README.md',
      '../../../libs/utils/sugar/**/*.md',
    ],
    cleanOutputDir: true,
  },
],

./plugins/api-docs-generator

const { default: plugin } = require('docusaurus-plugin-typedoc');
const path = require('path');

module.exports = function pluginDocusaurus(context, opts) {
  const { siteDir } = context;
  const docsPath = 'docs';

  const { files, ...options } = opts;
  const pluginInstance = plugin(context, options);
  const prevLoadContent = pluginInstance.loadContent;
  pluginInstance.loadContent = async function () {
    const content = await prevLoadContent();
    const copy = (await import('cpy')).default;

    const outputDir = path.resolve(siteDir, docsPath, options.out, 'src');
    await copy(files, outputDir);

    return { ...content };
  };

  pluginInstance.contentLoaded = async function ({ content, actions }) {
    console.log({ content });
  };

  return pluginInstance;
};

blessanm86 avatar Nov 06 '22 10:11 blessanm86

Apologies for the delayed response. Will look into this requirement.

tgreyuk avatar Dec 01 '22 23:12 tgreyuk

Recommended approach here is to write a local typedoc plugin:

plugin: ["./typedoc-plugin.mjs"],

Example repo: https://github.com/typedoc2md/docusaurus-plugin-typedoc-example/blob/main/docs-website/typedoc-plugin.mjs

tgreyuk avatar May 04 '24 12:05 tgreyuk