@rasterstate/agent-markdown (0.1.0)
Installation
@rasterstate:registry=npm config set @rasterstate:registry=npm install @rasterstate/agent-markdown@0.1.0"@rasterstate/agent-markdown": "0.1.0"About this package
@rasterstate/agent-markdown
Markdown copies of public pages for AI agents, for SvelteKit 3 sites on Cloudflare. Shared by fjord.sh, rasterstate.com and stephenway.dev.
Each public page is available as markdown two ways:
Accept: text/markdownon the page URL (content negotiation).- A fixed
/page.mdURL, advertised withLink: <…/page.md>; rel="alternate"; type="text/markdown"and pointing back withrel="canonical".
Each site keeps its own page list, llms.txt and security headers.
Install
echo '@rasterstate:registry=https://rasterhub.com/api/packages/rasterstate/npm/' >> .npmrc
pnpm add @rasterstate/agent-markdown
The registry is public, so installs need no token.
Usage
Both modes share a predicate that says which HTML paths are public:
// src/lib/public-pages.ts
export const isPublicPage = (path: string) => PUBLIC_PAGES.has(path);
Register the matcher so only .md paths reach the markdown route (otherwise its rest param claims every unmatched URL, and an endpoint's 404 skips +error.svelte):
// src/params.ts
import { defineParams } from '@sveltejs/kit/params';
import { matchMarkdown } from '@rasterstate/agent-markdown';
export const params = defineParams({ md: matchMarkdown });
Worker mode (pages rendered per request)
// src/hooks.server.ts
import { sequence } from '@sveltejs/kit/hooks';
import { alternateLinks, markdown } from '@rasterstate/agent-markdown';
export const handle = sequence(
securityHeaders,
alternateLinks({ siteUrl: SITE_URL, isPublic: isPublicPage }),
markdown() // last, so it converts the finished response
);
// src/routes/[...markdown=md]/+server.ts
import { markdownVariant } from '@rasterstate/agent-markdown';
export const GET = (event) => markdownVariant(event, { siteUrl: SITE_URL, isPublic: isPublicPage });
Prerender mode (static site)
Prerendered pages bypass hooks at request time, so the handle runs at build time and _headers carries the links.
// src/hooks.server.ts
export const handle = markdown();
// src/routes/[...markdown=md]/+server.ts
export const prerender = true;
export const GET = (event) =>
markdownVariant(event, { siteUrl: SITE_URL, isPublic: isPublicPage, mode: 'prerender' });
After vite build, append the header rules:
// scripts/agent-headers.js
import { writeAgentHeaders } from '@rasterstate/agent-markdown/headers';
const pages = writeAgentHeaders({
outDir: '.svelte-kit/cloudflare',
siteUrl: 'https://example.com',
globalHeaders: { 'X-Content-Type-Options': 'nosniff' }
});
console.log(`agent headers: ${pages} pages`);
It throws if no .md files were prerendered, so a broken route fails the build instead of silently dropping the copies.
Release
Bump version in package.json, then tag vX.Y.Z and push the tag. The publish workflow needs a PACKAGE_TOKEN secret (Forgejo PAT with write:package).
Dependencies
Dependencies
| ID | Version |
|---|---|
| @markdown-for-agents/web | 1.3.5 |
| markdown-for-agents | 1.4.0 |
Development dependencies
| ID | Version |
|---|---|
| @sveltejs/kit | ^3.1.1 |
| @types/node | ^24.0.0 |
| prettier | ^3.9.10 |
| typescript | ^6.0.3 |
| vitest | ^5.1.0 |
Peer dependencies
| ID | Version |
|---|---|
| @sveltejs/kit | ^3.0.0 |