Skip to content
This repository has been archived by the owner on Oct 6, 2021. It is now read-only.

Commit

Permalink
[js] initial commit of v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhyde committed Sep 22, 2015
1 parent 0d38050 commit 2ba69ba
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 7 deletions.
6 changes: 1 addition & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,5 @@ insert_final_newline = true
indent_style = space
indent_size = 2

[*.{coffee,json,yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
trim_trailing_whitespace = false
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- '0.12'
- '4'
- '4.0'
- 'node'
- 'iojs'
before_install:
- npm install -g grunt-cli
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## v0.1.0
* replaced `grunt.template.today()` with `moment()` to fit `W3C Datetime` standart
* allow to set custom time format #note: see [moment.js](http://momentjs.com/)
* [js-standard-style](https://github.com/feross/standard)
* code rewrited in ES6 and requres node v4.0.0 or higher
* general improvements to gruntfile (coffee, jit-grunt)
* upgraded `xmlbuilder` to 3.1.0
* new `pretty` option #note: false by default
22 changes: 22 additions & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2015 LotusTM

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
54 changes: 54 additions & 0 deletions gruntfile.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module.exports = (grunt) ->
'use strict'

# Track execution time
require('time-grunt') grunt

# Load grunt tasks automatically
require('jit-grunt') grunt

grunt.initConfig
pkg: grunt.file.readJSON 'package.json'

path:
temp: 'temp'
test: 'test'
fixtures: '<%= path.test %>/fixtures'

clean:
test:
'<%= path.temp %>'

sitemap_xml:
default_options:
files: [
cwd: '<%= path.fixtures %>'
src: '{,**/}*.html'
dest: '<%= path.temp %>/sitemap.xml'
]
custom_options:
options:
root: 'true',
stripIndex: false,
fileName: 'map',
lastMod: grunt.template.today('yyyy-mm-dd'),
priority: '0.1',
changeFreq: 'monthly'
pretty: true
files: [
cwd: '<%= path.fixtures %>'
src: '{,**/}*.{html,htm}'
dest: '<%= path.temp %>/map.xml'
]

grunt.loadTasks 'tasks'

###
A task for scss and js linting
###
grunt.registerTask 'test', [
'clean'
'sitemap_xml'
]

return
56 changes: 56 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "grunt-sitemap-xml",
"description": "Grunt plugin for generating XML sitemaps for search engine indexing",
"version": "0.1.0",
"homepage": "https://github.com/LotusTM/grunt-sitemap-xml",
"author": "LotusTM <npm@2bad.me>",
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/LotusTM/grunt-sitemap-xml.git"
},
"bugs": {
"url": "https://github.com/LotusTM/grunt-sitemap-xml/issues"
},
"keywords": [
"generator",
"google",
"grunt",
"gruntplugin",
"plugin",
"seo",
"sitemap",
"xml"
],
"dependencies": {
"chalk": "^1.1.1",
"moment": "^2.10.6",
"xmlbuilder": "^3.1.0"
},
"devDependencies": {
"babel-eslint": "^4.1.3",
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-jshint": "^0.11.3",
"jit-grunt": "^0.9.1",
"standard": "^5.3.1",
"time-grunt": "^1.2.1"
},
"files": [
"tasks",
"CHANGELOG.md",
"LICENSE-MIT"
],
"directories": {
"test": "test"
},
"scripts": {
"test": "standard && grunt test"
},
"engines": {
"node": ">=4.0"
},
"standard": {
"parser": "babel-eslint"
}
}
78 changes: 78 additions & 0 deletions tasks/sitemap_xml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* grunt-sitemap-xml
* https://github.com/LotusTM/grunt-sitemap-xml
*
* Copyright (c) 2015 LotusTM
* Licensed under the MIT license.
*/
'use strict'

const chalk = require('chalk')
const moment = require('moment')
const builder = require('xmlbuilder')

module.exports = function (grunt) {
// Read package.json
const pkg = this.config.data.pkg || grunt.file.readJSON('package.json')

grunt.registerMultiTask('sitemap_xml', 'Grunt task for generating sitemap.xml for search engine indexing', function () {
let sitemap, root, url, message

const options = this.options({
siteRoot: pkg.homepage,
stripIndex: true,
fileName: 'sitemap',
lastMod: moment().format('YYYY-MM-DDTHH:mm:ssZ'),
priority: '0.5',
changeFreq: 'weekly',
pretty: false
})

// Resolve options.siteRoot, add '/' if needed
if (options.siteRoot) {
root = (options.siteRoot.slice(-1) === '/') ? options.siteRoot : options.siteRoot + '/'
} else {
grunt.fail.warn('Please set siteRoot variable in options or homepage property in package.json.')
}

// Build XML string
let urlset = builder.create('urlset', {
version: '1.0',
encoding: 'UTF-8'
})

urlset.att('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9')
.att('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance')
.att('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd')

// Iterate over all specified file groups
this.files.forEach(file => {
file.src.forEach(filepath => {
// Strip index.html
filepath = (options.stripIndex) ? filepath.replace('index.html', '') : filepath

// Create XML node for each entry
url = urlset.ele('url')

url.ele('loc', root + filepath)
url.ele('lastmod', options.lastMod)
url.ele('changefreq', options.changeFreq)
url.ele('priority', options.priority)

// for debug purpose
message = `loc: ${root + filepath}\nlastmod: ${options.lastMod}\nchangefreq: ${options.changeFreq}\npriority: ${options.priority}\n`
grunt.verbose.writeln(message)
})

// Format XML sitemap
sitemap = urlset.end({
pretty: options.pretty
})

// Write the destination file.
grunt.file.write(file.dest, sitemap)
// Print a success message.
grunt.log.writeln(`File ${chalk.cyan(file.dest)} created.`)
})
})
}
1 change: 1 addition & 0 deletions test/fixtures/blog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blog
1 change: 1 addition & 0 deletions test/fixtures/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index
1 change: 1 addition & 0 deletions test/fixtures/news.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
news
1 change: 1 addition & 0 deletions test/fixtures/short.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
short

0 comments on commit 2ba69ba

Please sign in to comment.