From a2d53bcb7701096a10fb38f188752807a8c0f98a Mon Sep 17 00:00:00 2001 From: Vishnu Sankar Date: Mon, 3 Aug 2020 00:35:16 +0530 Subject: [PATCH] - Added documentation --- README.md | 38 ++++++++++++++++++-- example/{next.sitemap.js => next-sitemap.js} | 0 packages/next-sitemap/src/export/index.ts | 10 ++++-- packages/next-sitemap/src/index.ts | 2 -- packages/next-sitemap/src/path.ts | 2 +- 5 files changed, 45 insertions(+), 7 deletions(-) rename example/{next.sitemap.js => next-sitemap.js} (100%) diff --git a/README.md b/README.md index 6c114924..369336e0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,37 @@ -# fullstack-template +# next-sitemap -Fullstack project template +Sitemap generator for next.js + +## Install + +```shell +yarn add next-sitemap -D +``` + +## Create config file + +`next-sitemap` requires a basic config file (`next-sitemap.js`) under your project root + +```js +module.exports = { + siteUrl: 'https://example.com' + // other options +} +``` + +## Add next-sitemap as your postbuild script + +```json +{ + "build": "next build", + "postbuild": "next-sitemap" +} +``` + +## `next-sitemap.js` Options + +| property | description | +| --------------------- | ------------------------------------ | +| siteUrl | Base url of your website | +| changefreq (optional) | Change frequency. Default to `daily` | +| priority (optional) | Priority. Default to `0.7` | diff --git a/example/next.sitemap.js b/example/next-sitemap.js similarity index 100% rename from example/next.sitemap.js rename to example/next-sitemap.js diff --git a/packages/next-sitemap/src/export/index.ts b/packages/next-sitemap/src/export/index.ts index 1be9a61c..4f329009 100644 --- a/packages/next-sitemap/src/export/index.ts +++ b/packages/next-sitemap/src/export/index.ts @@ -1,5 +1,11 @@ import fs from 'fs' +import path from 'path' -export const exportSitemap = (path: string, xml: string) => { - fs.writeFileSync(path, xml) +export const exportSitemap = (filePath: string, xml: string) => { + const folder = path.dirname(filePath) + if (!fs.existsSync(folder)) { + fs.mkdirSync(folder) + } + + fs.writeFileSync(filePath, xml) } diff --git a/packages/next-sitemap/src/index.ts b/packages/next-sitemap/src/index.ts index 1cbd0092..7ec8f07a 100644 --- a/packages/next-sitemap/src/index.ts +++ b/packages/next-sitemap/src/index.ts @@ -11,6 +11,4 @@ const urlSet = createUrlSet(config, manifest) const sitemapPath = config.path const sitemapXml = buildSitemapXml(config, [...urlSet]) -console.log(sitemapPath) - exportSitemap(sitemapPath, sitemapXml) diff --git a/packages/next-sitemap/src/path.ts b/packages/next-sitemap/src/path.ts index 7adb03dd..b4a1789a 100644 --- a/packages/next-sitemap/src/path.ts +++ b/packages/next-sitemap/src/path.ts @@ -7,7 +7,7 @@ export const getPath = (rel: string) => { const allPath = { NEXT_MANIFEST: getPath('.next/build-manifest.json'), PRERENDER_MANIFEST: getPath('.next/prerender-manifest.json'), - CONFIG_FILE: getPath('next.sitemap.js') + CONFIG_FILE: getPath('next-sitemap.js') } export default allPath