Skip to content

Commit

Permalink
docs(readme): add usage guide and more
Browse files Browse the repository at this point in the history
  • Loading branch information
CBW2007 committed Mar 12, 2021
1 parent 698d06e commit 2d1be0c
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,83 @@
# sitemap-manager
An easy way to create sitemaps!

## Features
Quick, Fast, And Beautiful!

## Usage
First run

```shell
$ npm i sitemap-manager --save
or
$ yarn add sitemap-manager
```

Then just try it:

```js
const { CreateSitemap, CreateIndexSitemap, CreateSitemapStylesheet } = require('sitemap-manager')
const data = {/* data here */} //see more in scripts/test.js
const siteURL = data.site.siteMetadata.siteUrl
const pathPrefix = '/aaa/'

// Create Sitemaps for each kind of pages.
CreateSitemap(
path.resolve('./public/sitemap-articles.xml'), // The path of the file which will be generated.
pathPrefix, // Prefix of the path. If your site doesn't at the root of the domain,just try this.
// Example:
// given path: /foo/
// handled path: /aaa/foo/
siteURL, // The domain of your site.
data.postsQuery.edges, // Your data, shoud be an array
(data) => { return data.node.fields.slug }, // How to turn the data to a path
)
CreateSitemap(
path.resolve('./public/sitemap-logs.xml'),
pathPrefix,
siteURL,
data.postsQuery.edges,
(data) => { return data.node.fields.slug + 'changelog/' },
)
CreateSitemap(
path.resolve('./public/sitemap-tags.xml'),
pathPrefix,
siteURL,
data.tagsQuery.group,
(data) => { return `/tags/${data.fieldValue}/` },
)
CreateSitemap(
path.resolve('./public/sitemap-pages.xml'),
pathPrefix,
siteURL,
['/pages/', '/settings/'],
(data) => { return data },
)
// Create an index for all sitemaps.
CreateIndexSitemap(
path.resolve('./public/sitemap.xml'), // The path of the file which will be generated.
pathPrefix, // Prefix of the path. If your site doesn't at the root of the domain,just try this.
siteURL, // The domain of your site.
['sitemap-pages.xml', 'sitemap-articles.xml', 'sitemap-logs.xml', 'sitemap-tags.xml'], // All the sitemaps should be here.
)
// Create the xml template file.
// !IMPORTANT
// Should be at the same dir as any other sitemaps.
// E.g.
// |
// \
// aaa
// | sitemap.xml
// | sitemap.xsl
// | sitemap-artcles.xml
// | sitemap-logs.xml
// ...
CreateSitemapStylesheet(
path.resolve('./public/sitemap.xsl'), // The path of the file which will be generated.
pathPrefix, // Prefix of the path. If your site doesn't at the root of the domain,just try this.
siteURL, // The domain of your site.
)
```

## LICENSE
MIT

0 comments on commit 2d1be0c

Please sign in to comment.