sourcey 3.3.6 → 3.3.8
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.
|
@@ -20,7 +20,10 @@ export type { PageHeading } from "../utils/markdown.js";
|
|
|
20
20
|
export declare function loadMarkdownPage(filePath: string, slug: string): Promise<MarkdownPage>;
|
|
21
21
|
/**
|
|
22
22
|
* Derive a URL slug from a file path.
|
|
23
|
-
*
|
|
23
|
+
* Preserves directory structure to avoid collisions:
|
|
24
|
+
* "getting-started.md" → "getting-started"
|
|
25
|
+
* "run/index.md" → "run/index"
|
|
26
|
+
* "run/install.md" → "run/install"
|
|
24
27
|
*/
|
|
25
28
|
export declare function slugFromPath(filePath: string): string;
|
|
26
29
|
//# sourceMappingURL=markdown-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown-loader.d.ts","sourceRoot":"","sources":["../../src/core/markdown-loader.ts"],"names":[],"mappings":"AAKA,OAAO,EAAmC,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAMzF,MAAM,WAAW,YAAY;IAC3B,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,sEAAsE;IACtE,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAwTxD;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,YAAY,CAAC,CAmBvB;AAUD
|
|
1
|
+
{"version":3,"file":"markdown-loader.d.ts","sourceRoot":"","sources":["../../src/core/markdown-loader.ts"],"names":[],"mappings":"AAKA,OAAO,EAAmC,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAMzF,MAAM,WAAW,YAAY;IAC3B,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,sEAAsE;IACtE,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAwTxD;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,YAAY,CAAC,CAmBvB;AAUD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIrD"}
|
|
@@ -252,8 +252,13 @@ function extractFirstHeading(md) {
|
|
|
252
252
|
}
|
|
253
253
|
/**
|
|
254
254
|
* Derive a URL slug from a file path.
|
|
255
|
-
*
|
|
255
|
+
* Preserves directory structure to avoid collisions:
|
|
256
|
+
* "getting-started.md" → "getting-started"
|
|
257
|
+
* "run/index.md" → "run/index"
|
|
258
|
+
* "run/install.md" → "run/install"
|
|
256
259
|
*/
|
|
257
260
|
export function slugFromPath(filePath) {
|
|
258
|
-
|
|
261
|
+
const ext = extname(filePath);
|
|
262
|
+
const stripped = ext ? filePath.slice(0, -ext.length) : filePath;
|
|
263
|
+
return stripped.split("/").map((s) => htmlId(s)).join("/");
|
|
259
264
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA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,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,cAAc,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAY3E;AAMD,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CACtC;AAED,wBAAsB,aAAa,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,CA0G5F;AAgKD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,YAAY,EACV,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { resolve, extname } from "node:path";
|
|
2
|
+
import { resolve, extname, posix } from "node:path";
|
|
3
3
|
import { loadSpec } from "./core/loader.js";
|
|
4
4
|
import { convertToOpenApi3 } from "./core/converter.js";
|
|
5
5
|
import { parseSpec } from "./core/parser.js";
|
|
@@ -99,7 +99,7 @@ export async function buildSiteDocs(options = {}) {
|
|
|
99
99
|
// Resolve internal links in markdown pages.
|
|
100
100
|
// Builds a map from every plausible href to the correct output path,
|
|
101
101
|
// then rewrites matching href attributes in each page's HTML.
|
|
102
|
-
resolveInternalLinks(sitePages);
|
|
102
|
+
resolveInternalLinks(sitePages, config);
|
|
103
103
|
// Build search index
|
|
104
104
|
const markdownPagesByTab = new Map();
|
|
105
105
|
for (const tab of tabs) {
|
|
@@ -192,7 +192,7 @@ async function resolveAssetUrl(pathOrUrl) {
|
|
|
192
192
|
* rewrites matching href values so they resolve on static file servers
|
|
193
193
|
* that don't support extensionless URLs.
|
|
194
194
|
*/
|
|
195
|
-
function resolveInternalLinks(pages) {
|
|
195
|
+
function resolveInternalLinks(pages, config) {
|
|
196
196
|
// Build a map from every plausible clean path to the output path.
|
|
197
197
|
// e.g. "components" -> "components.html", "config/ref-theme-tokens" -> "config/ref-theme-tokens.html"
|
|
198
198
|
const pathMap = new Map();
|
|
@@ -201,6 +201,10 @@ function resolveInternalLinks(pages) {
|
|
|
201
201
|
const clean = out.replace(/\.html$/, ""); // "components" or "config/ref-theme-tokens"
|
|
202
202
|
pathMap.set(clean, out);
|
|
203
203
|
}
|
|
204
|
+
// Repo source link base: e.g. "https://github.com/user/repo/tree/main"
|
|
205
|
+
const repoBase = config.repo?.replace(/\/$/, "");
|
|
206
|
+
const branch = config.editBranch;
|
|
207
|
+
const sourceBase = repoBase && branch ? `${repoBase}/tree/${branch}` : undefined;
|
|
204
208
|
for (const page of pages) {
|
|
205
209
|
if (page.currentPage.kind !== "markdown" || !page.currentPage.markdown)
|
|
206
210
|
continue;
|
|
@@ -218,8 +222,8 @@ function resolveInternalLinks(pages) {
|
|
|
218
222
|
// Split off hash fragment
|
|
219
223
|
const [path, hash] = href.split("#", 2);
|
|
220
224
|
const hashSuffix = hash ? `#${hash}` : "";
|
|
221
|
-
// Normalize: strip leading slash, trailing slash
|
|
222
|
-
const clean = path.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
225
|
+
// Normalize: strip leading slash, trailing slash, and .md extension
|
|
226
|
+
const clean = path.replace(/^\/+/, "").replace(/\/+$/, "").replace(/\.md$/, "");
|
|
223
227
|
// Skip if already has .html extension
|
|
224
228
|
if (clean.endsWith(".html"))
|
|
225
229
|
return _match;
|
|
@@ -235,11 +239,25 @@ function resolveInternalLinks(pages) {
|
|
|
235
239
|
break;
|
|
236
240
|
candidate = candidate.substring(slash + 1);
|
|
237
241
|
}
|
|
238
|
-
if (
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
242
|
+
if (target) {
|
|
243
|
+
// Build relative path from this page to the target
|
|
244
|
+
const relativePath = toRoot + target;
|
|
245
|
+
return `href="${relativePath}${hashSuffix}"`;
|
|
246
|
+
}
|
|
247
|
+
// If the link contains ../ and we have a repo URL configured,
|
|
248
|
+
// resolve it relative to the markdown source file. Links to docs
|
|
249
|
+
// pages are already handled above (pathMap lookup catches them after
|
|
250
|
+
// .md stripping and prefix stripping). What remains are links to
|
|
251
|
+
// repo source code outside the docs directory.
|
|
252
|
+
if (sourceBase && href.includes("../") && md.sourcePath) {
|
|
253
|
+
const sourceDir = posix.dirname(md.sourcePath);
|
|
254
|
+
const resolved = posix.normalize(posix.join(sourceDir, path));
|
|
255
|
+
// Only rewrite if the path stays inside the repo root
|
|
256
|
+
if (!resolved.startsWith("..")) {
|
|
257
|
+
return `href="${sourceBase}/${resolved}${hashSuffix}"`;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return _match;
|
|
243
261
|
});
|
|
244
262
|
}
|
|
245
263
|
}
|