-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trim index.js, improve modularity and tests
- Loading branch information
Showing
5 changed files
with
146 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
var slash = require('slash'); | ||
|
||
//TODO: export this to an external module | ||
|
||
var xmlHeader = [ | ||
'<?xml version="1.0" encoding="UTF-8"?>', | ||
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' | ||
]; | ||
|
||
var prepareSitemap = function (entries, config) { | ||
//insert xml heaader | ||
entries.unshift(xmlHeader); | ||
//close off urlset | ||
entries.push('</urlset>'); | ||
return entries.join(config.newLine); | ||
}; | ||
|
||
/** | ||
* processFile | ||
* | ||
* @param filename | ||
* @param lastmod | ||
* @param config | ||
* @return {Array} | ||
*/ | ||
var processFile = function (filename, lastmod, config) { | ||
//format mtime to ISO (same as +00:00) | ||
lastmod = new Date(lastmod).toISOString(); | ||
//turn index.html into -> / | ||
var relativeFile = filename.replace(/(index)\.(html?){1}$/, '', 'i'); | ||
//url location. Use slash to convert windows \\ or \ to / | ||
var loc = config.siteUrl + slash(relativeFile); | ||
var returnArr = []; | ||
|
||
//push file to xml | ||
//TODO: skip spacing and use an xml beautifier | ||
returnArr.push(config.spacing + '<url>'); | ||
returnArr.push(config.spacing + config.spacing + '<loc>' + loc + '</loc>'); | ||
returnArr.push(config.spacing + config.spacing + '<lastmod>' + lastmod + '</lastmod>'); | ||
returnArr.push(config.spacing + config.spacing + '<changefreq>' + config.changeFreq + '</changefreq>'); | ||
returnArr.push(config.spacing + config.spacing + '<priority>' + config.priority + '</priority>'); | ||
returnArr.push(config.spacing + '</url>'); | ||
return returnArr; | ||
}; | ||
|
||
exports.prepareSitemap = prepareSitemap; | ||
exports.processFile = processFile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,52 @@ | ||
{ | ||
"name": "gulp-sitemap", | ||
"version": "0.2.6", | ||
"description": "Generate a search engine friendly sitemap.xml using a Gulp stream", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/pgilad/gulp-sitemap" | ||
}, | ||
"homepage": "https://github.com/pgilad/gulp-sitemap", | ||
"bugs": "https://github.com/pgilad/gulp-sitemap/issues", | ||
"author": { | ||
"name": "Gilad Peleg", | ||
"email": "[email protected]" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"LICENSE.md" | ||
], | ||
"scripts": { | ||
"watchTest": "mocha -R spec --watch test/test.js", | ||
"test": "mocha test/test.js" | ||
}, | ||
"main": "index.js", | ||
"keywords": [ | ||
"gulpplugin", | ||
"gulp", | ||
"js", | ||
"javascript", | ||
"seo", | ||
"sitemap", | ||
"sitemap.xml", | ||
"google", | ||
"search-engine", | ||
"xml" | ||
], | ||
"dependencies": { | ||
"gulp-util": "~2.2.12", | ||
"slash": "^0.1.3", | ||
"through2": "^0.5.1" | ||
}, | ||
"devDependencies": { | ||
"gulp": "^3.6.2", | ||
"mocha": "^1.19.0", | ||
"should": "^4.0.4" | ||
} | ||
"name": "gulp-sitemap", | ||
"version": "0.2.6", | ||
"description": "Generate a search engine friendly sitemap.xml using a Gulp stream", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/pgilad/gulp-sitemap" | ||
}, | ||
"homepage": "https://github.com/pgilad/gulp-sitemap", | ||
"bugs": "https://github.com/pgilad/gulp-sitemap/issues", | ||
"author": { | ||
"name": "Gilad Peleg", | ||
"email": "[email protected]" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"LICENSE.md", | ||
"lib" | ||
], | ||
"scripts": { | ||
"watchTest": "mocha -R spec --watch test/test.js", | ||
"test": "mocha test/test.js -R spec" | ||
}, | ||
"main": "index.js", | ||
"keywords": [ | ||
"gulpplugin", | ||
"gulp", | ||
"js", | ||
"javascript", | ||
"seo", | ||
"sitemap", | ||
"sitemap.xml", | ||
"google", | ||
"search-engine", | ||
"xml" | ||
], | ||
"dependencies": { | ||
"gulp-util": "~2.2.12", | ||
"lodash.defaults": "^2.4.1", | ||
"slash": "^0.1.3", | ||
"through2": "^0.5.1" | ||
}, | ||
"devDependencies": { | ||
"gulp": "^3.6.2", | ||
"mocha": "^1.19.0", | ||
"should": "^4.0.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters