@forsakringskassan/docs-generator 3.11.1 → 3.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -910,6 +910,12 @@ export declare interface SourceFiles {
910
910
  exclude?: string | string[];
911
911
  basePath?: string;
912
912
  fileReader: FileReader_2;
913
+ /**
914
+ * Only documents for which filter returns true are used.
915
+ *
916
+ * Runs before `transform`.
917
+ */
918
+ filter?(this: void, doc: Document_2): boolean;
913
919
  /**
914
920
  * Transform document before further processing.
915
921
  *
package/dist/index.mjs CHANGED
@@ -2049,6 +2049,7 @@ function parseFile$2(filePath, basePath, content) {
2049
2049
  path: ["", "."].includes(urlpath) ? "." : `./${normalizePath(urlpath)}`,
2050
2050
  name: filename,
2051
2051
  fullPath: normalizePath(filePath),
2052
+ /* eslint-disable-next-line unicorn/prefer-logical-operator-over-ternary -- false positive? */
2052
2053
  outputName: include ? `${filename}.html` : false
2053
2054
  }
2054
2055
  };
@@ -2769,7 +2770,7 @@ async function globAll(pattern) {
2769
2770
  return new Set(results.flat());
2770
2771
  }
2771
2772
  async function getDocumentsForSource(context, src, index) {
2772
- const { transform } = src;
2773
+ const { transform, filter = () => true } = src;
2773
2774
  const include = await globAll(src.include);
2774
2775
  const exclude = await globAll(src.exclude);
2775
2776
  const files = Array.from(difference(include, exclude));
@@ -2794,7 +2795,8 @@ async function getDocumentsForSource(context, src, index) {
2794
2795
  }
2795
2796
  return [];
2796
2797
  }
2797
- const docs2 = await src.fileReader(it, src.basePath);
2798
+ const allDocs = await src.fileReader(it, src.basePath);
2799
+ const docs2 = allDocs.filter(filter);
2798
2800
  if (transform) {
2799
2801
  return docs2.map((it2) => transform(it2));
2800
2802
  }
@@ -2982,9 +2984,10 @@ async function compileScript(options) {
2982
2984
  fs: fs$1 = fs
2983
2985
  } = options;
2984
2986
  const iconLib = process.env.DOCS_ICON_LIB ?? "@fkui/icon-lib-default";
2987
+ const sanitizedName = name.replaceAll(/[^a-z0-9-]+/gi, "_");
2985
2988
  try {
2986
2989
  const entryPoints = [src instanceof URL ? fileURLToPath(src) : src];
2987
- const outfile = path__default.join("temp", `asset-${name}.js`);
2990
+ const outfile = path__default.join("temp", `asset-${sanitizedName}.js`);
2988
2991
  const external = [...assets, ...vendor.map(toExternalVendor)];
2989
2992
  const format = buildOptions.format ?? "esm";
2990
2993
  await esbuild({
@@ -3004,7 +3007,7 @@ async function compileScript(options) {
3004
3007
  const content = await fs$1.readFile(outfile, "utf8");
3005
3008
  const fingerprint = getFingerprint(content);
3006
3009
  const integrity = getIntegrity(content);
3007
- const filename = `${outputName}.js`.replaceAll("[name]", () => name).replaceAll("[hash]", () => fingerprint);
3010
+ const filename = `${outputName}.js`.replaceAll("[name]", () => sanitizedName).replaceAll("[hash]", () => fingerprint);
3008
3011
  const dst = path__default.join(outputFolder, filename);
3009
3012
  const publicPath = path__default.posix.join(
3010
3013
  path__default.posix.relative(rootDir, outputFolder),