Skip to content

Commit

Permalink
Merge pull request #20 from assemble/develop
Browse files Browse the repository at this point in the history
v0.2.1
  • Loading branch information
hariadi committed Feb 23, 2014
2 parents d5624a9 + 78e8048 commit bccb5b0
Show file tree
Hide file tree
Showing 21 changed files with 105 additions and 70 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
npm-debug.log
*.sublime-*
*.iml
.idea
22 changes: 16 additions & 6 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
v0.2.1:
date: 2014-02-21
changes:
- fix option.robot was ignored and always true 0159123
- feature: add option.dest and use as output path
- fix: option.robot was ignored and always true
- feature: add option to overwrite changefreq per file
- cosmetical changes (code formatting, naming, simplify)
- wip: enable globbing patterns for option.exclude

v0.2.0:
date: 2013-02-05
date: 2014-02-05
changes:
- Generation of robots.txt will now respect the relativedest option.

v0.1.9:
date: 2013-02-02
date: 2014-02-02
changes:
- Fix sitemap destination

v0.1.8:
date: 2013-01-28
date: 2014-01-28
changes:
- Use external library
- Get pages from assemble object

v0.1.7:
date: 2013-01-03
date: 2014-01-03
changes:
- Add relativedest option

Expand Down Expand Up @@ -49,9 +59,9 @@ v0.1.1:
- Add option to generate robots.txt
- Change name to assemble-contrib.sitemap
- Move to Assemble main repo

v0.1.0:
date: 2013-10-01
changes:
- First commmit.
- Add option to exclude
- Add option to exclude
18 changes: 18 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ module.exports = function(grunt) {
dest: 'test/actual/sitemap_relative'
}
]
},
sitemap_dest: {
options: {
sitemap: {
homepage: 'http://assemble.io',
exclude: ['**/articles/**'],
relativedest: true,
dest: 'test/actual/sitemap_dest'
}
},
files: [
{
expand: true,
cwd: 'test/fixtures/pages',
src: ['**/*.hbs'],
dest: 'test/actual/sitemap_dest'
}
]
}
},

Expand Down
22 changes: 7 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* [Usage Examples](#usage-examples)
* [Contributing](#contributing)
* [Author](#author)
* [Release History](#release-history)
* [License](#license)


Expand Down Expand Up @@ -49,6 +48,12 @@ If everything was installed and configured correctly, you should be ready to go!
## Options
See [sitemaps.org](http://www.sitemaps.org/protocol.html#xmlTagDefinitions) for detail XML tag definitions.

#### dest
Type: `String`
Default: `assemble.pages`

Sitemap destination. If not set, fallback to assemble destination.

### homepage
Type: `String`
Default: `homepage` (from package.json)
Expand Down Expand Up @@ -165,23 +170,10 @@ We welcome all kinds of contributions! The most basic way to show your support i
+ [github.com/hariadi](https://github.com/hariadi)
+ [twitter.com/hariadi](http://twitter.com/hariadi)

## Release History

* 2013-02-05   v0.2.0   Generation of robots.txt will now respect the relativedest option.
* 2013-02-02   v0.1.9   Fix sitemap destination
* 2013-01-28   v0.1.8   Use external library Get pages from assemble object
* 2013-01-03   v0.1.7   Add relativedest option
* 2013-12-12   v0.1.6   Fix plugin name in Usage Examples Update deps
* 2013-11-28   v0.1.4   Updates dependencies to work with Grunt 0.4.2 [object Object] Add TOC to docs
* 2013-10-20   v0.1.3   Fix sitemap and robots.txt generated on every folder Update docs options:exclusions
* 2013-10-18   v0.1.2   Fix homepage
* 2013-10-17   v0.1.1   Add option to generate robots.txt Change name to assemble-contrib.sitemap Move to Assemble main repo
* 2013-10-01   v0.1.0   First commmit. Add option to exclude

## License
Copyright (c) 2014 Hariadi Hinta, contributors.
Released under the license

***

_This file was generated on Thursday, February 5, 2014._
_This file was generated on Saturday, February 22, 2014._
17 changes: 0 additions & 17 deletions docs/README.tmpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,6 @@ We welcome all kinds of contributions! The most basic way to show your support i
+ [github.com/{%= username %}](https://github.com/{%= username %})
+ [twitter.com/{%= username %}](http://twitter.com/{%= username %})

## Release History
{% if (changelog) {
_.each(changelog, function(details, version) {
var date = details.date;
if (date instanceof Date) {
date = grunt.template.date(new Date(date.getTime() + date.getTimezoneOffset() * 60000), 'yyyy-mm-dd');
}
print('\n * ' + [
date,
version,
details.changes.join(' '),
].join('\u2003\u2003\u2003'));
});
} else { %}
_(Nothing yet)_
{% } %}

## License
{%= copyright %}
{%= license %}
Expand Down
6 changes: 6 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
See [sitemaps.org](http://www.sitemaps.org/protocol.html#xmlTagDefinitions) for detail XML tag definitions.

### dest
Type: `String`
Default: `undefined`

Sitemap destination. If not set, fallback to assemble destination.

## homepage
Type: `String`
Default: `homepage` (from package.json)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "assemble-contrib-sitemap",
"version": "0.2.0",
"version": "0.2.1",
"description": "Sitemap generator plugin for Assemble",
"homepage": "http://assemble.io/plugins",
"author": {
Expand Down
38 changes: 18 additions & 20 deletions sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,25 @@ var _ = require('lodash');
var path = require('path');

module.exports = function (params, callback) {

var assemble = params.assemble;
var grunt = params.grunt;
var pages = assemble.options.pages;
var options = assemble.options.sitemap || {};
var dest = path.dirname(pages[0].dest);
var sitemap = [];
var robots = [];
var exclusion = ['404'];
var pkg = grunt.file.readJSON('package.json');

options.homepage = options.homepage || pkg.homepage;
options.robot = options.robot || true;
options.robot = options.robot !== false;
options.changefreq = options.changefreq || 'weekly';
options.priority = (options.priority || 0.5).toString();
options.relativedest = options.relativedest || false;
options.dest = options.dest || path.dirname(pages[0].dest);


// Only write if it actually changed.
var write = function(file, content) {
var write = function (file, content) {
var msg;
var old = grunt.file.exists(file) ? grunt.file.read(file) : '';

Expand All @@ -47,37 +46,38 @@ module.exports = function (params, callback) {
};

// Return the relative destination if the option is enabled
var getRelativeDest = function(relativedest, file) {
return (relativedest ? file.dest.replace(file.filePair.orig.dest + "/", "") : file.dest );
var getExternalFilePath = function (relativedest, file) {
return (relativedest ? file.dest.replace(options.dest + "/", "") : file.dest );
};

async.forEach(pages, function (file, next) {

if(!_.isUndefined(options.exclude)) {
if (!_.isUndefined(options.exclude)) {
exclusion = _.union([], exclusion, options.exclude || []);
}

var url = options.homepage;
var date = file.data.updated || file.data.date || new Date();
var changefreq = options.changefreq;
var changefreq = file.data.changefreq || options.changefreq;
var priority = options.priority;
var relativedest = options.relativedest;

if(exclusion.indexOf(file.basename) !== -1) {
robots.push('Disallow: /' + getRelativeDest(relativedest, file));
if (exclusion.indexOf(file.basename) !== -1 ||
grunt.file.isMatch({srcBase: options.dest}, exclusion, file.dest)) {
robots.push('Disallow: /' + getExternalFilePath(relativedest, file));
return;
}

sitemap.push({
url: {
loc: url + '/' + getRelativeDest(relativedest, file),
loc: url + '/' + getExternalFilePath(relativedest, file),
lastmod: date.toISOString(),
changefreq: changefreq,
priority: priority
}
});

next();
next();
}, callback());

var result = xml.toXML({
Expand All @@ -88,22 +88,20 @@ module.exports = function (params, callback) {
_content: sitemap
}, {header: true, indent: ' '});



var sitemapDest = dest + '/sitemap.xml';

var sitemapDest = options.dest + '/sitemap.xml';
write(sitemapDest, result);

if (options.robot) {
var robot = "User-agent: *\n\n";

_.forEach(robots, function(item) {
robot += item + '\n';
});
robot += robots.join('\n') + '\n';

var robotpDest = dest + '/robots.txt';
var robotpDest = options.dest + '/robots.txt';
write(robotpDest, robot);
}

};

module.exports.options = {
Expand Down
2 changes: 1 addition & 1 deletion test/actual/sitemap/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<url>
<loc>http://assemble.io/plugins/test/actual/sitemap/index.html</loc>
<lastmod>2013-10-01T00:00:00.000Z</lastmod>
<changefreq>weekly</changefreq>
<changefreq>hourly</changefreq>
<priority>0.5</priority>
</url>
</urlset>
2 changes: 2 additions & 0 deletions test/actual/sitemap_dest/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<h1>404</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<h1>Arctic Ice is Really Cold</h1>
<p>Suprising discovery! Contrary to popular belief, ice in the arctic tundra was found to be below freezing temperatures.</p>
3 changes: 3 additions & 0 deletions test/actual/sitemap_dest/articles/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<h1>Some Category</h1>
<p>Index page nested in a directory.</p>
2 changes: 2 additions & 0 deletions test/actual/sitemap_dest/foo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<h1>foo</h1>
3 changes: 3 additions & 0 deletions test/actual/sitemap_dest/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<h1>Home</h1>
<p>This is the home page!</p>
5 changes: 5 additions & 0 deletions test/actual/sitemap_dest/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
User-agent: *

Disallow: /404.html
Disallow: /articles/arctic-ice-is-really-cold.html
Disallow: /articles/index.html
15 changes: 15 additions & 0 deletions test/actual/sitemap_dest/sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://assemble.io/foo.html</loc>
<lastmod>2013-10-03T00:00:00.000Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>http://assemble.io/index.html</loc>
<lastmod>2013-10-01T00:00:00.000Z</lastmod>
<changefreq>hourly</changefreq>
<priority>0.5</priority>
</url>
</urlset>
4 changes: 0 additions & 4 deletions test/actual/sitemap_option/robots.txt

This file was deleted.

2 changes: 1 addition & 1 deletion test/actual/sitemap_option/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<url>
<loc>http://assemble.io/test/actual/sitemap_option/index.html</loc>
<lastmod>2013-10-01T00:00:00.000Z</lastmod>
<changefreq>daily</changefreq>
<changefreq>hourly</changefreq>
<priority>0.8</priority>
</url>
</urlset>
4 changes: 0 additions & 4 deletions test/actual/sitemap_relative/robots.txt

This file was deleted.

2 changes: 1 addition & 1 deletion test/actual/sitemap_relative/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<url>
<loc>http://assemble.io/index.html</loc>
<lastmod>2013-10-01T00:00:00.000Z</lastmod>
<changefreq>daily</changefreq>
<changefreq>hourly</changefreq>
<priority>0.8</priority>
</url>
</urlset>
1 change: 1 addition & 0 deletions test/fixtures/pages/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Home
description: This is the home page!
slug: home-page
date: 2013-10-01
changefreq: hourly
---
<h1>{{{title}}}</h1>
<p>{{{description}}}</p>

0 comments on commit bccb5b0

Please sign in to comment.