1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

はじめに

以前こちらの記事でNext.js13でのサイトマップの作り方を説明しました

今回はさらに/events/1のようなidを含めたサイトマップを作る方法をまとめます

やり方

app/sitemap.tsを作って以下の処理を書きます

app/sitemap.ts
import { getEvents } from "./lib/api/event";
import { getPitches } from "./lib/api/pitch";

const URL = "https://pitchme.jp";

export default async function sitemap() {
  const events = await getEvents();
  const eventsPages = events.map((event) => {
    return {
      url: `${URL}/events/${event.id}`,
      lastModified: event.date,
    };
  });

  const pitches = await getPitches();
  const pitchesPages = pitches.map((pitch) => {
    return {
      url: `${URL}/pitch/${pitch.id}`,
      lastModified: new Date(),
    };
  });

  const routes = [
    { url: `${URL}/` },
    { url: `${URL}/events` },
    { url: `${URL}/events/recruitment` },
    { url: `${URL}/pitch` },
    { url: `${URL}/terms` },
    { url: `${URL}/privacy` },
    { url: `${URL}/contact` },
  ].map((route) => ({
    url: route.url,
    lastModified: new Date(),
  }));

  return [...routes, ...eventsPages, ...pitchesPages];
}

サーバーサイドでデータを取得してIdを取得して返しています
ちなみにサイトマップ登録したところ日付が不正となったのですが、時間が経つとなおりました

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?