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
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,23 @@ coverage
.vercel

# Build Outputs
.astro/
.next/
.nuxt/
.output/
.svelte-kit/
out/
/build
dist
*.tsbuildinfo

# Generated example docs
apps/*/public/docs/
apps/*/public/llms-full.txt
apps/*/public/llms.txt
apps/sveltekit-example/static/docs/
apps/sveltekit-example/static/llms-full.txt
apps/sveltekit-example/static/llms.txt


# Debug
Expand Down
19 changes: 19 additions & 0 deletions apps/astro-example/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import path from "node:path";
import mdx from "@astrojs/mdx";
import { defineConfig } from "astro/config";
import { createMdxSourcePlugins } from "leadtype/mdx";

export default defineConfig({
integrations: [
mdx({
remarkPlugins: [
...createMdxSourcePlugins({
typeTableBasePath: path.resolve(
process.cwd(),
"../../examples/shared-docs"
),
}),
],
}),
],
});
20 changes: 20 additions & 0 deletions apps/astro-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "astro-example",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"docs:generate": "leadtype generate --src ../../examples/shared-docs --out public --base-url http://localhost:4321 --json",
"dev": "bun run --filter leadtype build && bun run docs:generate && ASTRO_TELEMETRY_DISABLED=1 astro dev",
"build": "bun run --filter leadtype build && bun run docs:generate && ASTRO_TELEMETRY_DISABLED=1 astro build",
"preview": "ASTRO_TELEMETRY_DISABLED=1 astro preview",
"check-types": "bun run --filter leadtype build && bun run docs:generate && ASTRO_TELEMETRY_DISABLED=1 astro check"
},
"dependencies": {
"@astrojs/check": "^0.9.4",
"@astrojs/mdx": "^4.0.0",
"astro": "^5.0.0",
"leadtype": "workspace:*",
"typescript": "6.0.3"
}
}
68 changes: 68 additions & 0 deletions apps/astro-example/public/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
body {
margin: 0;
color: #20262d;
background: #f8fafc;
font-family: Arial, sans-serif;
}

a {
color: #0c6b58;
}

.shell,
.docs-layout {
width: min(1080px, calc(100% - 32px));
margin: 0 auto;
}

.shell {
padding: 80px 0;
}

.docs-layout {
display: grid;
grid-template-columns: 180px minmax(0, 1fr);
gap: 32px;
padding: 32px 0;
}

aside,
.search,
.markdown {
border: 1px solid #d8e0e8;
border-radius: 8px;
background: white;
}

aside {
display: grid;
align-content: start;
gap: 12px;
padding: 16px;
}

.button {
display: inline-flex;
margin-top: 16px;
padding: 10px 14px;
border-radius: 6px;
color: white;
background: #0c6b58;
text-decoration: none;
}

.search,
.markdown {
padding: 16px;
}

.markdown {
overflow: auto;
white-space: pre-wrap;
}

@media (max-width: 720px) {
.docs-layout {
grid-template-columns: 1fr;
}
}
12 changes: 12 additions & 0 deletions apps/astro-example/src/lib/source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import path from "node:path";
import { createDocsSource } from "leadtype";
import docsConfig from "../../../../examples/shared-docs/docs/docs.config";

const fixtureRoot = path.resolve(process.cwd(), "../../examples/shared-docs");

export const source = await createDocsSource({
contentDir: path.join(fixtureRoot, "docs"),
groups: docsConfig.groups,
baseUrl: "http://localhost:4321",
typeTableBasePath: fixtureRoot,
});
68 changes: 68 additions & 0 deletions apps/astro-example/src/pages/docs/[...slug].astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
import { createGetStaticPaths, createLoadPageData } from "leadtype/astro";
import { source } from "../../lib/source";

export const getStaticPaths = createGetStaticPaths({ source });

const loadPageData = createLoadPageData({ source });
const page = await loadPageData(Astro.params.slug);

if (!page) {
return Astro.redirect("/docs");
}
---

<html lang="en">
<head>
<title>{page.title}</title>
<link rel="stylesheet" href="/styles.css" />
</head>
<body>
<main class="docs-layout">
<aside>
<a href="/llms.txt">llms.txt</a>
<a href="/llms-full.txt">llms-full.txt</a>
<a href={page.urlPath === "/docs" ? "/docs/index.md" : `${page.urlPath}.md`}>Markdown</a>
</aside>
<article>
<section class="search">
<input id="docs-search" aria-label="Search docs" placeholder="Search docs" />
<span id="docs-search-status" role="status" aria-live="polite">idle</span>
<ul id="docs-search-results"></ul>
</section>
<pre class="markdown">{page.markdown}</pre>
</article>
</main>
<script>
import { createSearchClient } from "leadtype/search/client";

const input = document.querySelector<HTMLInputElement>("#docs-search");
const status = document.querySelector("#docs-search-status");
const results = document.querySelector("#docs-search-results");
const client = createSearchClient("docs");

if (input && status && results) {
input.addEventListener("input", async () => {
const query = input.value;
status.textContent = query.trim() ? "loading" : "idle";
results.replaceChildren();
if (!query.trim()) return;
try {
const matches = await client.search(query);
status.textContent = "ready";
for (const result of matches) {
const item = document.createElement("li");
const link = document.createElement("a");
link.href = result.urlWithHash;
link.textContent = result.title;
item.append(link);
results.append(item);
}
} catch {
status.textContent = "error";
}
});
}
</script>
</body>
</html>
14 changes: 14 additions & 0 deletions apps/astro-example/src/pages/docs/[...slug].md.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createDocsEndpoint, createMarkdownStaticPaths } from "leadtype/astro";
import { normalizeAgentReadabilityManifest } from "leadtype/llm/readability";
import manifestJson from "../../../public/docs/agent-readability.json";
import { source } from "../../lib/source";

const manifest = normalizeAgentReadabilityManifest(manifestJson);

export const getStaticPaths = createMarkdownStaticPaths({ source });

export const GET = createDocsEndpoint({
manifest,
});

export const HEAD = GET;
17 changes: 17 additions & 0 deletions apps/astro-example/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html lang="en">
<head>
<title>Leadtype Astro Example</title>
<link rel="stylesheet" href="/styles.css" />
</head>
<body>
<main class="shell">
<p class="eyebrow">Astro dogfood</p>
<h1>Leadtype framework example</h1>
<p>
Astro renders the shared docs, serves markdown endpoints, and searches
static JSON with the plain browser helper.
</p>
<a class="button" href="/docs">Open docs</a>
</main>
</body>
</html>
7 changes: 7 additions & 0 deletions apps/astro-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "astro/tsconfigs/strict",
"compilerOptions": {
"types": ["astro/client"]
},
"include": ["src", "astro.config.mjs"]
}
12 changes: 4 additions & 8 deletions apps/example/server/utils/agent-readability.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import type {
AgentReadabilityManifest,
MarkdownMirrorTarget,
} from "leadtype/llm/readability";
import type { MarkdownMirrorTarget } from "leadtype/llm/readability";
import { normalizeAgentReadabilityManifest } from "leadtype/llm/readability";
import {
getHeader,
getRequestProtocol,
Expand All @@ -14,10 +12,8 @@ import manifestJson from "../../src/generated/agent-readability.json" with {
type: "json",
};

export const agentReadabilityManifest = {
...manifestJson,
version: 1,
} as unknown as AgentReadabilityManifest;
export const agentReadabilityManifest =
normalizeAgentReadabilityManifest(manifestJson);

export function getRequestOrigin(event: H3Event): string | undefined {
const forwardedHost = getHeader(event, "x-forwarded-host")
Expand Down
Loading
Loading