Option for seperated sitemaps?

Krystus
43
Krystus
commented 2 years ago

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.?

idea
0
NicoPennec
1.4k
NicoPennec
commented 2 years ago

Indeed, for now you can't.
I will start working on this feature, it will be a useful enhancement.

thks for your feedback!

6
martinrisseeuw
3
martinrisseeuw
commented a year ago

What is the status of this feature? It would be great to have for multi-regional & multi-lang projects.

0
mike-rotate
0
mike-rotate
commented a year ago

In the same situation as @martinrisseeuw currently, is there any feature/roadmap status on this one? Thanks!

0
desaintflorent
0
desaintflorent
commented a year ago

Same here, also interested by this feature ! Is it planed soon ?

0
antimodern
0
antimodern
commented 8 months ago

Without this feature this module is only suited for landing pages

0
manniL
5.8k
manniL
commented 8 months ago

Don't forget that the code is right in front of you. πŸ˜‰

0
antimodern
0
antimodern
commented 8 months ago

@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!

0
manniL
5.8k
manniL
commented 8 months ago

@antimodern There is already a PR (#26) by the way ☺️

0
antimodern
0
antimodern
commented 8 months ago

@manniL oh, this is cool. Will check out, thanks. Multiple sitemaps is crucial for hardcore SEO, like Images, Video, News sitemaps.

0
amjadkhan896
0
amjadkhan896
commented 7 months ago

Is this feature completed? I also need it.

0
vrusua
0
vrusua
commented 5 months ago

It will be very useful for multi-lang projects. Is this completed, or?

0
kaboume
13
kaboume
commented 4 months ago

+1

0
shavidzet
0
shavidzet
commented 4 months ago

This feature is very useful and sitemap is one of the most important feature for SEO, without splitting chunks I'm not sure why I should use it πŸ‘Ž

Does someone work on this feature?

0
miteyema
0
miteyema
commented 3 months ago

@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?

0
gokhancetiner
0
gokhancetiner
commented 3 months ago

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,

0
Moonsownner
0
Moonsownner
commented 2 months ago

Please finish this issue before close it!

0
dseeker
0
dseeker
commented a month ago

I'm serving multiple domains on the same Nuxt instance, the ability to have multiple sitemaps is really needed for my use case as well. any updates on this?
how can we help move this feature forward?

0
vrusua
0
vrusua
commented 15 days ago

Hi guys, can you please share any roadmap regarding this feature? Thanks a lot.

0
shavidzet
0
shavidzet
commented 14 days ago

@vrusua I highly recommend to use https://github.com/ekalinin/sitemap.js and do some tasks manually before someone fixes this.

0
papakay
0
papakay
commented 13 days ago

@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.

0
NicoPennec
1.4k
NicoPennec
commented 12 days ago

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:

  1. Do you need a sitemapindex to index your separated sitemaps?
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>
  1. Do you need separeted sitemaps by hostname ? (eg. for multi-lang)

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. πŸ˜‰

0
desaintflorent
0
desaintflorent
commented 11 days ago

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 ?

0
vrusua
0
vrusua
commented 11 days ago

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

0
shavidzet
0
shavidzet
commented 11 days ago

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

To have dynamic sitemap data based on API, you should re-deploy app after data changes in DB

0
Informations
Feature Request β€’ Open
#c5 - Created 2 years ago