lildocs 0.1.17 → 0.1.18

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.
Files changed (2) hide show
  1. package/dist/cli.mjs +10 -3
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -1062,12 +1062,14 @@ async function buildReferencePages(options) {
1062
1062
  outDir: tempDir
1063
1063
  });
1064
1064
  const markdownPaths = await collectMarkdownPaths(tempDir);
1065
+ const packageName = packageJsonData.name;
1066
+ if (typeof packageName !== "string" || !packageName) throw new Error(`Package name not found: ${packageJson.packagePath}`);
1065
1067
  return Promise.all(markdownPaths.map(async (sourcePath) => {
1066
- const generatedPath = toPosixPath(path.relative(tempDir, sourcePath));
1068
+ const rawMarkdown = await readFile(sourcePath, "utf8");
1067
1069
  return {
1068
1070
  sourcePath,
1069
- relativePath: toPosixPath(path.posix.join("reference", generatedPath)),
1070
- rawMarkdown: await readFile(sourcePath, "utf8")
1071
+ relativePath: referenceMarkdownPath(rawMarkdown, packageName),
1072
+ rawMarkdown
1071
1073
  };
1072
1074
  }));
1073
1075
  } catch (error) {
@@ -1103,6 +1105,11 @@ async function readPackageJson(packagePath) {
1103
1105
  throw error;
1104
1106
  }
1105
1107
  }
1108
+ function referenceMarkdownPath(rawMarkdown, packageName) {
1109
+ const packageSpecifier = rawMarkdown.match(/^#\s+(.+)$/m)?.[1]?.trim();
1110
+ if (!packageSpecifier || packageSpecifier !== packageName && !packageSpecifier.startsWith(`${packageName}/`) || packageSpecifier.split("/").some((part) => !part || part === "." || part === "..")) throw new Error(`Invalid package entry heading: ${packageSpecifier ?? "missing"}`);
1111
+ return toPosixPath(path.posix.join("reference", `${packageSpecifier}.md`));
1112
+ }
1106
1113
  function errorMessage(error) {
1107
1114
  if (error instanceof Error) return error.message;
1108
1115
  return String(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lildocs",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "A lightweight CLI that turns Markdown docs into a static searchable documentation site.",
5
5
  "homepage": "https://aleclarson.github.io/lildocs/",
6
6
  "repository": {