@larkiny/astro-github-loader 0.14.4 → 0.14.6

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,4 +1,3 @@
1
- import { slug } from "github-slugger";
2
1
  import path from "node:path";
3
2
  /**
4
3
  * Extract anchor fragment from a link
@@ -148,12 +147,11 @@ function generateSiteUrl(targetPath, stripPrefixes) {
148
147
  else if (url === "index") {
149
148
  url = "";
150
149
  }
151
- // Split path into segments and slugify each
152
- const segments = url
150
+ // Filter empty segments (from double slashes etc.)
151
+ url = url
153
152
  .split("/")
154
- .map((segment) => (segment ? slug(segment) : ""));
155
- // Reconstruct URL
156
- url = segments.filter((s) => s).join("/");
153
+ .filter((s) => s)
154
+ .join("/");
157
155
  // Ensure leading slash
158
156
  if (url && !url.startsWith("/")) {
159
157
  url = "/" + url;
@@ -199,7 +197,7 @@ function transformLink(linkText, linkUrl, context) {
199
197
  const globalMappings = context.global.linkMappings.filter((m) => m.global);
200
198
  if (globalMappings.length > 0) {
201
199
  const rawMapped = applyLinkMappings(linkPath + anchor, globalMappings, context);
202
- if (rawMapped !== linkPath + anchor) {
200
+ if (rawMapped !== linkPath + anchor && rawMapped.startsWith("/")) {
203
201
  return `[${linkText}](${rawMapped})`;
204
202
  }
205
203
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@larkiny/astro-github-loader",
3
3
  "type": "module",
4
- "version": "0.14.4",
4
+ "version": "0.14.6",
5
5
  "description": "Load content from GitHub repositories into Astro content collections with asset management and content transformations",
6
6
  "keywords": [
7
7
  "astro",
@@ -46,7 +46,6 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@octokit/auth-app": "^8.1.1",
49
- "github-slugger": "^2.0.0",
50
49
  "octokit": "^5.0.4",
51
50
  "picomatch": "^4.0.2"
52
51
  },
@@ -244,6 +244,69 @@ describe("globalLinkTransform", () => {
244
244
  expect(result[0].content).toBe("[See B](/api/page-b/#section)");
245
245
  });
246
246
 
247
+ it("should not early-return multi-segment bare-path sibling references with .md", () => {
248
+ // Multi-segment bare paths like "types/subscription.md" are file-relative
249
+ // sibling references (e.g., from subscriber.md to types/subscription.md).
250
+ // The .md-stripping global mapping should NOT cause an early return — the
251
+ // link must flow through normalizePath() + sourceToTargetMap to resolve.
252
+ const files: ImportedFile[] = [
253
+ createImportedFile(
254
+ "latest/api/subscriber.md",
255
+ "src/content/docs/docs/algokit-subscriber/typescript/latest/api/subscriber.md",
256
+ "[`AlgorandSubscriberConfig`](types/subscription.md#algorandsubscriberconfig)",
257
+ ),
258
+ createImportedFile(
259
+ "latest/api/types/subscription.md",
260
+ "src/content/docs/docs/algokit-subscriber/typescript/latest/api/types/subscription.md",
261
+ "# subscription",
262
+ ),
263
+ ];
264
+
265
+ const result = globalLinkTransform(files, {
266
+ stripPrefixes: ["src/content/docs"],
267
+ linkMappings: [
268
+ { pattern: /\.md(#|$)/, replacement: "$1", global: true },
269
+ { pattern: /\/index(\.md)?$/, replacement: "/", global: true },
270
+ ],
271
+ logger,
272
+ });
273
+
274
+ // Should resolve via sourceToTargetMap to absolute URL, NOT leave as relative
275
+ expect(result[0].content).toBe(
276
+ "[`AlgorandSubscriberConfig`](/docs/algokit-subscriber/typescript/latest/api/types/subscription/#algorandsubscriberconfig)",
277
+ );
278
+ });
279
+
280
+ it("should preserve dots and case in generated site URLs", () => {
281
+ // TypeDoc output uses dot-separated filenames like types_account_manager.AccountManager.md
282
+ // The generated URL should preserve dots and case to match Starlight's generateId
283
+ const files: ImportedFile[] = [
284
+ createImportedFile(
285
+ "latest/api/classes/types_account_manager.AccountManager.md",
286
+ "src/content/docs/docs/algokit-utils/typescript/latest/api/classes/types_account_manager.AccountManager.md",
287
+ "# AccountManager",
288
+ ),
289
+ createImportedFile(
290
+ "latest/api/classes/types_app_factory.AppFactory.md",
291
+ "src/content/docs/docs/algokit-utils/typescript/latest/api/classes/types_app_factory.AppFactory.md",
292
+ "[AccountManager](types_account_manager.AccountManager.md)",
293
+ ),
294
+ ];
295
+
296
+ const result = globalLinkTransform(files, {
297
+ stripPrefixes: ["src/content/docs"],
298
+ linkMappings: [
299
+ { pattern: /\.md(#|$)/, replacement: "$1", global: true },
300
+ ],
301
+ logger,
302
+ });
303
+
304
+ // URL should preserve dots and case — NOT slugify to types_account_manageraccountmanager
305
+ expect(result[1].content).toBe(
306
+ "[AccountManager](/docs/algokit-utils/typescript/latest/api/classes/types_account_manager.AccountManager/)",
307
+ );
308
+ });
309
+
247
310
  it("should preserve anchors in transformed links", () => {
248
311
  const files: ImportedFile[] = [
249
312
  createImportedFile(
@@ -1,4 +1,3 @@
1
- import { slug } from "github-slugger";
2
1
  import path from "node:path";
3
2
  import type {
4
3
  LinkMapping,
@@ -270,13 +269,11 @@ function generateSiteUrl(targetPath: string, stripPrefixes: string[]): string {
270
269
  url = "";
271
270
  }
272
271
 
273
- // Split path into segments and slugify each
274
- const segments = url
272
+ // Filter empty segments (from double slashes etc.)
273
+ url = url
275
274
  .split("/")
276
- .map((segment) => (segment ? slug(segment) : ""));
277
-
278
- // Reconstruct URL
279
- url = segments.filter((s) => s).join("/");
275
+ .filter((s) => s)
276
+ .join("/");
280
277
 
281
278
  // Ensure leading slash
282
279
  if (url && !url.startsWith("/")) {
@@ -337,7 +334,7 @@ function transformLink(
337
334
  globalMappings,
338
335
  context,
339
336
  );
340
- if (rawMapped !== linkPath + anchor) {
337
+ if (rawMapped !== linkPath + anchor && rawMapped.startsWith("/")) {
341
338
  return `[${linkText}](${rawMapped})`;
342
339
  }
343
340
  }