@larkiny/astro-github-loader 0.14.3 → 0.14.5
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,10 +185,13 @@ 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
|
-
// Only for bare paths — relative (./, ../) and absolute (/) links
|
|
189
|
-
// through normalizePath() first
|
|
190
|
-
//
|
|
191
|
-
|
|
188
|
+
// Only for multi-segment bare paths — relative (./, ../) and absolute (/) links
|
|
189
|
+
// must flow through normalizePath() first. Single-segment bare paths (no "/")
|
|
190
|
+
// like "api-algopy" or "types_amount.AlgoAmount" are sibling-file references
|
|
191
|
+
// that also need normalization, so we require at least one "/" to distinguish
|
|
192
|
+
// repo-root-relative paths from sibling references.
|
|
193
|
+
const isBareBarePath = linkPath.includes("/") &&
|
|
194
|
+
!linkPath.startsWith("./") &&
|
|
192
195
|
!linkPath.startsWith("../") &&
|
|
193
196
|
!linkPath.startsWith("/") &&
|
|
194
197
|
!linkPath.includes("://");
|
|
@@ -196,7 +199,7 @@ function transformLink(linkText, linkUrl, context) {
|
|
|
196
199
|
const globalMappings = context.global.linkMappings.filter((m) => m.global);
|
|
197
200
|
if (globalMappings.length > 0) {
|
|
198
201
|
const rawMapped = applyLinkMappings(linkPath + anchor, globalMappings, context);
|
|
199
|
-
if (rawMapped !== linkPath + anchor) {
|
|
202
|
+
if (rawMapped !== linkPath + anchor && rawMapped.startsWith("/")) {
|
|
200
203
|
return `[${linkText}](${rawMapped})`;
|
|
201
204
|
}
|
|
202
205
|
}
|
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
|
+
"version": "0.14.5",
|
|
5
5
|
"description": "Load content from GitHub repositories into Astro content collections with asset management and content transformations",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"astro",
|
|
@@ -211,6 +211,72 @@ describe("globalLinkTransform", () => {
|
|
|
211
211
|
expect(result[0].content).toBe("[Overview](/overview/)");
|
|
212
212
|
});
|
|
213
213
|
|
|
214
|
+
it("should not early-return single-segment bare-path sibling references", () => {
|
|
215
|
+
// Single-segment bare paths like "page-b.md" are sibling-file references.
|
|
216
|
+
// They must go through normalizePath() (joining with current dir) to resolve
|
|
217
|
+
// via sourceToTargetMap, NOT be caught by the bare-path pre-normalization check.
|
|
218
|
+
const files: ImportedFile[] = [
|
|
219
|
+
createImportedFile(
|
|
220
|
+
"docs/api/page-a.md",
|
|
221
|
+
"src/content/docs/api/page-a.md",
|
|
222
|
+
"[See B](page-b.md#section)",
|
|
223
|
+
),
|
|
224
|
+
createImportedFile(
|
|
225
|
+
"docs/api/page-b.md",
|
|
226
|
+
"src/content/docs/api/page-b.md",
|
|
227
|
+
"# Page B",
|
|
228
|
+
),
|
|
229
|
+
];
|
|
230
|
+
|
|
231
|
+
const result = globalLinkTransform(files, {
|
|
232
|
+
stripPrefixes: ["src/content/docs"],
|
|
233
|
+
linkMappings: [
|
|
234
|
+
{
|
|
235
|
+
pattern: /\.md(#|$)/,
|
|
236
|
+
replacement: "$1",
|
|
237
|
+
global: true,
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
logger,
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// "page-b.md" normalizes to "docs/api/page-b.md", resolves via sourceToTargetMap
|
|
244
|
+
expect(result[0].content).toBe("[See B](/api/page-b/#section)");
|
|
245
|
+
});
|
|
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
|
+
|
|
214
280
|
it("should preserve anchors in transformed links", () => {
|
|
215
281
|
const files: ImportedFile[] = [
|
|
216
282
|
createImportedFile(
|
|
@@ -318,10 +318,13 @@ 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
|
-
// Only for bare paths — relative (./, ../) and absolute (/) links
|
|
322
|
-
// through normalizePath() first
|
|
323
|
-
//
|
|
321
|
+
// Only for multi-segment bare paths — relative (./, ../) and absolute (/) links
|
|
322
|
+
// must flow through normalizePath() first. Single-segment bare paths (no "/")
|
|
323
|
+
// like "api-algopy" or "types_amount.AlgoAmount" are sibling-file references
|
|
324
|
+
// that also need normalization, so we require at least one "/" to distinguish
|
|
325
|
+
// repo-root-relative paths from sibling references.
|
|
324
326
|
const isBareBarePath =
|
|
327
|
+
linkPath.includes("/") &&
|
|
325
328
|
!linkPath.startsWith("./") &&
|
|
326
329
|
!linkPath.startsWith("../") &&
|
|
327
330
|
!linkPath.startsWith("/") &&
|
|
@@ -334,7 +337,7 @@ function transformLink(
|
|
|
334
337
|
globalMappings,
|
|
335
338
|
context,
|
|
336
339
|
);
|
|
337
|
-
if (rawMapped !== linkPath + anchor) {
|
|
340
|
+
if (rawMapped !== linkPath + anchor && rawMapped.startsWith("/")) {
|
|
338
341
|
return `[${linkText}](${rawMapped})`;
|
|
339
342
|
}
|
|
340
343
|
}
|