sourcey 3.3.6 → 3.3.7

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.
@@ -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;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,aAAa,CAAC;AAc/D,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,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;AA2ID,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,YAAY,EACV,cAAc,EACd,mBA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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 (!target)
239
- return _match;
240
- // Build relative path from this page to the target
241
- const relativePath = toRoot + target;
242
- return `href="${relativePath}${hashSuffix}"`;
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sourcey",
3
- "version": "3.3.6",
3
+ "version": "3.3.7",
4
4
  "description": "Open source documentation platform. API references, guides, static output.",
5
5
  "type": "module",
6
6
  "engines": {