Skip to content

Commit

Permalink
feat: add sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
ncrmro committed Feb 5, 2024
1 parent de592a3 commit 9368830
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 34 deletions.
4 changes: 0 additions & 4 deletions next-sitemap.js

This file was deleted.

26 changes: 0 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"eslint": "8.49.0",
"eslint-config-next": "13.5.2",
"kysely-codegen": "^0.10.1",
"next-sitemap": "^1.3.22",
"prettier": "^2.4.1"
},
"prettier": {
Expand Down
25 changes: 22 additions & 3 deletions src/app/sitemap.xml/route.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
import { NextResponse } from "next/server";
import { db } from "@/lib/database";
import { db, sql } from "@/lib/database";

export async function GET(request: Request) {
const rootURL = "https://ncrmro.com";
const posts = await db
.selectFrom("posts")
.select(["slug"])
.select([
"slug",
"updated_at",
// sql<string>`date(updated_at, 'unixepoch', 'utc')`.as("updated_at"),
])
.where("published", "=", 1)
.orderBy("publish_date", "desc")
.execute();
console.log(posts);
const content = `
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>${rootURL}</loc>
</url>
<url>
<loc>${rootURL}/about</loc>
</url>
<url>
<loc>${rootURL}/resume</loc>
</url>
<url>
<loc>${rootURL}/posts/tech</loc>
</url>
<url>
<loc>${rootURL}/posts/travel</loc>
</url>
<url>
<loc>${rootURL}/posts/food</loc>
</url>
${posts
.map(
(p) => `<url>
<loc>${rootURL}/posts/${p.slug}</loc>
<lastmod>${p.updated_at.split(" ")[0]}</lastmod>
</url>`
)
.join("\n")}
Expand Down

0 comments on commit 9368830

Please sign in to comment.