From 19d61f7bc5b8be639405209a7e1029b24debf077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Famibelle-Pronzola?= Date: Sat, 22 Jul 2023 13:05:16 +0400 Subject: [PATCH] Move sitemap script to app and adapt it --- app/sitemap.js | 54 +++++++++++++++++++++++++++++++++++++++ pages/sitemap.xml.js | 61 -------------------------------------------- 2 files changed, 54 insertions(+), 61 deletions(-) create mode 100644 app/sitemap.js delete mode 100644 pages/sitemap.xml.js diff --git a/app/sitemap.js b/app/sitemap.js new file mode 100644 index 0000000..9f0f1f0 --- /dev/null +++ b/app/sitemap.js @@ -0,0 +1,54 @@ +import {jwennAwtisSlug, jwennTeksSlug} from '../lib/oki-api' + +const url = process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost' + +async function jwennDone() { + const teksSlug = await jwennTeksSlug() + const awtisSlug = await jwennAwtisSlug() + + return { + teksSlug, + awtisSlug + } +} + +export default async function sitemap() { + const {teksSlug, awtisSlug} = await jwennDone() + + const urls = [ + { + url, + priority: 1 + }, + { + url: `${url}/paroles`, + priority: 0.9 + }, + { + url: `${url}/sipote`, + priority: 0.8 + }, + { + url: `${url}/awtis`, + priority: 0.6 + }, + { + url: `${url}/pwopose`, + priority: 0.5 + } + ] + + for (const teks of teksSlug) { + urls.push({ + url: `${`${url}/paroles/${teks}`}` + }) + } + + for (const awtis of awtisSlug) { + urls.push({ + url: `${`${url}/awtis/${awtis}`}` + }) + } + + return urls +} diff --git a/pages/sitemap.xml.js b/pages/sitemap.xml.js deleted file mode 100644 index 446d773..0000000 --- a/pages/sitemap.xml.js +++ /dev/null @@ -1,61 +0,0 @@ -import {jwennAwtisSlug, jwennTeksSlug} from '../lib/oki-api' - -const url = process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost' - -const createSitemap = (teksSlug, awtisSlug) => ( - ` - - - ${url} - 1 - - - ${url}/paroles - 0.9 - - - ${url}/soutyen - 0.8 - - - ${url}/awtis - 0.6 - - - ${url}/soumet - 0.5 - - ${teksSlug - .map(slug => ` - - ${`${url}/paroles/${slug}`} - - `) - .join('')} - ${awtisSlug - .map(slug => ` - - ${`${url}/awtis/${slug}`} - - `) - .join('')} - - ` -) - -export default function Sitemap() { - return null -} - -export async function getServerSideProps({res}) { - const teksSlug = await jwennTeksSlug() - const awtisSlug = await jwennAwtisSlug() - - res.setHeader('Content-Type', 'text/xml') - res.write(createSitemap(teksSlug, awtisSlug)) - res.end() - - return { - props: {} - } -}