@larkiny/astro-github-loader 0.14.2 → 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,7 +185,17 @@ 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
|
-
|
|
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("./") &&
|
|
195
|
+
!linkPath.startsWith("../") &&
|
|
196
|
+
!linkPath.startsWith("/") &&
|
|
197
|
+
!linkPath.includes("://");
|
|
198
|
+
if (isBareBarePath && context.global.linkMappings) {
|
|
189
199
|
const globalMappings = context.global.linkMappings.filter((m) => m.global);
|
|
190
200
|
if (globalMappings.length > 0) {
|
|
191
201
|
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.
|
|
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",
|
|
@@ -146,6 +146,104 @@ 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
|
+
|
|
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
|
+
|
|
149
247
|
it("should preserve anchors in transformed links", () => {
|
|
150
248
|
const files: ImportedFile[] = [
|
|
151
249
|
createImportedFile(
|
|
@@ -318,7 +318,18 @@ 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
|
-
|
|
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.
|
|
326
|
+
const isBareBarePath =
|
|
327
|
+
linkPath.includes("/") &&
|
|
328
|
+
!linkPath.startsWith("./") &&
|
|
329
|
+
!linkPath.startsWith("../") &&
|
|
330
|
+
!linkPath.startsWith("/") &&
|
|
331
|
+
!linkPath.includes("://");
|
|
332
|
+
if (isBareBarePath && context.global.linkMappings) {
|
|
322
333
|
const globalMappings = context.global.linkMappings.filter((m) => m.global);
|
|
323
334
|
if (globalMappings.length > 0) {
|
|
324
335
|
const rawMapped = applyLinkMappings(
|