Skip to content

Commit

Permalink
add robots and sitemap
Browse files Browse the repository at this point in the history
Signed-off-by: Vu Van Dung <[email protected]>
  • Loading branch information
joulev committed Jun 7, 2024
1 parent eea6bb5 commit a46a6a0
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/app/robots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { MetadataRoute } from "next";

export default function robots(): MetadataRoute.Robots {
return {
rules: [
{
userAgent: "*",
disallow: [
"/apps/cuid2/",
"/apps/irasuto/add",
"/apps/link/success",
"/apps/link/l",
"/apps/live-reaction",
"/admin",
"/api",
"/p",
"/sign-in",
],
},
],
sitemap: "https://joulev.dev/sitemap.xml",
};
}
77 changes: 77 additions & 0 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { execSync } from "node:child_process";
import type { MetadataRoute } from "next";
import { meta } from "./(public)/blogs/meta";

function getLastUpdatedDate(filePath: string) {
const command = `git log -1 --format=%cd --date=format:'%Y-%m-%d' '${filePath}'`;
const lastCommitDate = execSync(command, { encoding: "utf-8" }).trim();
return lastCommitDate;
}

export default function sitemap(): MetadataRoute.Sitemap {
const now = new Date();
now.setUTCHours(0, 0, 0, 0);
return [
{
url: "https://joulev.dev",
lastModified: new Date(getLastUpdatedDate("src/app/(public)/(home)")),
priority: 1,
},
{
url: "https://joulev.dev/glui",
lastModified: new Date(getLastUpdatedDate("src/app/(public)/glui")),
priority: 1,
},
{
url: "https://joulev.dev/blogs",
lastModified: new Date(getLastUpdatedDate("src/app/(public)/blogs/meta.ts")),
priority: 0.9,
},
...meta.map(({ slug, postedDate }) => ({
url: `https://joulev.dev/blogs/${slug}`,
lastModified: new Date(postedDate),
priority: 0.9,
})),
...[
"",
"/watching",
"/rewatching",
"/completed/tv",
"/completed/movies",
"/completed/others",
"/paused",
"/dropped",
"/planning",
].map(status => ({
url: `https://joulev.dev/apps/anime${status}`,
lastModified: now,
changeFrequency: "daily" as const,
})),
{
url: "https://joulev.dev/apps/cuid2",
lastModified: new Date(getLastUpdatedDate("src/app/(public)/apps/cuid2")),
},
{
url: "https://joulev.dev/apps/irasuto",
lastModified: now,
changeFrequency: "daily",
},
{
url: "https://joulev.dev/apps/irasuto/random",
lastModified: now,
changeFrequency: "daily",
},
{
url: "https://joulev.dev/apps/link",
lastModified: new Date(getLastUpdatedDate("src/app/(public)/apps/link")),
},
{
url: "https://joulev.dev/apps/snippets",
lastModified: new Date(getLastUpdatedDate("src/app/(public)/apps/snippets")),
},
{
url: "https://joulev.dev/apps/tategaki",
lastModified: new Date(getLastUpdatedDate("src/app/(public)/apps/tategaki")),
},
];
}

0 comments on commit a46a6a0

Please sign in to comment.