Sitemap and XML suport out of the box

awronski
351
awronski
commented 3 years ago

Hi!

It would be great if nuxt supports xml format out of the box.

I know I can now use nuxt as middleware for the express. But what I love about nuxt that it just works without any configuration.

How I see it:
there would be xml folder

In xml folder we can create as many js files as we want.
Each file is mapped to one route as xml page.

For example
xml\sitemap.js would generate sitemap.xml
xml\merchants.js would generate merchants.xml (google shops format)
etc.

In each file there should be exported one function that takes context and return a promise
The promise returns xml data.

So nuxt should scan the folder, map the routes and set proper content-type when request come.

Guys, what do you thing about it?

0
Atinux
26.4k
Atinux
commented 3 years ago

Hi @awronski

Thank you for your idea, but we cannot implement it in the core of nuxt.js.

But we would love to see a plugin/module for it, called nuxt-sitemap for example which extend nuxt.render to check the url, and if the url match a file in the xml folder, then call the method, otherwise, call the original nuxt.render(req, res) method.

You can take a look at nuxt-helpers made by @pi0 who did a great job on it.

In the future we may introduce a feature to include nuxt modules directly inside the nuxt.config.js:

module.exports = {
  modules: ['nuxt-sitemap', 'nuxt-helpers/optimize']
}

The module will be called when nuxt instance will be created so the module can extend nuxt (by overwriting it's method or options).

2
awronski
351
awronski
commented 3 years ago

Thanks for the hint. I will look at the helpers.

It would ber great if you add modules to the config!

Thanks in advance,

On Fri, Mar 3, 2017 at 12:12 PM, Sébastien Chopin notifications@github.com
wrote:

Closed #337 https://github.com/nuxt/nuxt.js/issues/337.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/nuxt/nuxt.js/issues/337#event-985221134, or mute the
thread
https://github.com/notifications/unsubscribe-auth/AB4d3cia5rBd8i9oAoSFhj4r7390SluYks5rh_WogaJpZM4MSFbj
.

0
NicoPennec
1.4k
NicoPennec
commented 2 years ago

issue resolved 😄

  • Install module with npm (or yarn)
npm install @nuxtjs/sitemap
  • Configure module in nuxt.config.js
  modules: [
   '@nuxtjs/sitemap'
  ]

https://github.com/nuxt-community/modules/tree/master/modules/sitemap

9
pi0
31.7k
pi0
commented 2 years ago

@NicoPennec Thanks to your works sitemap would be a super useful thing for many Nuxt users. ❤️

I'm adding little more improvements. Will inform you making a final review before publish (Will be ready in ~1h). BTW Still two important decision remaining:

First, As of express section in docs they suggested creating a global sitemap instance shared across requests and updating it using dynamic capabilities, current approach that calling async generate routes for each request feels like a PHP approach (1 req - 1 complete process), However I still agree there should be a runtime method for updating sitemap. My suggestion is we could use something like an LRU cache with maxAge option. Whats your idea?

Second, while middleware are nice, they won't work for static generated sites, I will try to handle it supporting both methods like your first version :)

0
NicoPennec
1.4k
NicoPennec
commented 2 years ago

@pi0 yes, I have planned to manage a LRU cache. It should be the next release.
For the second topic, I never use the generate feature. Thanks for your help on this point :)

0
pi0
31.7k
pi0
commented 2 years ago

@NicoPennec I've pushed my changes (cache is added too sorry i was too exciting for that :P) please take a look and feel free making PR for changes. I will release alpha then. Also soon we separate some modules (including sitemap) into their own dedicated repo so then we could easily contribute.

0
awronski
351
awronski
commented 2 years ago

@pi0 I didn't see the push yet but just want to let you know that sitemap has a built cacheTime.
So it is working out of the box

0
pi0
31.7k
pi0
commented 2 years ago

@awronski cacheTime of sitemap is implemented too but we need additional care to evaluate routes promise not on every request.

0
MatthieuHPP
8
MatthieuHPP
commented 2 years ago

Many thanks for this work, this will ease the "sitemap" implementation I have to do :-).

1
ducdebreme
0
ducdebreme
commented 2 years ago

I followed the 2 steps on my Mac

  1. npm install @nuxtjs/sitemap
  2. modules: [ '@nuxtjs/sitemap' ]

But when I run

nuxt build
[nuxt] Building…
[nuxt] Unable to resolve module @nuxtjs/sitemap

I get an syntax error …
[SyntaxError: Unexpected token {]

I checked node_modules folder: the module has been installed.
The error goes away as soon as I remove the modules key from nuxt.config.js

0
andreliem
16
andreliem
commented 2 years ago

@ducdebreme I had the same issue, and it ended up being that I had to update my version of node.

0
NicoPennec
1.4k
NicoPennec
commented 2 years ago

@ducdebreme @andreliem
Which version of Node.js ?
Can you share your nuxt.config.js (sitemap part only) ?

From my side, it works fine with the following config:

  • Node.js v8.3.0
  • Nuxt v1.0.0 RC4
  • @nuxtjs/sitemap v0.0.3
0
ducdebreme
0
ducdebreme
commented 2 years ago

Mine is

0
NicoPennec
1.4k
NicoPennec
commented 2 years ago

@ducdebreme Node.js v5 doesn't support ES6 and in my sitemap module I use arrow function from ES6…

you can run your node.js with the ES6 flag => node --harmony
or
upgrade to Node.js v6 or V8 :-p

1
ducdebreme
0
ducdebreme
commented 2 years ago

Thanks Nico, I have updated to latest Node.js, Nuxt and sitemap, too.
Still need to try the sitemap …

0
MatthieuHPP
8
MatthieuHPP
commented 2 years ago

hello,

I have installed @nuxtjs/sitemap via npm and have referred it within the module part of the nuxt config file : modules: [ '@nuxtjs/sitemap' ].

Tools evaluating SEO say my web site does not have any sitemap.xml file.
What am I doing wrong ?

Nuxt is used in production, my versions are :
node 6.11.0
nuxt 1.0.0_alpha5
@nuxt/sitemap 0.0.3

Many thanks for your help

Matthieu

0
fabionolasco
0
fabionolasco
commented 2 years ago

Hi MatthieHPP, it worked for me.
I am using node 6.11.1.
Here is my github repo with the use case:
https://github.com/fabionolasco/fabionolasco.com

0
MatthieuHPP
8
MatthieuHPP
commented 2 years ago

Many thanks Narcisio. I'have added robots.txt in static folder and now
sitemap.xml is found by seo tools.
Have a nice day
Matthieu

Le 26 août 2017 00:46, "Fabio Nolasco" notifications@github.com a écrit :

Hi MatthieHPP, it worked for me.
I am using node 6.11.1.
Here is my github repo with the use case:
https://github.com/fabionolasco/fabionolasco.com


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/nuxt/nuxt.js/issues/337#issuecomment-325050379, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AXMGW_yF3MX2kbtTNFOtKuJ9BeB-UwK_ks5sb07AgaJpZM4MSFbj
.

0
Informations
QuestionUnresolved
#c287 - Created 3 years ago