Do I miss something or right now module allow me to make only one sitemap.xml and I can't create separated sitemaps for example for users, pages, products etc.?
What is the status of this feature? It would be great to have for multi-regional & multi-lang projects.
In the same situation as @martinrisseeuw currently, is there any feature/roadmap status on this one? Thanks!
Same here, also interested by this feature ! Is it planed soon ?
Without this feature this module is only suited for landing pages
@manniL you are absolutely right. I will check out how to achieve it with original package first, then will see what can we do with Nuxt module. And thanks for your contributions!
@manniL oh, this is cool. Will check out, thanks. Multiple sitemaps is crucial for hardcore SEO, like Images, Video, News sitemaps.
@manniL @shavidzet @amjadkhan896 It seems that the PR https://github.com/nuxt-community/sitemap-module/pull/26 has been closed, so I would also like to know if there still is work going on for this feature?
Can you give us an update @NicoPennec?
Hello guys,
Thanks for this great module.
Is there any update on this issue or do you have any date to finish it?
Many Thanks,
@vrusua I highly recommend to use https://github.com/ekalinin/sitemap.js and do some tasks manually before someone fixes this.
@shavidzet thank you a lot for sharing this great resource. Please any idea of how I can add this to a nuxt project? Thank you.
Hello everyone!
and a big thank for your interest in the sitemap module.
I'm really sorry for the delay of my answers so far, but it should be better now π
I started refactoring the module to support multiple sitemaps, without introducing breaking changes (if possible π€).
For now I have some questions to finalize the feature:
sitemap: {
path: "/sitemapindex.xml",
sitemaps: [
{ path: "/sitemap-products.xml", routes: [...], ... },
{ path: "/sitemap-news.xml", routes: [...], ... },
]
}
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://example.com/sitemap-products.xml</loc>
<lastmod>2019-08-30</lastmod>
</sitemap>
<sitemap>
<loc>https://example.com/sitemap-news.xml</loc>
<lastmod>2019-09-05</lastmod>
</sitemap>
</sitemapindex>
eg. without resolver
sitemap: [
{ hostname: "https://example.com", path: "/sitemap-en.xml", routes: [...], ... },
{ hostname: "https://example.fr", path: "/sitemap-fr.xml", routes: [...], ... },
}
eg. with a custom resolver (that will check the current request headers for example)
sitemap: [
{ hostname: "https://example.com", path: "/sitemap.xml", routes: [...], resolver: (req) => req.headers.host === "example.com", ... },
{ hostname: "https://example.fr", path: "/sitemap.xml", routes: [...], , resolver: (req) => req.headers.host === "example.fr", ... },
}
notice:
If you have more concrete use cases of separate sitemaps, please share any dummy example of expected configuration for your nuxt.config.js
. π
Hello, @NicoPennec it's good this see this feature not forgotten !
In my case I would be in the 1. case
.
Do you think it could be possible to generate separated sitemaps dynamically ?
In my case I would need a separate sitemap for each city of my country with business shops registered in my db. I would get that from an api.
So the list would grow automatically and I would only use one sitemapindex.xml listing all sitemaps generated from cities with business shops.
Exemple of sitemapindex.xml
<sitemap>
<loc>https://domain.com/sitemap/city-1.xml</loc>
<lastmod>2019-08-21 09:28:37</lastmod>
</sitemap>
<sitemap>
<loc>https://domain.com/sitemap/city-2.xml</loc>
<lastmod>2019-08-20 20:24:08</lastmod>
</sitemap>
[...]
<sitemap>
<loc>https://domain.com/sitemap/city-n.xml</loc>
<lastmod>2019-08-20 20:24:08</lastmod>
</sitemap>
Exemple of Sitemap for city 1
https://domain.com/sitemap/city-1.xml
<url>
<loc>
https://domain.com/city-1/businessname
</loc>
<changefreq>weekly</changefreq>
</url>
<url>
<loc>
https://www.domain.com/city-1/businessname2
</loc>
<changefreq>weekly</changefreq>
</url>
Would love to know if that's possible.
In your previous post, you are talking about hard coding each sitemap in the nuxt.config.js
am I right ?
Hi, @NicoPennec,
thanks for the update that this task in on board!
My current sitemaps are more related to the 2nd point without resolver (grouped multiple lang routes). However, the additional option with the resolver will be great to have too.
The 1st point (indexed sitemaps) is awesome also to have as an option in further.
Thank you.
Cheers,
Ruslan
My solution:
server/index.js
(() => {
require('dotenv').config({
path: process.env.ENV_PATH || '.env'
})
})()
const express = require('express')
const consola = require('consola')
const { Nuxt, Builder } = require('nuxt')
const app = express()
const esmModulesRequire = require('esm')(module)
const generateSitemap = esmModulesRequire('../sitemap/index').default
// Import and Set Nuxt.js options
const config = require('../nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')
async function start() {
// Init Nuxt.js
const nuxt = new Nuxt(config)
const { host, port } = nuxt.options.server
generateSitemap()
app.use(express.static('sitemap/files'))
// Build only in dev mode
if (config.dev) {
const builder = new Builder(nuxt)
await builder.build()
} else {
await nuxt.ready()
}
// Give nuxt middleware to express
app.use(nuxt.render)
// Listen the server
app.listen(port, host)
consola.ready({
message: `Server listening on http://${host}:${port}`,
badge: true
})
}
start()
sitemap/index.js
import fs from 'fs'
import { format } from 'date-fns'
import mkdirp from 'mkdirp'
import sm from 'sitemap'
import api from '../api'
import { locales } from '../lang'
api.lang = 'en'
const routes = async () => {
const { places } = await api.fetchPlaces()
const placeNames = places
.map(({ name }) => {
return places.reduce((state, item) => {
const newArr = name === item.name ? [] : [`from-${name}-to-${item.name}`]
return [
...state,
...newArr
]
}, [])
})
return [
...placeNames
]
}
const getHostname = () => {
const protocol = process.env.PROTOCOL
const hostname = process.env.HOST
const port = process.env.PORT || ''
const fullUrl = `${protocol}://${hostname}:${port}`
return port
? fullUrl
: fullUrl.slice(0, -1) // remove :
}
const generateUrls = async (lang) => {
const allRoutes = await routes()
const { tours: allTours } = (await api.fetchTours()).data
const flatRoutes = allRoutes
.reduce((state, route) => {
return [
...state,
...route
]
}, [])
const placeRoutes = flatRoutes.map(route => ({
url: `/${lang}/trip-planner?routes=${route}`,
changefreq: 'daily',
priority: 0.8,
lastmod: format(new Date(), 'YYYY-MM-DD')
}))
const tours = allTours.map(({ id }) => ({
url: `/${lang}/tour-detail/${id}`,
changefreq: 'daily',
priority: 0.8,
lastmod: format(new Date(), 'YYYY-MM-DD')
}))
const urls = [
{
url: `/${lang}/`,
changefreq: 'daily',
priority: 0.8,
lastmod: format(new Date(), 'YYYY-MM-DD')
},
{
url: `/${lang}/trip-planner`,
changefreq: 'daily',
priority: 0.8,
lastmod: format(new Date(), 'YYYY-MM-DD')
},
{
url: `/${lang}/tours`,
changefreq: 'daily',
priority: 0.8,
lastmod: format(new Date(), 'YYYY-MM-DD')
},
{
url: `/${lang}/transfer`,
changefreq: 'daily',
priority: 0.8,
lastmod: format(new Date(), 'YYYY-MM-DD')
},
{
url: `/${lang}/contact`,
changefreq: 'daily',
priority: 0.8,
lastmod: format(new Date(), 'YYYY-MM-DD')
},
...tours,
...placeRoutes
]
return urls
}
const generateSitemap = () => {
locales.forEach(({ code }) => {
const path = `./sitemap/files/${code}`
mkdirp(path, async (err) => {
if (err) {
throw err
}
const sitemap = sm.createSitemap({
hostname: getHostname(),
cacheTime: 600000,
urls: await generateUrls(code)
})
fs.writeFileSync(`${path}/sitemap.xml`, sitemap.toString())
})
})
}
export default generateSitemap
Thank you for your answers!
It helps to move in the right direction π
I made good progress on the feature:
<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked> sitemapindex
<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked> universal mode
<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked> generate mode
<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked> add Jest test
<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked> add config on README
<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked> multiple sitemap (without resolver)
<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked> universal mode
<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked> generate mode
<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked> add Jest test
<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked> add config on README
The branch will be publish soon so you can test.
The release 2.0.0 has just been published with the mutliple sitemaps and the sitemap index.
@desaintflorent
the "autosplit" feadure is planned for the next release.
you can follow or discuss about this request on issue #79.
Indeed, for now you can't.
I will start working on this feature, it will be a useful enhancement.
thks for your feedback!