Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/astro-github-loader/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@larkiny/astro-github-loader",
"type": "module",
"version": "0.14.3",
"version": "0.14.4",
"description": "Load content from GitHub repositories into Astro content collections with asset management and content transformations",
"keywords": [
"astro",
Expand Down
33 changes: 33 additions & 0 deletions packages/astro-github-loader/src/github.link-transform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,39 @@ describe("globalLinkTransform", () => {
expect(result[0].content).toBe("[Overview](/overview/)");
});

it("should not early-return single-segment bare-path sibling references", () => {
// Single-segment bare paths like "page-b.md" are sibling-file references.
// They must go through normalizePath() (joining with current dir) to resolve
// via sourceToTargetMap, NOT be caught by the bare-path pre-normalization check.
const files: ImportedFile[] = [
createImportedFile(
"docs/api/page-a.md",
"src/content/docs/api/page-a.md",
"[See B](page-b.md#section)",
),
createImportedFile(
"docs/api/page-b.md",
"src/content/docs/api/page-b.md",
"# Page B",
),
];

const result = globalLinkTransform(files, {
stripPrefixes: ["src/content/docs"],
linkMappings: [
{
pattern: /\.md(#|$)/,
replacement: "$1",
global: true,
},
],
logger,
});

// "page-b.md" normalizes to "docs/api/page-b.md", resolves via sourceToTargetMap
expect(result[0].content).toBe("[See B](/api/page-b/#section)");
});

it("should preserve anchors in transformed links", () => {
const files: ImportedFile[] = [
createImportedFile(
Expand Down
9 changes: 6 additions & 3 deletions packages/astro-github-loader/src/github.link-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,13 @@ function transformLink(
// Bare-path links (e.g., "docs/markdown/autoapi/foo/") are repo-root-relative
// but normalizePath() treats them as file-relative, mangling the path.
// Applying global mappings first lets patterns match the link as written.
// Only for bare paths — relative (./, ../) and absolute (/) links must flow
// through normalizePath() first to avoid over-matching by generic global
// mappings like .md-stripping from generateStarlightLinkMappings().
// Only for multi-segment bare paths — relative (./, ../) and absolute (/) links
// must flow through normalizePath() first. Single-segment bare paths (no "/")
// like "api-algopy" or "types_amount.AlgoAmount" are sibling-file references
// that also need normalization, so we require at least one "/" to distinguish
// repo-root-relative paths from sibling references.
const isBareBarePath =
linkPath.includes("/") &&
!linkPath.startsWith("./") &&
!linkPath.startsWith("../") &&
!linkPath.startsWith("/") &&
Expand Down