Skip to content

Commit f0365d2

Browse files
oemuellerNicoPennec
authored andcommittedJun 25, 2020
feat: add hooks on sitemap generation
1 parent b6d79c8 commit f0365d2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
 

‎README.md

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- [Sitemap Options](#sitemap-options)
3030
- [Sitemap Index Options](#sitemap-index-options)
3131
- [Routes Declaration](#routes-declaration)
32+
- [Hooks](#hooks)
3233

3334
## Installation
3435

@@ -591,6 +592,18 @@ const axios = require('axios')
591592
}
592593
```
593594

595+
596+
## Hooks
597+
598+
Hooks are listeners to Nuxt events. [Learn more](https://nuxtjs.org/api/configuration-hooks)
599+
600+
You can register hooks on certain life cycle events.
601+
602+
| Hook | Arguments | When |
603+
|---|---|---|
604+
| sitemap:generate:before | (nuxt, sitemapOptions) | Hook on before site generation |
605+
| sitemap:generate:done | (nuxt) | Hook on sitemap generation finished |
606+
594607
## License
595608

596609
[MIT License](./LICENSE)

‎lib/module.js

+2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ module.exports = async function module(moduleOptions) {
3939

4040
// On "generate" mode, generate static files for each sitemap or sitemapindex
4141
nuxtInstance.nuxt.hook('generate:done', async () => {
42+
await nuxtInstance.nuxt.callHook('sitemap:generate:before', nuxtInstance, options)
4243
logger.info('Generating sitemaps')
4344
await Promise.all(options.map((options) => generateSitemaps(options, globalCache, nuxtInstance)))
45+
await nuxtInstance.nuxt.callHook('sitemap:generate:done', nuxtInstance)
4446
})
4547

4648
// On "ssr" mode, register middlewares for each sitemap or sitemapindex

0 commit comments

Comments
 (0)
Please sign in to comment.