mirror of
https://github.com/fosrl/docs-v2.git
synced 2026-10-01 02:09:12 +02:00
seo and geo optimizations
This commit is contained in:
@@ -15,6 +15,7 @@ import { appName, docsDir, getPageMarkdownUrl, gitConfig, siteUrl } from '@/lib/
|
||||
import { AskAIAboutPage } from '@/components/ai/ask-page';
|
||||
import { SiteFooter } from '@/components/site-footer';
|
||||
import { AskBar } from '@/components/ai/ask-bar';
|
||||
import { pageJsonLd } from '@/lib/json-ld';
|
||||
|
||||
export default async function Page(props: PageProps<'/[[...slug]]'>) {
|
||||
const params = await props.params;
|
||||
@@ -25,20 +26,22 @@ export default async function Page(props: PageProps<'/[[...slug]]'>) {
|
||||
const markdownUrl = getPageMarkdownUrl(page).url;
|
||||
|
||||
return (
|
||||
<DocsPage
|
||||
toc={page.data.toc}
|
||||
full={page.data.full}
|
||||
tableOfContent={{ style: 'clerk' }}
|
||||
// rendered after the previous / next page links
|
||||
footer={{
|
||||
children: (
|
||||
<>
|
||||
<SiteFooter />
|
||||
<AskBar />
|
||||
</>
|
||||
),
|
||||
}}
|
||||
>
|
||||
<>
|
||||
<script type="application/ld+json" dangerouslySetInnerHTML={{ __html: pageJsonLd(page) }} />
|
||||
<DocsPage
|
||||
toc={page.data.toc}
|
||||
full={page.data.full}
|
||||
tableOfContent={{ style: 'clerk' }}
|
||||
// rendered after the previous / next page links
|
||||
footer={{
|
||||
children: (
|
||||
<>
|
||||
<SiteFooter />
|
||||
<AskBar />
|
||||
</>
|
||||
),
|
||||
}}
|
||||
>
|
||||
<DocsTitle>{page.data.title}</DocsTitle>
|
||||
<DocsDescription className="mb-0">{page.data.description}</DocsDescription>
|
||||
<div className="flex flex-row flex-wrap gap-2 items-center border-b pb-6">
|
||||
@@ -58,7 +61,8 @@ export default async function Page(props: PageProps<'/[[...slug]]'>) {
|
||||
})}
|
||||
/>
|
||||
</DocsBody>
|
||||
</DocsPage>
|
||||
</DocsPage>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ export async function GET() {
|
||||
`> ${siteDescription}`,
|
||||
'',
|
||||
`The full documentation as a single file is available at ${siteUrl}/llms-full.txt. Append \`.md\` to any page URL to get its Markdown source.`,
|
||||
`An MCP server for searching and reading this documentation is available at ${siteUrl}/mcp.`,
|
||||
'',
|
||||
];
|
||||
const listed = new Set<string>();
|
||||
|
||||
+6
-43
@@ -1,55 +1,18 @@
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { statSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import type { MetadataRoute } from 'next';
|
||||
import { pageLastModified } from '@/lib/last-modified';
|
||||
import { source } from '@/lib/source';
|
||||
import { docsDir, siteUrl } from '@/lib/shared';
|
||||
import { siteUrl } from '@/lib/shared';
|
||||
|
||||
/**
|
||||
* Same shape as a Mintlify docs sitemap (`/docs/sitemap.xml` on Infisical):
|
||||
* one `<loc>` and `<lastmod>` per published page.
|
||||
*/
|
||||
export default function sitemap(): MetadataRoute.Sitemap {
|
||||
const dates = lastCommitDates();
|
||||
|
||||
return source
|
||||
.getPages()
|
||||
.map((page) => {
|
||||
const file = `${docsDir}/${page.path}`;
|
||||
return {
|
||||
url: `${siteUrl}${page.url}`,
|
||||
lastModified: dates.get(file) ?? mtime(page.absolutePath ?? path.join(process.cwd(), file)),
|
||||
};
|
||||
})
|
||||
.map((page) => ({
|
||||
url: `${siteUrl}${page.url}`,
|
||||
lastModified: pageLastModified(page),
|
||||
}))
|
||||
.sort((a, b) => a.url.localeCompare(b.url));
|
||||
}
|
||||
|
||||
/** Newest commit that touched each file under content/docs. Empty when git is unavailable. */
|
||||
function lastCommitDates(): Map<string, Date> {
|
||||
const dates = new Map<string, Date>();
|
||||
try {
|
||||
const out = execFileSync('git', ['log', '--format=COMMIT %cI', '--name-only', '--', docsDir], {
|
||||
encoding: 'utf8',
|
||||
});
|
||||
let current: Date | undefined;
|
||||
for (const line of out.split('\n')) {
|
||||
if (line.startsWith('COMMIT ')) {
|
||||
const date = new Date(line.slice('COMMIT '.length));
|
||||
current = Number.isNaN(date.getTime()) ? undefined : date;
|
||||
} else if (line && current && !dates.has(line)) {
|
||||
dates.set(line, current);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Docker builds without git fall back to file mtime.
|
||||
}
|
||||
return dates;
|
||||
}
|
||||
|
||||
function mtime(file: string): Date {
|
||||
try {
|
||||
return statSync(file).mtime;
|
||||
} catch {
|
||||
return new Date();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user