Move sitemap script to app and adapt it
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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) => (
|
||||
`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>${url}</loc>
|
||||
<priority>1</priority>
|
||||
</url>
|
||||
<url>
|
||||
<loc>${url}/paroles</loc>
|
||||
<priority>0.9</priority>
|
||||
</url>
|
||||
<url>
|
||||
<loc>${url}/soutyen</loc>
|
||||
<priority>0.8</priority>
|
||||
</url>
|
||||
<url>
|
||||
<loc>${url}/awtis</loc>
|
||||
<priority>0.6</priority>
|
||||
</url>
|
||||
<url>
|
||||
<loc>${url}/soumet</loc>
|
||||
<priority>0.5</priority>
|
||||
</url>
|
||||
${teksSlug
|
||||
.map(slug => `
|
||||
<url>
|
||||
<loc>${`${url}/paroles/${slug}`}</loc>
|
||||
</url>
|
||||
`)
|
||||
.join('')}
|
||||
${awtisSlug
|
||||
.map(slug => `
|
||||
<url>
|
||||
<loc>${`${url}/awtis/${slug}`}</loc>
|
||||
</url>
|
||||
`)
|
||||
.join('')}
|
||||
</urlset>
|
||||
`
|
||||
)
|
||||
|
||||
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: {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user