-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nuxt 2.13.0 compatibility (nuxt static export) #143
Comments
haha I was just going to request the same feature 😄 At first I didn't want to use the crawler because I assumed it would increase the build time. But actually there is no difference, at least in my case. So I removed my routes and let the crawler do the job, but then I realised that my sitemap was now empty. Of course, I could still query the routes for the sitemap, but it would be awesome if the sitemap module could simply take the routes crawled by the Nuxt crawler. |
Yes please! This would be an awesome feature actually... |
For fully static Nuxt websites hosted on Netlify, this build plugin could also be a viable solution: https://github.com/netlify-labs/netlify-plugin-sitemap |
Woah! Didn't know about that one! Thank you! |
This will be super great!!! |
It would be great. Would save us from the pain of generating the routes manually |
How is this feature going? |
i18n: {
locales: [
{ name: '简体中文', code: 'zh', iso: 'zh-CN', file: 'zh.js' },
{ name: 'English', code: 'en', iso: 'en-US', file: 'en.js' }
],
strategy: 'prefix',
rootRedirect: 'zh',
defaultLocale: 'zh',
lazy: true,
langDir: 'i18n/',
seo: true,
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected'
},
vueI18n: {
fallbackLocale: 'zh'
}
},
sitemap: {
hostname: 'https://hanzi.press',
i18n: true
} sitemap generated: <?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>https://hanzi.press/about</loc>
</url>
<url>
<loc>https://hanzi.press/ar</loc>
</url>
<url>
<loc>https://hanzi.press/card</loc>
</url>
<url>
<loc>https://hanzi.press/story</loc>
</url>
<url>
<loc>https://hanzi.press/surround</loc>
</url>
<url>
<loc>https://hanzi.press/</loc>
</url>
</urlset> i have no idea whether it's about nuxt v2.13.0 |
Would love this to work with |
Second this! Although as a Netlify user, @mornir's comment about https://github.com/netlify-labs/netlify-plugin-sitemap seems to do the trick for now :) |
Until that's implemented, if you're not using Netlify and your requirements are modest, you could add this to your nuxt.config.js: //nuxt.config.js
import fs from 'fs'
import path from 'path'
export default {
hooks: {
generate: {
done: (generator) => {
const hostname = 'https://pinkyandthebrain.com' // Your hostname
// Array of regular expressions to exclude routes. If you don't need to exclude anything, just use an empty array
const exclusionRegExps = ['\/admin\/.+', '\/secrets.*', 'planstotakeovertheworld']
const sitemapFilePath = path.join(
generator.nuxt.options.generate.dir,
'sitemap.xml' // Customise sitemap name here
)
const filteredRoutes = Array.from(generator.generatedRoutes).filter((route) => {
return exclusionRegExps.some(rule => RegExp(rule).test(route)) ? false : true
})
const urlElements = filteredRoutes.map(route => {
return `<url><loc>${hostname}${route}</loc></url>`
})
const template = `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">${urlElements.join('')}</urlset>`
fs.writeFileSync(sitemapFilePath, template)
}
}
}
} Caveats
ProsIt doesn't get any simpler than this, so it should be easy for anyone to customise 😉 |
@timbenniks also wrote a blog post about it: https://timbenniks.dev/writings/easy-dynamic-routes-in-your-nuxt-sitemap/ |
@mornir thanks for the mention. It should indeed not be too complex to add my approach to the module. However, I don't know about its internals and potentially there is quite a bit to consider. Like multiple sitemaps etc. |
@mornir Thanks for that! I just implemented it, but I realized you can use the default sitemap option |
I tired making a PR for this, but kept getting Git commit issues. Never done a PR to an OSS project before. Oh well I give up. So frustrating what has become of frontend DX these days. Pretty sure this is the solution if someone wants to make a PR. Will need to add /lib/module.js:
|
Thank you all for your suggestions! I know this feature is eagerly awaited. I just published a PR to handle the new static mode directly in the sitemap module. $ npm install nuxt-community/sitemap-module#feat/static-crawler Your test results and feedbacks would be really appreciated before to release it? 🙏 |
@NicoPennec Thanks for implementing this feature! It works great. |
@NicoPennec very nice! In my case it also works great. |
@NicoPennec that's really cool, worked well on my side too. |
@NicoPennec thank you for the amazing work. What is missing to be merged? 😃 |
@NicoPennec does the feature respect the exclude option? I couldn't make exclude work on routes generated with the crawler. |
@Velikolay as there is a new test added without a crawler and the old one still tests with an exclude I would say, yes it is expected to work. |
not compatible to @nuxt/content-theme-docs nuxt config: import theme from '@nuxt/content-theme-docs';
export default theme({
loading: { color: '#00CD81' },
i18n: {
locales: () => [
{
code: 'zh',
iso: 'zh-CN',
file: 'zh-CN.js',
name: '简体中文'
}
],
defaultLocale: 'zh'
},
buildModules: ['@nuxtjs/google-analytics', '@nuxtjs/google-adsense', '@nuxtjs/sitemap'],
content: {
liveEdit: false
},
components: true,
pwa: {
manifest: {
name: 'RxJS教程'
}
},
googleAnalytics: {
id: 'UA-33096931-4'
},
'google-adsense': {
id: 'ca-pub-5059418763237956',
pageLevelAds: true
},
sitemap: {
hostname: 'https://rx.js.cool'
}
}); result: https://rx.js.cool/sitemap.xml <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>https://rx.js.cool/</loc>
</url>
<url>
<loc>https://rx.js.cool/releases</loc>
</url>
</urlset> |
Hoping this PR gets released soon. Its a must for larger static websites. |
+1 ps. Feature works great on nuxt 2.15.4 with content, i18n, 6 level deep urls, 200+ pages. |
I'd like to know this as well. |
is is for static or work by ssr? also which version of nuxt? |
I gave up trying to get the crawler feature working, wasted 1-2 hours with this module then found a chrome extension that could generate a sitemap for SPAs with zero configuration - Sitemap Generator When it finishes crawling save the sitemap.xml and move it your /static folder. When you run |
Is there any update on this and when will this be merged? Would be great to have that. |
What problem does this feature solve?
It would be nice if the sitemap automatically generate routes in combination with the Nuxt
static
optionThe text was updated successfully, but these errors were encountered: