From f9fcbb3fb6945d22a8e5db001d2336ecb89b5001 Mon Sep 17 00:00:00 2001 From: Ru Chern Chong Date: Tue, 20 Aug 2024 01:54:41 +0800 Subject: [PATCH] Update sitemap Relates to #67 --- app/sitemap.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/sitemap.ts b/app/sitemap.ts index 7c626a0..41f01cf 100644 --- a/app/sitemap.ts +++ b/app/sitemap.ts @@ -1,14 +1,31 @@ -import { SITE_URL } from "@/config"; +import { API_URL, SITE_URL } from "@/config"; +import { fetchApi } from "@/utils/fetchApi"; +import type { Make } from "@/types"; import type { MetadataRoute } from "next"; -const sitemap = (): MetadataRoute.Sitemap => { +// TODO: Interim solution +const FUEL_TYPE = ["petrol", "hybrid", "electric", "diesel"]; + +const sitemap = async (): Promise => { + const makes = await fetchApi(`${API_URL}/make`); + return [ { url: SITE_URL, lastModified: new Date(), - changeFrequency: "yearly", - priority: 1, }, + { + url: `${SITE_URL}/cars`, + lastModified: new Date(), + }, + ...FUEL_TYPE.map((type) => ({ + url: `${SITE_URL}/cars/${type}`, + lastModified: new Date(), + })), + ...makes.map((make) => ({ + url: `${SITE_URL}/make/${make}`, + lastModified: new Date(), + })), ]; };