Skip to content
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

Feature request: add last modification date #44

Closed
derevandal opened this issue Jan 30, 2019 — with CMTY · 5 comments

Comments

Projects
None yet
3 participants
Copy link
Contributor

commented Jan 30, 2019 — with CMTY

What problem does this feature solve?

Adding <lastmod>2019-01-23</lastmod> in a url tag, search engines will know how this content changed and when it was added and improve the pagerank.

What does the proposed changes look like?

I suggest to use fs.stat(path, [callback]) to read mtime stat of .vue's file or .md's (I wanna use to a blog system, so, it be helpfull this support) and write in sitemap.xml

This feature request is available on Nuxt community (#c39)

@cmty cmty bot added the cmty:feature-request label Jan 30, 2019

@manniL

This comment has been minimized.

Copy link
Member

commented Feb 7, 2019

Reading the mtime would be perfect for a situation like yours. As soon as you are using an API or similar you can't use that approach though.

Adding lastmod already works (see https://blog.lichter.io/sitemap.xml).

I'd leave the implementation up the user.

@manniL manniL closed this Feb 7, 2019

@manniL

This comment has been minimized.

Copy link
Member

commented Feb 7, 2019

Ah, but there should be a neat way for "static" URLs to provide that, right.

Overlaps with #15

@manniL manniL reopened this Feb 7, 2019

@NicoPennec

This comment has been minimized.

Copy link
Member

commented Feb 7, 2019

@derevandal the sitemap npm lib behind the sitemap-module offers this feature with the lastmodfile option.

 { url: '/page1', lastmodrealtime: true, lastmodfile: 'pages/page1.vue' },
 { url: '/page2', lastmodrealtime: true, lastmodfile: 'data/page2.md' },

see https://github.com/ekalinin/sitemap.js#example-of-pre-generating-sitemap-based-on-existing-static-files

But I never try it I just tried it, it works fine 👍

Let me know if it meets your needs.

@NicoPennec NicoPennec closed this Feb 14, 2019

@derevandal

This comment has been minimized.

Copy link
Contributor Author

commented Feb 14, 2019

@NicoPennec is there a way to make this automatically?
Should I user filter option?
Thanks <3

@NicoPennec

This comment has been minimized.

Copy link
Member

commented Feb 15, 2019

@derevandal It depends on your need.

If you targeting only dynamic routes, on your sitemap config your can set it directly.

eg.

    routes() {
      const products = ... // fetch your data from anywhere (API, JSON, static file, ...)
      return products.map(product => ({
        url: `/product/${product.slug}`,
        lastmodfile: `data/${product.slug}.md`,
        lastmodrealtime: true
      }))
    }

If you have static routes to process, the filter option is the way to do it. This is a perfect use case for this option, because it will be your own function to readjust your custom routes declarations.

eg.

    filter({ routes }) {
      return routes.map(route => {
        // eg. url = '/product/product-id-1' with the *.md source file = ./data/product-id-1.md
        const slug = route.url.replace('/product/', '')
        route.lastmodfile =  `data/${slug}.md`
        route.lastmodrealtime = true
      })
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.