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
2 changes: 2 additions & 0 deletions website/src/components/templates/BaseTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export const BaseTemplate: FC<BaseTemplateProps> = ({
<meta name="twitter:site" content="@typstapp" />
<meta name="twitter:card" content="summary_large_image" />
<link rel="canonical" href={`https://typst-jp.github.io${route}`} />
<meta name="robots" content="index, follow" />
<link rel="sitemap" type="application/xml" href="/sitemap.xml" />
<meta
name="twitter:image:alt"
content="The left side of a text editor with colorful cursors, as well as the text 'Compose papers faster, Typst'"
Expand Down
35 changes: 35 additions & 0 deletions website/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,39 @@ flattenedPages.forEach((page, pageIndex) => {
});
});

app.get("/sitemap.xml", (c) => {
const routes = ["/", ...flattenedPages.map((page) => page.route)];
const today = new Date();
const formattedDate = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, "0")}-${String(today.getDate()).padStart(2, "0")}`;

const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${routes
.map(
(route) => ` <url>
<loc>https://typst-jp.github.io${route}</loc>
<lastmod>${formattedDate}</lastmod>
</url>`,
)
.join("\n")}
</urlset>
`;

return c.text(sitemap, 200, {
"Content-Type": "application/xml",
});
});

app.get("/robots.txt", (c) => {
const robotsTxt = `User-agent: *
Allow: /

Sitemap: https://typst-jp.github.io/sitemap.xml
`;

return c.text(robotsTxt, 200, {
"Content-Type": "text/plain",
});
});

export default app;
Loading