Skip to content
Open
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
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ Will remove extensions from the urls in the sitemap. Useful when you're rewritin

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

##### xslUrl

* `optional`
* `default: ''`

Will add a link to the xsl file specified.

##### frontmatterIgnore

* `optional`
* `default: 'private'`

Will exclude files with this frontmatter property set to true.

## Frontmatter

Some values can also be set on a file-to-file basis from a file's frontmatter, the options are:
Expand All @@ -103,7 +117,7 @@ Some values can also be set on a file-to-file basis from a file's frontmatter, t
* `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.
* `private`: by default will exclude the file from the sitemap when set to true, but can be overrided with the `frontmatterIgnore` option.

For example:

Expand Down
10 changes: 7 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ function plugin(opts){
var omitIndex = opts.omitIndex;
var output = opts.output || 'sitemap.xml';
var pattern = opts.pattern || '**/*.html';
var xslUrl = opts.xslUrl || '';
var frontmatterIgnore = opts.frontmatterIgnore || 'private';

var priority = isNaN(opts.priority) ? 0.5 : opts.priority; // priority might be 0.0 which evaluates to false

var chompRight = function(input, suffix) {
Expand All @@ -68,7 +71,8 @@ function plugin(opts){
return function(files, metalsmith, done) {
// Create sitemap object
var sitemap = sm.createSitemap ({
hostname: hostname
hostname: hostname,
xslUrl: xslUrl
});

// Checks whether files should be processed
Expand All @@ -79,7 +83,7 @@ function plugin(opts){
}

// Don't process private files
if (frontmatter.private) {
if (frontmatter.private || frontmatter[frontmatterIgnore]) {
return false;
}

Expand Down Expand Up @@ -130,7 +134,7 @@ function plugin(opts){
entry.lastmod = new Date(entry.lastmod).toUTCString();
}

console.log(entry);


// Add the url (which is allowed to be falsy)
entry.url = buildUrl(file, frontmatter);
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "metalsmith-mapsite",
"version": "1.0.6",
"version": "1.0.8",
"description": "A metalsmith plugin for generating a sitemap.xml file.",
"main": "lib/index.js",
"scripts": {
"test": "make test"
},
"repository": {
"type": "git",
"url": "https://github.com/quercy/metalsmith-mapsite.git"
"url": "https://github.com/sparkalow/metalsmith-mapsite.git"
},
"keywords": [
"metalsmith",
Expand All @@ -17,9 +17,9 @@
"author": "quercy <reid.savage@gmail.com> (https://quercy.co)",
"license": "MIT",
"bugs": {
"url": "https://github.com/quercy/metalsmith-mapsite/issues"
"url": "https://github.com/sparkalow/metalsmith-mapsite/issues"
},
"homepage": "https://github.com/quercy/metalsmith-mapsite",
"homepage": "https://github.com/sparkalow/metalsmith-mapsite",
"dependencies": {
"is": "^3.0.1",
"lodash.isundefined": "^3.0.1",
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/xsl/build/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello
1 change: 1 addition & 0 deletions test/fixtures/xsl/build/sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="style.xsl"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"><url><loc>http://www.website.com/index.html</loc><changefreq>weekly</changefreq><priority>0.5</priority></url></urlset>
1 change: 1 addition & 0 deletions test/fixtures/xsl/expected/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello
1 change: 1 addition & 0 deletions test/fixtures/xsl/expected/sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="style.xsl"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"><url><loc>http://www.website.com/index.html</loc><changefreq>weekly</changefreq><priority>0.5</priority></url></urlset>
1 change: 1 addition & 0 deletions test/fixtures/xsl/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello
15 changes: 15 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ describe('metalsmith-sitemap', function(){
done();
});
});

it('should include XSL file if passed in options', function(done){
Metalsmith('test/fixtures/xsl')
.use(sitemap({
hostname: 'http://www.website.com/',
xslUrl: 'style.xsl'
}))
.build(function(err){
if (err) {
return done(err);
}
equal('test/fixtures/xsl/expected', 'test/fixtures/xsl/build');
done();
});
});

it('should ignore files marked as private', function(done){
Metalsmith('test/fixtures/private')
Expand Down