@larkiny/astro-github-loader 0.14.3 → 0.14.4
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("://");
|
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.4",
|
|
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,39 @@ 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
|
+
|
|
214
247
|
it("should preserve anchors in transformed links", () => {
|
|
215
248
|
const files: ImportedFile[] = [
|
|
216
249
|
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("/") &&
|