Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #12

Merged
merged 10 commits into from Sep 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Deployed apps should consider commenting this line out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules
node_modules
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mocha=node_modules/.bin/mocha --reporter spec

node_modules: package.json
@npm install

test: node_modules
@$(mocha)

.PHONY: test
134 changes: 105 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,110 @@
metalsmith-sitemap
==========================
This provides a [metalsmith](http://www.metalsmith.io/) plugin to generate a sitemap according to the
[Sitemaps Protocol](http://www.sitemaps.org/protocol.html). There are four pieces of information possible for on any page.
The URL of the page (loc), the last modified date (lastmod), the change frequency (changefreq) and the priority. loc is
the only value that is required.

###Options
# metalsmith-sitemap

> A metalsmith plugin for generating a sitemap

This plugin allows you to generate a [sitemap.xml](http://www.sitemaps.org/protocol.html) from your source files. By default it looks for any `.html` files and processes them with [sitemap.js](https://github.com/ekalinin/sitemap.js).

## Installation

```bash
$ npm install metalsmith-sitemap
```
var Sitemap = require('metalsmith-sitemap');

Sitemap({
ignoreFiles: [/test.xml/], // Matched files will be ignored
output: 'sitemap.xml', // The location where the final sitemap should be placed
urlProperty: 'seo.canonical', // Key for URL property
hostname: 'http://www.metalsmith.io', // hostname to use for URL, if needed
modifiedProperty: 'modified', // Key for last modified property
defaults: { // You can provide default values for any property in here
priority: 0.5,
changefreq: 'daily'

## Example

Configuration in `metalsmith.json`:

```json
{
"plugins": {
"metalsmith-sitemap": {
"hostname": "http://www.website.com"
}
})
}
}
```

## Options

You can pass options to `metalsmith-sitemap` with the [Javascript API](https://github.com/segmentio/metalsmith#api) or [CLI](https://github.com/segmentio/metalsmith#cli). The options are:

##### hostname

* `required`

The hostname used for generating the urls.

##### changefreq

* `optional`
* `default: weekly`

Change the default [changefreq](http://www.sitemaps.org/protocol.html).

##### pattern

* `optional`
* `default: '**/*.html'`

A [multimatch](https://github.com/sindresorhus/multimatch) pattern. Only files that match this pattern will be included in the sitemap. Can be a string or an array of strings.

##### priority

* `optional`
* `default: '0.5'`

Change the default [priority](http://www.sitemaps.org/protocol.html).

##### output

* `optional`
* `default: 'sitemap.xml'`

Change the output file for the sitemap.

##### lastmod

* `optional`

Add a lastmodified date to the sitemap. Should be a Date object and can be passed through the Javascript API or the frontmatter.

##### omitExtension

* `optional`
* `default: false`

Will remove extensions from the urls in the sitemap. Useful when you're rewriting urls.

##### omitIndex

* `optional`
* `default: false`

Will replace any paths ending in `index.html` with `''`. Useful when you're using [metalsmith-permalinks](https://github.com/segmentio/metalsmith-permalinks).

## Frontmatter

Some values can also be set on a file-to-file basis from a file's frontmatter, the options are:

* `canonical`: will override the filename used to generate the url. The path is relative to the hostname.
* `changefreq`: will override any other settings for `changefreq` for the current file.
* `lastmod`: will override any other settings for `lastmod` for the current file.
* `priority`: will override any other settings for `priority` for the current file.
* `private`: will exclude the file from the sitemap when set to true.

For example:

```html
---
canonical: 'different'
changefreq: always
lastmod: 2014-12-01
priority: 1.0
private: true
---
<!-- index.html -->
```
Note that the property keys (`urlProperty`, `modifiedProperty`) can use the dot syntax to traverse the front matter
object for any given page.

###Front Matter
There are a few properties that Sitemap will use from a files front matter. The first two, mentioned above, are
configurable. The next two are expected to be at a set location. These are page specific values for `priority` and
`changefreq` which should be at `sitemap.priority` and `sitemap.changefreq` respectively.
## License

The last piece of front matter that the sitemap pays attention to is another way of ignoring files. If a file has
`private` set to true in the front matter it will be skipped in the sitemap`private` set to true in the front matter it
will be skipped inthe sitemap.
MIT
Loading