Skip to content

Commit 5136649

Browse files
authored
chore: WebサイトのSitemapとrobots.txtの生成でHono SSG pluginを使用するように変更 (#253)
1 parent e95f113 commit 5136649

File tree

4 files changed

+16
-38
lines changed

4 files changed

+16
-38
lines changed

website/bun.lockb

731 Bytes
Binary file not shown.

website/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
},
1414
"devDependencies": {
1515
"@biomejs/biome": "1.9.4",
16+
"@hono/ssg-plugins-essential": "^0.1.0",
1617
"@hono/vite-dev-server": "^0.19.0",
17-
"@hono/vite-ssg": "^0.1.2",
18+
"@hono/vite-ssg": "^0.2.0",
1819
"@tailwindcss/typography": "^0.5.16",
1920
"@tailwindcss/vite": "^4.1.5",
2021
"@types/bun": "latest",
21-
"hono": "^4.6.13",
22+
"hono": "^4.9.0",
2223
"pagefind": "^1.3.0",
2324
"tailwind-merge": "^3.3.0",
2425
"tailwindcss": "^4.1.5",

website/src/index.tsx

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -71,39 +71,4 @@ flattenedPages.forEach((page, pageIndex) => {
7171
});
7272
});
7373

74-
app.get("/sitemap.xml", (c) => {
75-
const routes = ["/", ...flattenedPages.map((page) => page.route)];
76-
const today = new Date();
77-
const formattedDate = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, "0")}-${String(today.getDate()).padStart(2, "0")}`;
78-
79-
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
80-
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
81-
${routes
82-
.map(
83-
(route) => ` <url>
84-
<loc>https://typst-jp.github.io${route}</loc>
85-
<lastmod>${formattedDate}</lastmod>
86-
</url>`,
87-
)
88-
.join("\n")}
89-
</urlset>
90-
`;
91-
92-
return c.text(sitemap, 200, {
93-
"Content-Type": "application/xml",
94-
});
95-
});
96-
97-
app.get("/robots.txt", (c) => {
98-
const robotsTxt = `User-agent: *
99-
Allow: /
100-
101-
Sitemap: https://typst-jp.github.io/sitemap.xml
102-
`;
103-
104-
return c.text(robotsTxt, 200, {
105-
"Content-Type": "text/plain",
106-
});
107-
});
108-
10974
export default app;

website/vite.config.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { rmSync, symlinkSync } from "node:fs";
22
import { resolve } from "node:path";
3+
import { robotsTxtPlugin } from "@hono/ssg-plugins-essential/robots-txt";
4+
import { sitemapPlugin } from "@hono/ssg-plugins-essential/sitemap";
35
import { defaultOptions } from "@hono/vite-dev-server";
46
import devServer from "@hono/vite-dev-server";
57
import ssg from "@hono/vite-ssg";
@@ -16,7 +18,17 @@ symlinkSync(assetsDocsPath, publicAssetsDocsPath, "dir");
1618
export default defineConfig({
1719
plugins: [
1820
tailwindcss(),
19-
ssg(),
21+
ssg({
22+
plugins: [
23+
sitemapPlugin({
24+
baseUrl: "https://typst-jp.github.io/",
25+
}),
26+
robotsTxtPlugin({
27+
rules: [{ userAgent: "*", allow: ["/"] }],
28+
sitemapUrl: "https://typst-jp.github.io/sitemap.xml",
29+
}),
30+
],
31+
}),
2032
devServer({
2133
entry: "src/index.tsx",
2234
exclude: [...defaultOptions.exclude, /^\/assets\/.+/, /^\/index\.html$/],

0 commit comments

Comments
 (0)