@larkiny/astro-github-loader 0.14.2 → 0.14.3

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.
@@ -185,7 +185,14 @@ function transformLink(linkText, linkUrl, context) {
185
185
  // Bare-path links (e.g., "docs/markdown/autoapi/foo/") are repo-root-relative
186
186
  // but normalizePath() treats them as file-relative, mangling the path.
187
187
  // Applying global mappings first lets patterns match the link as written.
188
- if (context.global.linkMappings) {
188
+ // Only for bare paths — relative (./, ../) and absolute (/) links must flow
189
+ // through normalizePath() first to avoid over-matching by generic global
190
+ // mappings like .md-stripping from generateStarlightLinkMappings().
191
+ const isBareBarePath = !linkPath.startsWith("./") &&
192
+ !linkPath.startsWith("../") &&
193
+ !linkPath.startsWith("/") &&
194
+ !linkPath.includes("://");
195
+ if (isBareBarePath && context.global.linkMappings) {
189
196
  const globalMappings = context.global.linkMappings.filter((m) => m.global);
190
197
  if (globalMappings.length > 0) {
191
198
  const rawMapped = applyLinkMappings(linkPath + anchor, globalMappings, context);
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.2",
4
+ "version": "0.14.3",
5
5
  "description": "Load content from GitHub repositories into Astro content collections with asset management and content transformations",
6
6
  "keywords": [
7
7
  "astro",
@@ -146,6 +146,71 @@ describe("globalLinkTransform", () => {
146
146
  );
147
147
  });
148
148
 
149
+ it("should not early-return relative ./ links when .md-stripping global mappings exist", () => {
150
+ const files: ImportedFile[] = [
151
+ createImportedFile(
152
+ "docs/guide.md",
153
+ "src/content/docs/guide.md",
154
+ "[Subscriber](./subscriber.md)",
155
+ ),
156
+ createImportedFile(
157
+ "docs/subscriber.md",
158
+ "src/content/docs/subscriber.md",
159
+ "# Subscriber",
160
+ ),
161
+ ];
162
+
163
+ const result = globalLinkTransform(files, {
164
+ stripPrefixes: ["src/content/docs"],
165
+ linkMappings: [
166
+ {
167
+ pattern: /\.md(#|$)/,
168
+ replacement: "$1",
169
+ global: true,
170
+ },
171
+ {
172
+ pattern: /\/index(\.md)?$/,
173
+ replacement: "/",
174
+ global: true,
175
+ },
176
+ ],
177
+ logger,
178
+ });
179
+
180
+ // Should resolve via sourceToTargetMap, not early-return from .md stripping
181
+ expect(result[0].content).toBe("[Subscriber](/subscriber/)");
182
+ });
183
+
184
+ it("should not early-return relative ../ links when global mappings exist", () => {
185
+ const files: ImportedFile[] = [
186
+ createImportedFile(
187
+ "docs/guides/intro.md",
188
+ "src/content/docs/guides/intro.md",
189
+ "[Overview](../overview.md)",
190
+ ),
191
+ createImportedFile(
192
+ "docs/overview.md",
193
+ "src/content/docs/overview.md",
194
+ "# Overview",
195
+ ),
196
+ ];
197
+
198
+ const result = globalLinkTransform(files, {
199
+ stripPrefixes: ["src/content/docs"],
200
+ linkMappings: [
201
+ {
202
+ pattern: /\.md(#|$)/,
203
+ replacement: "$1",
204
+ global: true,
205
+ },
206
+ ],
207
+ logger,
208
+ });
209
+
210
+ // Should resolve via normalization + sourceToTargetMap
211
+ expect(result[0].content).toBe("[Overview](/overview/)");
212
+ });
213
+
149
214
  it("should preserve anchors in transformed links", () => {
150
215
  const files: ImportedFile[] = [
151
216
  createImportedFile(
@@ -318,7 +318,15 @@ function transformLink(
318
318
  // Bare-path links (e.g., "docs/markdown/autoapi/foo/") are repo-root-relative
319
319
  // but normalizePath() treats them as file-relative, mangling the path.
320
320
  // Applying global mappings first lets patterns match the link as written.
321
- if (context.global.linkMappings) {
321
+ // Only for bare paths — relative (./, ../) and absolute (/) links must flow
322
+ // through normalizePath() first to avoid over-matching by generic global
323
+ // mappings like .md-stripping from generateStarlightLinkMappings().
324
+ const isBareBarePath =
325
+ !linkPath.startsWith("./") &&
326
+ !linkPath.startsWith("../") &&
327
+ !linkPath.startsWith("/") &&
328
+ !linkPath.includes("://");
329
+ if (isBareBarePath && context.global.linkMappings) {
322
330
  const globalMappings = context.global.linkMappings.filter((m) => m.global);
323
331
  if (globalMappings.length > 0) {
324
332
  const rawMapped = applyLinkMappings(