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: {} - } -}