@larkiny/astro-github-loader 0.14.1 → 0.14.2

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.
@@ -181,6 +181,19 @@ function transformLink(linkText, linkUrl, context) {
181
181
  return `[${linkText}](${linkUrl})`;
182
182
  }
183
183
  const { path: linkPath, anchor } = extractAnchor(linkUrl);
184
+ // Try global linkMappings on the RAW link path before normalization.
185
+ // Bare-path links (e.g., "docs/markdown/autoapi/foo/") are repo-root-relative
186
+ // but normalizePath() treats them as file-relative, mangling the path.
187
+ // Applying global mappings first lets patterns match the link as written.
188
+ if (context.global.linkMappings) {
189
+ const globalMappings = context.global.linkMappings.filter((m) => m.global);
190
+ if (globalMappings.length > 0) {
191
+ const rawMapped = applyLinkMappings(linkPath + anchor, globalMappings, context);
192
+ if (rawMapped !== linkPath + anchor) {
193
+ return `[${linkText}](${rawMapped})`;
194
+ }
195
+ }
196
+ }
184
197
  // Normalize the link path relative to current file FIRST
185
198
  const normalizedPath = normalizePath(linkPath, context.currentFile.sourcePath, context.global.logger);
186
199
  // Apply global path mappings to the normalized path
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.1",
4
+ "version": "0.14.2",
5
5
  "description": "Load content from GitHub repositories into Astro content collections with asset management and content transformations",
6
6
  "keywords": [
7
7
  "astro",
@@ -120,6 +120,32 @@ describe("globalLinkTransform", () => {
120
120
  expect(result[0].content).toBe("[See other](/other/)");
121
121
  });
122
122
 
123
+ it("should apply global linkMappings to bare-path links before normalization", () => {
124
+ const files: ImportedFile[] = [
125
+ createImportedFile(
126
+ "docs/markdown/capabilities/guide.md",
127
+ "src/content/docs/guide.md",
128
+ "[`AccountManager`](docs/markdown/autoapi/algokit_utils/accounts/account_manager/#algokit_utils.accounts.account_manager.AccountManager)",
129
+ ),
130
+ ];
131
+
132
+ const result = globalLinkTransform(files, {
133
+ stripPrefixes: ["src/content/docs"],
134
+ linkMappings: [
135
+ {
136
+ pattern: /^docs\/markdown\/autoapi\/algokit_utils\/(.+)/,
137
+ replacement: "/docs/algokit-utils/python/latest/api/$1",
138
+ global: true,
139
+ },
140
+ ],
141
+ logger,
142
+ });
143
+
144
+ expect(result[0].content).toBe(
145
+ "[`AccountManager`](/docs/algokit-utils/python/latest/api/accounts/account_manager/#algokit_utils.accounts.account_manager.AccountManager)",
146
+ );
147
+ });
148
+
123
149
  it("should preserve anchors in transformed links", () => {
124
150
  const files: ImportedFile[] = [
125
151
  createImportedFile(
@@ -314,6 +314,24 @@ function transformLink(
314
314
 
315
315
  const { path: linkPath, anchor } = extractAnchor(linkUrl);
316
316
 
317
+ // Try global linkMappings on the RAW link path before normalization.
318
+ // Bare-path links (e.g., "docs/markdown/autoapi/foo/") are repo-root-relative
319
+ // but normalizePath() treats them as file-relative, mangling the path.
320
+ // Applying global mappings first lets patterns match the link as written.
321
+ if (context.global.linkMappings) {
322
+ const globalMappings = context.global.linkMappings.filter((m) => m.global);
323
+ if (globalMappings.length > 0) {
324
+ const rawMapped = applyLinkMappings(
325
+ linkPath + anchor,
326
+ globalMappings,
327
+ context,
328
+ );
329
+ if (rawMapped !== linkPath + anchor) {
330
+ return `[${linkText}](${rawMapped})`;
331
+ }
332
+ }
333
+ }
334
+
317
335
  // Normalize the link path relative to current file FIRST
318
336
  const normalizedPath = normalizePath(
319
337
  linkPath,