fastrepl / canary

🐤 Canary provides UI primitives for building modern search-bar for docs with self-hostable infrastructure.
https://getcanary.dev
MIT License
35 stars 1 forks source link

import from `@generated/pagefind/pagefind` in `@getcanary/docusaurus-pagefind` #44

Open yujonglee opened 1 month ago

yujonglee commented 1 month ago
export default function plugin(_context, options) {
  const { indexOnly = false } = options;

  let generatedPath = null;

  const config = {
    name: "docusaurus-plugin-pagefind-canary",
    async contentLoaded({ actions }) {
      actions.setGlobalData({ options });
    },
+    configureWebpack(config) {
+      generatedPath = config.resolve.alias["@generated"];
+      return {};
+    },
    async postBuild({ routesPaths = [], outDir, baseUrl }) {
      const docs = getFilePaths(routesPaths, outDir, baseUrl, options);
+      await buildIndex(generatedPath, docs);
    },
  };

  if (indexOnly) {
    return config;
  }

  return {
    ...config,
    getThemePath() {
      return path.resolve(__dirname, "./theme");
    },
  };
}
yujonglee commented 1 month ago

In canary-provider-pagefind side, I tried checking url if it starts with @generated, and import without webpack ignore. But got can not access local file (<>/.docusaurus/pagefind..)