Skip to content

Commit

Permalink
- Added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
iamvishnusankar committed Aug 2, 2020
1 parent db1e7c7 commit a2d53bc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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` |
File renamed without changes.
10 changes: 8 additions & 2 deletions packages/next-sitemap/src/export/index.ts
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 0 additions & 2 deletions packages/next-sitemap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ const urlSet = createUrlSet(config, manifest)
const sitemapPath = config.path
const sitemapXml = buildSitemapXml(config, [...urlSet])

console.log(sitemapPath)

exportSitemap(sitemapPath, sitemapXml)
2 changes: 1 addition & 1 deletion packages/next-sitemap/src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a2d53bc

Please sign in to comment.