Skip to content

Commit d992232

Browse files
committed
fix: llms links
1 parent 6388d1f commit d992232

4 files changed

Lines changed: 41 additions & 7 deletions

File tree

data/docs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export const siteMetadata = {
8181
"Probitas is a scenario-based testing framework for Deno that enables declarative, readable integration tests for APIs, databases, message queues, and other backend services.",
8282
github: "https://github.com/jsr-probitas/probitas",
8383
jsr: "https://jsr.io/@probitas/probitas",
84-
baseUrl: "https://jsr-probitas.github.io/documents",
84+
baseUrl: Deno.env.get("BASE_URL") ??
85+
"https://jsr-probitas.github.io/documents",
8586
};
8687

8788
/**

lib/api-markdown.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
formatMethodSignature,
3535
formatTypeAliasSignature,
3636
} from "./signature-formatters.ts";
37+
import { siteMetadata } from "../data/docs.ts";
3738

3839
// ============================================================================
3940
// Type Reference Collector
@@ -61,7 +62,7 @@ class TypeReferenceCollector {
6162
localTypes: Set<string>,
6263
typeToPackage: Map<string, string>,
6364
currentPackage: string,
64-
baseUrl = "https://jsr-probitas.github.io/documents",
65+
baseUrl = siteMetadata.baseUrl,
6566
) {
6667
this.localTypes = localTypes;
6768
this.typeToPackage = typeToPackage;
@@ -525,7 +526,7 @@ export function generateApiMarkdown(
525526
const lines: string[] = [];
526527
const {
527528
allPackages = [],
528-
baseUrl = "https://jsr-probitas.github.io/documents",
529+
baseUrl = siteMetadata.baseUrl,
529530
updatedAt,
530531
} = options;
531532

lib/llms.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ async function getPackageDescription(packageName: string): Promise<string> {
3939
export async function generateLlmsTxt(): Promise<string> {
4040
const groups = await getPackageGroups();
4141

42+
const resolveDocMarkdownPath = (path: string): string =>
43+
path.endsWith("/") ? `${path}index.md` : `${path}.md`;
44+
4245
const lines: string[] = [
4346
`# ${siteMetadata.name}`,
4447
"",
@@ -47,7 +50,9 @@ export async function generateLlmsTxt(): Promise<string> {
4750
"## Documentation",
4851
"",
4952
...docPages.map((doc) =>
50-
`- [${doc.title}](${basePath}${doc.path}index.md): ${doc.description}`
53+
`- [${doc.title}](${basePath}${
54+
resolveDocMarkdownPath(doc.path)
55+
}): ${doc.description}`
5156
),
5257
"",
5358
"## API Reference",

tests/internal_link_check_test.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Element,
66
} from "https://deno.land/x/deno_dom@v0.1.47/deno-dom-wasm.ts";
77
import { dirname, fromFileUrl, resolve } from "jsr:@std/path@^1.0.1";
8+
import { basePath, siteMetadata } from "../data/docs.ts";
89

910
const SRC_ROOT = fromFileUrl(import.meta.resolve("../"));
1011
const SITE_ROOT = resolve(SRC_ROOT, "dist");
@@ -55,13 +56,39 @@ function isTargetLink(link: string): boolean {
5556
function normalizeLink(link: string, htmlMode: boolean): Link {
5657
const [path, fragment = null] = link.split("#");
5758
const cleanPath = path.split("?")[0];
59+
const basePaths = new Set<string>();
60+
if (basePath) {
61+
basePaths.add(basePath);
62+
}
63+
try {
64+
const { pathname } = new URL(siteMetadata.baseUrl);
65+
if (pathname && pathname !== "/") {
66+
basePaths.add(pathname);
67+
}
68+
} catch {
69+
// Ignore invalid baseUrl; basePaths will rely on BASE_PATH.
70+
}
71+
let normalizedPath = cleanPath;
72+
for (const candidate of basePaths) {
73+
const normalizedCandidate = candidate.endsWith("/")
74+
? candidate.slice(0, -1)
75+
: candidate;
76+
if (
77+
normalizedCandidate &&
78+
normalizedPath.startsWith(normalizedCandidate)
79+
) {
80+
const nextPath = normalizedPath.slice(normalizedCandidate.length);
81+
normalizedPath = nextPath || "/";
82+
break;
83+
}
84+
}
5885
if (!cleanPath) {
5986
return ["", fragment];
6087
}
61-
if (htmlMode && cleanPath.endsWith("/")) {
62-
return [`${cleanPath}index.html`, fragment];
88+
if (htmlMode && normalizedPath.endsWith("/")) {
89+
return [`${normalizedPath}index.html`, fragment];
6390
}
64-
return [cleanPath, fragment];
91+
return [normalizedPath, fragment];
6592
}
6693

6794
function readFile(filePath: string): File {

0 commit comments

Comments
 (0)