Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stovv/next-strapi-sitemap
Generate sitemap and robots.txt for NextJS used web hook from STRAPI
https://github.com/stovv/next-strapi-sitemap
nextjs robots-txt sitemap strapi
Last synced: 3 months ago
JSON representation
Generate sitemap and robots.txt for NextJS used web hook from STRAPI
- Host: GitHub
- URL: https://github.com/stovv/next-strapi-sitemap
- Owner: stovv
- Created: 2021-01-19T19:11:30.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-19T20:07:39.000Z (almost 4 years ago)
- Last Synced: 2024-08-01T00:38:43.055Z (6 months ago)
- Topics: nextjs, robots-txt, sitemap, strapi
- Language: JavaScript
- Homepage:
- Size: 82 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
- awesome-nextjs - Sitemap generator for NextJS & StrAPI - 🦾 An additional server on express that runs alongside nextjs and regenerates sitemap ( with index sitemap ) and robots.txt files on request from STR API. (Boilerplates)
- fucking-awesome-nextjs - Sitemap generator for NextJS & StrAPI - 🦾 An additional server on express that runs alongside nextjs and regenerates sitemap ( with index sitemap ) and robots.txt files on request from STR API. (Boilerplates)
README
# SiteMap and Robots.txt generator for NextJS with STR API
## Getting started
1. Clone into `scripts` folder into nextjs project
```bash
cd
git clone https://github.com/stovv/next-strapi-sitemap.git scripts
```
2. Install dependencies
```bash
cd /scripts
# if you use yarn
yarn install
# if you use npm
# npm install
```
3. Update start command in package.json
```json
{
"name": "project name",
...
"start": "next start & cd scripts;node sitemap-generator.js"
}
```
4. Create `.env` file by example in `.env.example`
```dotenv
# port for sitemap generator server
PORT=
# host name of site for sitemap generate
# e.g https://sitename.com
HOST=
# host name for your strapi instanse
# e.g https://strapi.sitename.com
BACKEND_HOST=
# a secret token that will be transmitted to the generator to check the adequacy of the call
WEBHOOK_TOKEN=
```
6. Generate webhook token
You can use services like this https://www.random.org/strings/
7. Go to your strapi admin panel
1. Open admin/settings/webhooks
2. Click to `Create New Webhook` button
3. Fill
- Name
- URL = http://localhost:
4. Add Header
- Key = Authorization
- Value = your generated webhook token from 6 step
5. Select all action on entry (create, update, delete)
![webhook example](img/webhook_configuration.png)
8. Update `next.config.js` for initial generate sitemaps and robots on `next build`
```javascript
// next.config.js
const withPlugins = require('next-compose-plugins');
module.exports = withPlugins(
[ ],
{
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
if (isServer){
// Generate sitemaps and robots.txt
const { generate } = require('./scripts/generate-sitemap');
generate(
// Public host name for sitemap generation
'https://sitename.ru',
// subfolder for generated sitemaps (not index sitemap) in public folder
'sitemaps',
// folder for generated sitemaps and robots.txt
'./public',
// disallow routes in robots.txt
['/api/', '/login']
);
}
return config;
}
}
);
```
9. Start your project by `yarn start` or `npm run start`---
### Enjoy! 🤘