Fetches the site's SEO files as raw text: the XML sitemap, robots.txt, llms.txt,
llms-full.txt and the Markdown version of a page. Serve each from a route handler on your
domain. Accessible as lynkow.seo. The SDK never caches these files.
Access via: lynkow.seo
Methods
6 methods
getMarkdown
getMarkdown(contentPath: string, options?: BaseRequestOptions): Promise<string>Fetches one article, blog category or page as Markdown by its public URL path; the SDK
appends .md. Pass Content.path for an article and Page.publicPath for a page.
Throws LynkowError NOT_FOUND (apiCode PATH_NOT_FOUND) when the path matches
nothing published, and NOT_FOUND when llms.txt is turned off in the SEO settings.
Parameter | Type | Description |
|---|---|---|
|
| The public URL path, such as |
|
| Request options, such as |
Returns: Promise<string>
const article = await lynkow.contents.getBySlug('my-article')
const md = await lynkow.seo.getMarkdown(article.path)
// In a Next.js catch-all route handler
export async function GET(req: Request) {
const url = new URL(req.url)
const path = url.pathname.replace(/\.md$/, '')
const md = await lynkow.seo.getMarkdown(path)
return new Response(md, {
headers: { 'Content-Type': 'text/markdown; charset=utf-8' }
})
}llmsFullTxt
llmsFullTxt(options?: BaseRequestOptions): Promise<string>Fetches the site's llms-full.txt: its published articles and pages in full in one
Markdown document, plus its catalogue pages. Can be large. Pass locale for that
locale's file: the client locale is not applied. Throws LynkowError NOT_FOUND when
llms.txt is turned off in the SEO settings, or for a locale a multi-language site does
not enable.
Parameter | Type | Description |
|---|---|---|
|
|
|
Returns: Promise<string>
// In a Next.js route handler (app/llms-full.txt/route.ts)
export async function GET() {
const md = await lynkow.seo.llmsFullTxt()
return new Response(md, {
headers: { 'Content-Type': 'text/plain; charset=utf-8' }
})
}llmsTxt
llmsTxt(options?: BaseRequestOptions): Promise<string>Fetches the site's llms.txt, a Markdown index of its articles, pages and catalogue
pages for AI crawlers. Pass locale for that locale's file: the client locale is not
applied, so without the option you get the default locale's file. Throws LynkowError
NOT_FOUND when llms.txt is turned off in the SEO settings, or for a locale a
multi-language site does not enable.
Parameter | Type | Description |
|---|---|---|
|
|
|
Returns: Promise<string>
// In a Next.js route handler (app/llms.txt/route.ts)
export async function GET() {
const md = await lynkow.seo.llmsTxt()
return new Response(md, {
headers: { 'Content-Type': 'text/plain; charset=utf-8' }
})
}robots
robots(options?: BaseRequestOptions): Promise<string>Fetches the site's robots.txt, to serve with Content-Type: text/plain: the rules set
in the SEO settings, or a default User-agent: * block when none are set, then a
Sitemap: line for the site's domain unless that link is turned off. When llms.txt is
enabled, it also keeps Googlebot and Bingbot off /llms.txt and /llms-full.txt.
Parameter | Type | Description |
|---|---|---|
|
| Request options, such as |
Returns: Promise<string>
// In a Next.js route handler (app/robots.txt/route.ts)
export async function GET() {
const txt = await lynkow.seo.robots()
return new Response(txt, {
headers: { 'Content-Type': 'text/plain' }
})
}sitemap
sitemap(options?: BaseRequestOptions): Promise<string>Fetches the site's sitemap.xml, to serve with Content-Type: application/xml. While
the site's own URLs fit in one file (50,000 URLs, 50 MB) and no external sitemap source
is enabled, it is a <urlset>. Otherwise it is a <sitemapindex> of files on your
domain: sitemap-content.xml when one file holds every URL, else sitemap-1.xml to
sitemap-N.xml, then the external sources. Serve those files with
SeoService.sitemapPart: sitemapPart(1) is sitemap-content.xml.
Parameter | Type | Description |
|---|---|---|
|
| Request options, such as |
Returns: Promise<string>
// In a Next.js route handler (app/sitemap.xml/route.ts)
export async function GET() {
const xml = await lynkow.seo.sitemap()
return new Response(xml, {
headers: { 'Content-Type': 'application/xml' }
})
}sitemapPart
sitemapPart(part: number, options?: BaseRequestOptions): Promise<string>Fetches sitemap-{part}.xml, one <urlset> of the site's own URLs, without the external
sitemap sources. SeoService.sitemap lists the parts when the URLs exceed one
file. A site within the limits has one part, so sitemapPart(1) also serves
sitemap-content.xml. Throws LynkowError NOT_FOUND for 0, a part above the count
of parts, or a number that is not a whole number.
Parameter | Type | Description |
|---|---|---|
|
| The part number, counted from 1. |
|
| Request options, such as |
Returns: Promise<string>
// A Next.js folder named `sitemap-[part].xml` is not a dynamic segment:
// only a segment wrapped whole in brackets is. Rewrite the public file
// names to a route handler instead, in next.config.ts:
// async rewrites() {
// return [{ source: '/sitemap\\-:part(\\d+)\\.xml', destination: '/sitemap-part/:part' }]
// }
// app/sitemap-part/[part]/route.ts
export async function GET(
_request: Request,
{ params }: { params: Promise<{ part: string }> }
) {
const { part } = await params
const xml = await lynkow.seo.sitemapPart(Number(part))
return new Response(xml, {
headers: { 'Content-Type': 'application/xml' }
})
}