I am generating the sitemap.xml for my Nuxt 3 based Nuxt Content website pages and everything works fine and able to get the correct sitemap after running the npm run generate or nuxt generate. However I am unable to add the default value for lastmod for dynamically created routes. I have created a sample re-production in CodeSandBox.
My /content/imprint/index.md file looks like this:
As we can see since I defined the lastmod for my imprint/index.md page I got the lastmod for only for that URL but for all the tags or dynamic routes which get created in the sitemap.xml it does not get the lastmod or changeFreq added by default to it.
I want to know how can I add the default lastmod value to all the dynamic tags routes during the generation of the sitemap.xml? If present from the file then add it directly if not then add the lastest or current date time lastmod: new Date(),
But this did not make any difference and I did not get the lastmod for the /tags. How to ensure if the lastmod to be added for all the URLS generated in sitemap.xml including the dynamic routes?
Following is my nuxt.config.js:
Click to toggle contents of `nuxt.config.js`
```
export default {
compatibilityDate: "2024-08-31",
modules: [
"@nuxtjs/tailwindcss",
"unplugin-fonts/nuxt",
"@nuxtjs/i18n",
"@nuxtjs/color-mode",
"@nuxt/image",
"@nuxt/content",
"@nuxtjs/sitemap",
],
ssr: true,
target: 'static',
site: {
url: process.env.BASE_URL || 'http://localhost:3000/',
name: "Test Application",
trailingSlash: true,
defaults: {
changefreq: "daily",
priority: 1,
lastmod: new Date(),
},
},
//To support and display the .md files from /content using @nuxt/content
content: {
// To highlight the code sections using the theme
highlight: {
theme: {
default: "aurora-x",
dark: "everforest-dark",
sepia: "monokai",
},
langs: ["json", "xml", "java", "shell"],
},
markdown: {
remarkPlugins: ["remark-reading-time"], //To get the reading time for each .md file in /content
anchorLinks: false, // Do not underline and highlight the h2, h3, h4 etc
}
},
//To support the dark/light mode theme using @nuxtjs/color-mode
colorMode: {
classSuffix: "",
preference: "system",
fallback: "dark",
},
app: {
head: {
link: [
{
rel: "icon",
type: "image/x-icon",
href: `/img/favicon.ico`,
},
],
},
},
buildModules: [
{
vue: {
config: {
assetDirs: ["assets", "public"],
},
},
},
],
runtimeConfig: {
apiSecret: "123",
public: {},
},
components: [
{
path: "~/components",
pathPrefix: false,
},
],
build: {
postcss: {
postcssOptions: {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
},
},
},
i18n: {
locales: [
{
code: "en",
files: ["en.json", "en-extended.json"],
},
],
lazy: true,
langDir: "./locales",
defaultLocale: "en",
},
plugins: [{ src: "@/plugins/aos", ssr: false, mode: "client" }],
};
```
đ What have you tried?
I tried couple of things already:
sitemap: {
hostname: process.env.NUXT_PUBLIC_SITE_URL,
trailingSlash: true,
lastmod: new Date(),
defaults: {
lastmod: new Date()
}
},
đ What are you trying to do?
I am generating the
sitemap.xml
for myNuxt 3
basedNuxt Content
website pages and everything works fine and able to get the correct sitemap after running thenpm run generate or nuxt generate
. However I am unable to add the default value forlastmod
for dynamically created routes. I have created a sample re-production in CodeSandBox.My
/content/imprint/index.md
file looks like this:And I get the following information within my
sitemap.xml
like this:As we can see since I defined the
lastmod
for myimprint/index.md
page I got thelastmod
for only for thatURL
but for all the tags or dynamic routes which get created in thesitemap.xml
it does not get thelastmod
orchangeFreq
added by default to it.I want to know how can I add the default
lastmod
value to all the dynamictags
routes during the generation of thesitemap.xml
? If present from the file then add it directly if not then add the lastest or current date timelastmod: new Date(),
I tried to add the defaults to my
nuxt.config.js
:But this did not make any difference and I did not get the
lastmod
for the/tags
. How to ensure if thelastmod
to be added for all theURLS
generated insitemap.xml
including the dynamic routes?Following is my
nuxt.config.js
:Click to toggle contents of `nuxt.config.js`
``` export default { compatibilityDate: "2024-08-31", modules: [ "@nuxtjs/tailwindcss", "unplugin-fonts/nuxt", "@nuxtjs/i18n", "@nuxtjs/color-mode", "@nuxt/image", "@nuxt/content", "@nuxtjs/sitemap", ], ssr: true, target: 'static', site: { url: process.env.BASE_URL || 'http://localhost:3000/', name: "Test Application", trailingSlash: true, defaults: { changefreq: "daily", priority: 1, lastmod: new Date(), }, }, //To support and display the .md files from /content using @nuxt/content content: { // To highlight the code sections using the theme highlight: { theme: { default: "aurora-x", dark: "everforest-dark", sepia: "monokai", }, langs: ["json", "xml", "java", "shell"], }, markdown: { remarkPlugins: ["remark-reading-time"], //To get the reading time for each .md file in /content anchorLinks: false, // Do not underline and highlight the h2, h3, h4 etc } }, //To support the dark/light mode theme using @nuxtjs/color-mode colorMode: { classSuffix: "", preference: "system", fallback: "dark", }, app: { head: { link: [ { rel: "icon", type: "image/x-icon", href: `/img/favicon.ico`, }, ], }, }, buildModules: [ { vue: { config: { assetDirs: ["assets", "public"], }, }, }, ], runtimeConfig: { apiSecret: "123", public: {}, }, components: [ { path: "~/components", pathPrefix: false, }, ], build: { postcss: { postcssOptions: { plugins: { tailwindcss: {}, autoprefixer: {}, }, }, }, }, i18n: { locales: [ { code: "en", files: ["en.json", "en-extended.json"], }, ], lazy: true, langDir: "./locales", defaultLocale: "en", }, plugins: [{ src: "@/plugins/aos", ssr: false, mode: "client" }], }; ```đ What have you tried?
I tried couple of things already:
Also added custom routes logic:
I did not get even console.log when generating the sitemap:
I have created a sample re-production in CodeSandBox.
âšī¸ Additional context
No response