Feature request: add last modification date

derevandal
50
derevandal
commented 5 months ago

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

idea
0
manniL
5.1k
manniL
commented 5 months ago

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.

0
manniL
5.1k
manniL
commented 5 months ago

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

Overlaps with #15

0
NicoPennec
1.3k
NicoPennec
commented 5 months ago

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

0
derevandal
50
derevandal
commented 4 months ago

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

0
NicoPennec
1.3k
NicoPennec
commented 4 months ago

@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
      })
    }
0
Informations
Feature Request โ€ข Open
#c39 - Created 5 months ago