Publishing and Workflow

Sitemaps, RSS feeds and llms.txt

Mis à jour 223 vues

Your Kookee content is served from your own domain, so the files crawlers look for — sitemap.xml, rss.xml, llms.txt — have to come from your app. The SDK gives you one bulk read and a set of pure builder functions, all exported from the package root, so each of those routes is a handful of lines instead of a page of string concatenation.

This article is about generating files. SEO and metadata for your content covers the fields themselves: what metaTitle and metaDescription are for, and how locale fallback creates duplicate content.

One getPath for every builder

Every builder needs to know where an entry lives on your site, and only you know that. Write it once and pass it everywhere:

TypeScript
import type { GetPath } from '@kookee/sdk';

export const getPath: GetPath = (entry) => {
  switch (entry.type) {
    case 'blog':
      return entry.slug ? `/blog/${entry.slug}` : null;
    case 'changelog':
      return entry.slug ? `/changelog/${entry.slug}` : null;
    case 'help_article':
      return entry.slug && entry.category ? `/help/${entry.category.slug}/${entry.slug}` : null;
    default:
      return null;
  }
};

The function receives { type, id, slug, locale, category } and returns a path or null. null means "this entry has no page on my site", and the entry is skipped everywhere — that is how you keep types you do not render out of the sitemap, the feed and llms.txt in one place.

Return a path, not a full URL. Each builder joins it to baseUrl for you and handles the slash between them.

If you serve locales on separate paths, branch on entry.locale — the export contains every locale of every entry:

TypeScript
export const getPath: GetPath = (entry) => {
  if (entry.type !== 'blog' || !entry.slug) return null;
  return entry.locale === 'en' ? `/blog/${entry.slug}` : `/${entry.locale}/blog/${entry.slug}`;
};

Returning null for non-default locales is the other valid answer, if you only publish one language.

entries.export(): the bulk read

kookee.entries.export() returns every published, public entry of the project as slim rows — all types, all locales, in one call. It follows pagination internally, so there is no page loop to write:

TypeScript
import { Kookee } from '@kookee/sdk';

const kookee = new Kookee({ apiKey: process.env.KOOKEE_API_KEY });

const entries = await kookee.entries.export();

Each row is { type, typeName, id, slug, locale, title, description, category, publishedAt, updatedAt, markdown }:

  • description is the entry's metaDescription, falling back to its excerpt text, or null.

  • typeName is the entry type's display name — "Blog", "Help Center" — which is what buildLlmsTxt uses for its section headings.

  • category is { slug, name } or null.

  • markdown is null unless you ask for it.

Two parameters:

TypeScript
const entries = await kookee.entries.export({ type: ['blog', 'help_article'], markdown: true });

type restricts the result to those entry type slugs. markdown adds each body as Markdown, which only llms-full.txt needs — leave it off otherwise, since it makes the response much larger.

Drafts, entries scheduled for a future date, entries whose unpublish date has passed and entries set to chatbot-only visibility never appear in the export. You cannot leak an unpublished page into a sitemap this way.

Page metadata with getEntrySeo

getEntrySeo turns one entry into the facts a <head> needs. It takes a list or detail entry — not an export row:

TypeScript
import { getEntrySeo } from '@kookee/sdk';
import { getPath } from './seo-paths';

const post = await kookee.blog.getBySlug(slug);
const translations = await kookee.blog.getTranslationsBySlug(slug);

const seo = getEntrySeo(post, {
  baseUrl: 'https://example.com',
  getPath,
  siteName: 'Example',
  translations,
});

EntrySeoOptions:

  • baseUrl — your site's origin, https://example.com. Required.

  • getPath — the function above. Required.

  • siteName — used as the JSON-LD publisher. Optional.

  • titleSuffix — appended to the entry title, ' | Blog'. Optional, and applied only when the entry has no metaTitle; a hand-written meta title is used exactly as typed.

  • translations — the map from getTranslationsBySlug() or getTranslationsById(). Optional; without it, alternates is empty.

You get back { title, description, path, canonical, image, type, publishedAt, updatedAt, alternates, jsonLd }. path is the raw path, canonical is that path joined to baseUrl, and both are null when getPath returned null. image is the entry's cover image URL, or null. type is 'article' for blog and changelog entries and 'website' for everything else.

The description follows a fallback chain, so it is never empty: metaDescription, then the excerpt text trimmed to 160 characters on a word boundary with an ellipsis, then the title. The trimming function is exported if you want the same behavior elsewhere:

TypeScript
import { truncateDescription } from '@kookee/sdk';

truncateDescription(someLongText); // 160 chars max
truncateDescription(someLongText, 80); // or your own limit

In Next.js, generateMetadata maps onto it almost field for field:

TypeScript
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
  const { slug } = await params;
  const post = await kookee.blog.getBySlug(slug);
  const seo = getEntrySeo(post, { baseUrl: SITE_URL, getPath, siteName: 'Example' });

  return {
    title: seo.title,
    description: seo.description,
    alternates: {
      canonical: seo.canonical ?? undefined,
      languages: Object.fromEntries(seo.alternates.map((a) => [a.hreflang, a.href])),
    },
    openGraph: {
      type: seo.type,
      title: seo.title,
      description: seo.description,
      url: seo.canonical ?? undefined,
      images: seo.image ? [seo.image] : undefined,
      publishedTime: seo.publishedAt ?? undefined,
      modifiedTime: seo.updatedAt,
    },
    twitter: { card: seo.image ? 'summary_large_image' : 'summary' },
  };
}

alternates and jsonLd, and where they go

seo.alternates is an array of { hreflang, href }. It is empty unless you passed translations and the entry actually has other locales; when it is not empty, the entry's own locale comes first. Each href is built by running getPath against that translation's own slug, so per-locale slugs are handled for you.

They belong in the head as <link> tags:

HTML
<link rel="alternate" hreflang="en" href="https://example.com/blog/hello-world" />
<link rel="alternate" hreflang="de" href="https://example.com/de/blog/hallo-welt" />
tsx
{seo.alternates.map((alternate) => (
  <link key={alternate.hreflang} rel="alternate" hrefLang={alternate.hreflang} href={alternate.href} />
))}

seo.jsonLd is a schema.org Article object — headline, description, image, datePublished, dateModified, author, publisher and mainEntityOfPage — or null when the entry has no page. It belongs in a script tag, not the head's meta tags. Serialize it with serializeJsonLd, never plain JSON.stringify: a </script> in an entry's title would close the tag and run whatever follows it.

tsx
import { serializeJsonLd } from '@kookee/sdk';

{seo.jsonLd && (
  <script
    type="application/ld+json"
    dangerouslySetInnerHTML={{ __html: serializeJsonLd(seo.jsonLd) }}
  />
)}

In TanStack Start, use the meta descriptor instead of head().scripts, because the router escapes the former and injects the latter unescaped:

TypeScript
head: () => ({ meta: [{ 'script:ld+json': seo.jsonLd }] }),

Sitemap

buildSitemap takes export rows and returns the finished XML document:

TypeScript
import { buildSitemap } from '@kookee/sdk';

// app/sitemap.xml/route.ts (Next.js) — or any server route
export async function GET() {
  const entries = await kookee.entries.export();
  const xml = buildSitemap(entries, {
    baseUrl: SITE_URL,
    getPath,
    extraUrls: ['/', '/pricing', '/about'],
  });

  return new Response(xml, { headers: { 'Content-Type': 'application/xml' } });
}

extraUrls is a list of paths for pages Kookee knows nothing about — your home page, pricing, marketing pages. They are listed first, as <loc> only. Every entry gets a <loc> plus a <lastmod> taken from its updatedAt, as a plain YYYY-MM-DD date. Entries whose getPath returns null are skipped.

The sitemap protocol caps one file at 50,000 URLs and 50 MB. buildSitemap does not split for you — it will happily emit a file that is over the limit — so if you are anywhere near it, chunk the rows yourself and serve a sitemap index:

TypeScript
const CHUNK_SIZE = 20_000;

const chunks = [];
for (let i = 0; i < entries.length; i += CHUNK_SIZE) {
  chunks.push(buildSitemap(entries.slice(i, i + CHUNK_SIZE), { baseUrl: SITE_URL, getPath }));
}

// then serve chunk N at /sitemap-N.xml and list them in a <sitemapindex> at /sitemap.xml

Most projects are nowhere near 50,000 URLs. Check entries.length before building anything more complicated than the first example.

RSS

buildFeed produces an RSS 2.0 document. Unlike the sitemap, it takes list entries, not export rows, because it uses the HTML excerpt for each item's description:

TypeScript
import { buildFeed } from '@kookee/sdk';

const posts = await kookee.blog.list({ limit: 50 });

const xml = buildFeed(posts.data, {
  baseUrl: SITE_URL,
  getPath,
  title: 'Example Blog',
  description: 'Latest posts',
  feedPath: '/rss.xml',
});

return new Response(xml, { headers: { 'Content-Type': 'application/rss+xml' } });
  • title and description describe the feed itself, and become the channel's title and description.

  • feedPath is where you serve the feed. It is emitted as the feed's atom:link rel="self", so it has to match the route you actually mounted, or readers will follow a dead self-reference.

Items come out in the order you pass them in, so pass them newest first — which is what list() already gives you. Each item gets a title, a link, a guid equal to the link, a pubDate when the entry has a published date, and a CDATA description when it has an excerpt. Entries whose getPath returns null are skipped.

llms.txt

llms.txt is a plain-text index at the root of your site, in the style described at llmstxt.org: a heading, an optional one-line summary, and a linked list of your pages with a short description each. It exists so that an AI assistant reading your site gets a clean map of it instead of scraping navigation chrome. llms-full.txt is the same index with every page's Markdown appended, so an assistant can read the whole thing in one request.

buildLlmsTxt writes both, from the same export rows:

TypeScript
import { buildLlmsTxt } from '@kookee/sdk';

const entries = await kookee.entries.export({ type: ['help_article', 'blog'], markdown: true });

const index = buildLlmsTxt(entries, {
  baseUrl: SITE_URL,
  getPath,
  siteName: 'Example',
  description: 'Docs and blog for Example',
});

const full = buildLlmsTxt(entries, {
  baseUrl: SITE_URL,
  getPath,
  siteName: 'Example',
  full: true,
});
  • siteName is required and becomes the # heading.

  • description is optional and becomes a > blockquote under it.

  • full appends each entry's Markdown body under a ## Title with a Source: line. It needs entries.export({ markdown: true }) — without it every markdown field is null and the bodies are silently left out.

The output groups entries into one ## section per entry type, using the type's display name, in the order the types first appear in the rows. Each line is - [Title](url): description, with [ and ] in the title and ( and ) in the URL escaped so the link stays intact.

Mounted as a route — this is TanStack Start, and the same shape works for the sitemap and the feed:

TypeScript
export const Route = createFileRoute('/llms.txt')({
  server: {
    handlers: {
      GET: async () => {
        const entries = await kookee.entries.export({ type: ['help_article'] });
        const body = buildLlmsTxt(entries, { baseUrl: SITE_URL, getPath, siteName: 'Example' });

        return new Response(body, { headers: { 'Content-Type': 'text/plain; charset=utf-8' } });
      },
    },
  },
});

Serve the index at /llms.txt and the full version at /llms-full.txt, both as text/plain.

Cache these routes

All four builders are pure functions over data you fetched, so the cost is the fetch, not the build. A crawler hitting an uncached sitemap.xml triggers a full export every time. Cache the response, or regenerate it on a schedule — see Caching strategies for Kookee content.

TypeScript
return new Response(xml, {
  headers: {
    'Content-Type': 'application/xml',
    'Cache-Control': 'public, max-age=3600, s-maxage=86400',
  },
});

Building URLs yourself

If you need the same base-plus-path joining outside a builder, it is exported:

TypeScript
import { joinUrl } from '@kookee/sdk';

joinUrl('https://example.com/', '/blog/hello-world'); // https://example.com/blog/hello-world

It trims trailing slashes from the base and adds the separator when the path lacks one, so a baseUrl written either way produces the same URL.

Cet article vous a-t-il aidé ?