├── .editorconfig ├── .eslintrc ├── .gitattributes ├── .gitignore ├── .nvmrc ├── .travis.yml ├── History.md ├── LICENSE ├── Makefile ├── README.md ├── lib └── index.js ├── package.json └── test ├── fixtures ├── canonical │ ├── build │ │ ├── index.html │ │ └── sitemap.xml │ ├── expected │ │ ├── index.html │ │ └── sitemap.xml │ └── src │ │ └── index.html ├── defaults │ ├── build │ │ ├── index.html │ │ └── sitemap.xml │ ├── expected │ │ ├── index.html │ │ └── sitemap.xml │ └── src │ │ └── index.html ├── frontmatter │ ├── build │ │ ├── index.html │ │ └── sitemap.xml │ ├── expected │ │ ├── index.html │ │ └── sitemap.xml │ └── src │ │ └── index.html ├── hostname │ ├── build │ │ ├── index.html │ │ └── sitemap.xml │ ├── expected │ │ ├── index.html │ │ └── sitemap.xml │ └── src │ │ └── index.html ├── html │ ├── build │ │ ├── image.jpg │ │ ├── index.css │ │ ├── index.html │ │ └── sitemap.xml │ ├── expected │ │ ├── image.jpg │ │ ├── index.css │ │ ├── index.html │ │ └── sitemap.xml │ └── src │ │ ├── image.jpg │ │ ├── index.css │ │ └── index.html ├── lastmod │ ├── build │ │ ├── index.html │ │ └── sitemap.xml │ ├── expected │ │ ├── index.html │ │ └── sitemap.xml │ └── src │ │ └── index.html ├── omitExtension │ ├── build │ │ ├── index.html │ │ └── sitemap.xml │ ├── expected │ │ ├── index.html │ │ └── sitemap.xml │ └── src │ │ └── index.html ├── omitIndex │ ├── build │ │ ├── index.html │ │ └── sitemap.xml │ ├── expected │ │ ├── index.html │ │ └── sitemap.xml │ └── src │ │ └── index.html ├── output │ ├── build │ │ ├── index.html │ │ └── mapsite.xml │ ├── expected │ │ ├── index.html │ │ └── mapsite.xml │ └── src │ │ └── index.html ├── pattern │ ├── build │ │ ├── image.jpg │ │ ├── index.hbs │ │ ├── index.html │ │ └── sitemap.xml │ ├── expected │ │ ├── image.jpg │ │ ├── index.hbs │ │ ├── index.html │ │ └── sitemap.xml │ └── src │ │ ├── image.jpg │ │ ├── index.hbs │ │ └── index.html └── private │ ├── build │ ├── index.html │ ├── private.html │ └── sitemap.xml │ ├── expected │ ├── index.html │ ├── private.html │ └── sitemap.xml │ └── src │ ├── index.html │ └── private.html └── index.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # For more information about the properties used in 2 | # this file, please see the EditorConfig documentation: 3 | # http://editorconfig.org/ 4 | 5 | root = true 6 | 7 | [*] 8 | charset = utf-8 9 | end_of_line = lf 10 | indent_size = 2 11 | indent_style = space 12 | insert_final_newline = true 13 | trim_trailing_whitespace = true 14 | 15 | [*.md] 16 | trim_trailing_whitespace = false 17 | 18 | [Makefile] 19 | indent_style = tab 20 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | env: 2 | node: true 3 | rules: 4 | indent: [2, 2] 5 | linebreak-style: 2 6 | no-irregular-whitespace: 2 7 | no-trailing-spaces: 2 8 | quotes: [2, "single", "avoid-escape"] 9 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Automatically normalize line endings for all text-based files 2 | # http://git-scm.com/docs/gitattributes#_end_of_line_conversion 3 | * text=auto 4 | 5 | # For the following file types, normalize line endings to LF on 6 | # checkin and prevent conversion to CRLF when they are checked out 7 | # (this is required in order to prevent newline related issues like, 8 | # for example, after the build script is run) 9 | .* text eol=lf 10 | *.css text eol=lf 11 | *.html text eol=lf 12 | *.js text eol=lf 13 | *.json text eol=lf 14 | *.md text eol=lf 15 | *.sh text eol=lf 16 | *.txt text eol=lf 17 | *.xml text eol=lf 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json 3 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v8.12.0 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | 1.0.6 - October 23, 2018 2 | ----------------------- 3 | * update dependencies, remove dependency on strings pkg 4 | 5 | 1.0.5 - October 23, 2018 6 | ----------------------- 7 | * fix broken tests, update nvmrc, bugfixes 8 | 9 | 1.0.4 - January 4, 2016 10 | ----------------------- 11 | * update readme and tests 12 | 13 | 1.0.3 - October 17, 2015 14 | ------------------------ 15 | * convert windows file path backslashes to slash 16 | 17 | 1.0.2 - October 17, 2015 18 | ------------------------ 19 | * update sitemap.js 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 ExtraHop Networks 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | mocha=node_modules/.bin/mocha --reporter spec 2 | 3 | node_modules: package.json 4 | @npm install 5 | 6 | test: node_modules 7 | @$(mocha) 8 | 9 | .PHONY: test 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # metalsmith-mapsite 2 | 3 | [![npm](https://img.shields.io/npm/v/metalsmith-mapsite.svg)](https://www.npmjs.com/package/metalsmith-mapsite) [![Build Status](https://travis-ci.org/quercy/metalsmith-mapsite.svg)](https://travis-ci.org/quercy/metalsmith-mapsite) [![dependencies Status](https://david-dm.org/quercy/metalsmith-mapsite/status.svg)](https://david-dm.org/quercy/metalsmith-mapsite) [![devDependencies Status](https://david-dm.org/quercy/metalsmith-mapsite/dev-status.svg)](https://david-dm.org/quercy/metalsmith-mapsite?type=dev) [![npm](https://img.shields.io/npm/dm/metalsmith-mapsite.svg)](https://www.npmjs.com/package/metalsmith-mapsite) 4 | 5 | > A metalsmith plugin for generating a sitemap 6 | 7 | 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). 8 | 9 | ## Installation 10 | 11 | ```bash 12 | $ npm install metalsmith-mapsite 13 | ``` 14 | 15 | ## CLI Usage 16 | 17 | Configuration in `metalsmith.json`: 18 | 19 | ```json 20 | { 21 | "plugins": { 22 | "metalsmith-mapsite": { 23 | "hostname": "http://www.website.com" 24 | } 25 | } 26 | } 27 | ``` 28 | 29 | ## JavaScript Usage 30 | 31 | ```javascript 32 | var sitemap = require('metalsmith-mapsite'); 33 | 34 | metalsmith(__dirname) 35 | .use(sitemap('http://www.website.com')) 36 | .build(function(err){ 37 | if (err) throw err; 38 | }); 39 | ``` 40 | ## Options 41 | 42 | You can pass options to `metalsmith-mapsite` with the [Javascript API](https://github.com/segmentio/metalsmith#api) or [CLI](https://github.com/segmentio/metalsmith#cli). The options are: 43 | 44 | ##### hostname 45 | 46 | * `required` 47 | 48 | The hostname used for generating the urls. 49 | 50 | ##### changefreq 51 | 52 | * `optional` 53 | * `default: weekly` 54 | 55 | Change the default [changefreq](http://www.sitemaps.org/protocol.html). 56 | 57 | ##### pattern 58 | 59 | * `optional` 60 | * `default: '**/*.html'` 61 | 62 | 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. 63 | 64 | ##### priority 65 | 66 | * `optional` 67 | * `default: '0.5'` 68 | 69 | Change the default [priority](http://www.sitemaps.org/protocol.html). 70 | 71 | ##### output 72 | 73 | * `optional` 74 | * `default: 'sitemap.xml'` 75 | 76 | Change the output file for the sitemap. 77 | 78 | ##### lastmod 79 | 80 | * `optional` 81 | 82 | Add a lastmodified date to the sitemap. Should be a Date object and can be passed through the Javascript API or the frontmatter. 83 | 84 | ##### omitExtension 85 | 86 | * `optional` 87 | * `default: false` 88 | 89 | Will remove extensions from the urls in the sitemap. Useful when you're rewriting urls. 90 | 91 | ##### omitIndex 92 | 93 | * `optional` 94 | * `default: false` 95 | 96 | Will replace any paths ending in `index.html` with `''`. Useful when you're using [metalsmith-permalinks](https://github.com/segmentio/metalsmith-permalinks). 97 | 98 | ##### verbose 99 | 100 | * `optional` 101 | * `default: false` 102 | 103 | Will output all entries to console. 104 | 105 | ## Frontmatter 106 | 107 | Some values can also be set on a file-to-file basis from a file's frontmatter, the options are: 108 | 109 | * `canonical`: will override the filename used to generate the url. The path is relative to the hostname. 110 | * `changefreq`: will override any other settings for `changefreq` for the current file. 111 | * `lastmod`: will override any other settings for `lastmod` for the current file. 112 | * `priority`: will override any other settings for `priority` for the current file. 113 | * `private`: will exclude the file from the sitemap when set to true. 114 | * `sitemap`: include arbitrary structure in sitemap. See [sitemap package](https://github.com/ekalinin/sitemap.js#readme) for examples 115 | 116 | For example: 117 | 118 | ```html 119 | --- 120 | canonical: 'different' 121 | changefreq: always 122 | lastmod: 2014-12-01 123 | priority: 1.0 124 | private: true 125 | sitemap: 126 | img: 127 | - url: https://resources.example.com/images/image1.png 128 | caption: Image 1 Caption 129 | title: Image 1 Title 130 | geo_location: Australia 131 | license: https://creativecommons.org/licenses/by/4.0/ 132 | - url: https://resources.example.com/images/image2.png 133 | caption: Image 2 Caption 134 | title: Image 2 Title 135 | geo_location: Australia 136 | license: https://creativecommons.org/licenses/by/4.0/ 137 | --- 138 | 139 | ``` 140 | 141 | ## Origins 142 | 143 | Metalsmith-mapsite is a fork of metalsmith-sitemap. After [refactoring metalsmith-sitemap](https://github.com/ExtraHop/metalsmith-sitemap/pull/12) I decided I would like to keep the plugin [as simple as possible](http://davidwalsh.name/designing-simplicity), to minimize possible points of failure and because it already does a lot. 144 | 145 | This conflicted with the maintainer's goals, which is why I forked the plugin to metalsmith-mapsite. Mainly just for personal use, but maybe it'll be of use for others as well! 146 | 147 | ## License 148 | 149 | MIT 150 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Dependencies 3 | */ 4 | var debug = require('debug')('metalsmith-mapsite') 5 | var isundefined = require('lodash.isundefined'); 6 | var is = require('is'); 7 | var match = require('multimatch'); 8 | var path = require('path'); 9 | var pickby = require('lodash.pickby'); 10 | var slash = require('slash'); 11 | var sm = require('sitemap'); 12 | 13 | /** 14 | * Export plugin 15 | */ 16 | module.exports = plugin; 17 | 18 | /** 19 | * Metalsmith plugin for generating a sitemap. 20 | * 21 | * @param {String or Object} options 22 | * @property {Date} lastmod (optional) 23 | * @property {String} changefreq (optional) 24 | * @property {Boolean} omitExtension (optional) 25 | * @property {Boolean} omitIndex (optional) 26 | * @property {String} hostname 27 | * @property {String} output (optional) 28 | * @property {String} pattern (optional) 29 | * @property {String} priority (optional) 30 | * @property {String} verbose (optional) 31 | * @return {Function} 32 | */ 33 | function plugin(opts){ 34 | /** 35 | * Init 36 | */ 37 | opts = opts || {}; 38 | 39 | // Accept string option to specify the hostname 40 | if (typeof opts === 'string') { 41 | opts = { hostname: opts }; 42 | } 43 | 44 | // A hostname should be specified 45 | if (!opts.hostname) { 46 | throw new Error('"hostname" option required'); 47 | } 48 | 49 | // Map options to local variables and set defaults 50 | var changefreq = opts.changefreq || 'weekly'; 51 | var hostname = opts.hostname; 52 | var lastmod = opts.lastmod; 53 | var omitExtension = opts.omitExtension; 54 | var omitIndex = opts.omitIndex; 55 | var output = opts.output || 'sitemap.xml'; 56 | var pattern = opts.pattern || '**/*.html'; 57 | var priority = isNaN(opts.priority) ? 0.5 : opts.priority; // priority might be 0.0 which evaluates to false 58 | var verbose = opts.verbose || false; 59 | 60 | var chompRight = function(input, suffix) { 61 | if (input.endsWith(suffix)) { 62 | return input.slice(0, input.length - suffix.length); 63 | } else { 64 | return input; 65 | } 66 | }; 67 | 68 | /** 69 | * Main plugin function 70 | */ 71 | return function(files, metalsmith, done) { 72 | // Create sitemap object 73 | var sitemap = sm.createSitemap ({ 74 | hostname: hostname 75 | }); 76 | 77 | // Checks whether files should be processed 78 | function check(file, frontmatter) { 79 | // Only process files that match the pattern 80 | if (!match(file, pattern)[0]) { 81 | return false; 82 | } 83 | 84 | // Don't process private files 85 | if (frontmatter.private) { 86 | return false; 87 | } 88 | 89 | return true; 90 | } 91 | 92 | // Builds a url 93 | function buildUrl(file, frontmatter) { 94 | // Convert any windows backslash paths to slash paths 95 | var normalizedFile = slash(file); 96 | 97 | // Frontmatter settings take precedence 98 | if (is.string(frontmatter.canonical)) { 99 | return frontmatter.canonical; 100 | } 101 | 102 | // Remove index.html if necessary 103 | if (omitIndex && path.basename(normalizedFile) === 'index.html') { 104 | return chompRight(normalizedFile, 'index.html'); 105 | } 106 | 107 | // Remove extension if necessary 108 | if (omitExtension) { 109 | return chompRight(normalizedFile,path.extname(normalizedFile)); 110 | } 111 | 112 | // Otherwise just use the normalized 'file' entry 113 | return normalizedFile; 114 | } 115 | 116 | Object.keys(files).forEach(function(file) { 117 | // Get the current file's frontmatter 118 | var frontmatter = files[file]; 119 | 120 | // Only process files that pass the check 121 | if (!check(file, frontmatter)) { 122 | return; 123 | } 124 | 125 | // Create the sitemap entry (reject keys with falsy values) 126 | var entry = pickby({ 127 | changefreq: frontmatter.changefreq || changefreq, 128 | priority: frontmatter.priority || priority, 129 | lastmod: frontmatter.lastmod || lastmod 130 | }, function(item) { return !isundefined(item); }); 131 | 132 | if('lastmod' in entry) { 133 | entry.lastmod = new Date(entry.lastmod).toUTCString(); 134 | } 135 | 136 | // Add the url (which is allowed to be falsy) 137 | entry.url = buildUrl(file, frontmatter); 138 | 139 | if (frontmatter.sitemap) Object.assign(entry, frontmatter.sitemap) 140 | 141 | if (verbose) debug(entry) 142 | 143 | // Add the entry to the sitemap 144 | sitemap.add(entry); 145 | }); 146 | 147 | // Create sitemap in files 148 | files[output] = { 149 | contents: Buffer.from(sitemap.toString()) 150 | }; 151 | 152 | debug('wrote ' + sitemap.urls.length + ' urls to sitemap') 153 | 154 | done(); 155 | }; 156 | } 157 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metalsmith-mapsite", 3 | "version": "1.0.6", 4 | "description": "A metalsmith plugin for generating a sitemap.xml file.", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "test": "make test" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/quercy/metalsmith-mapsite.git" 12 | }, 13 | "keywords": [ 14 | "metalsmith", 15 | "sitemap" 16 | ], 17 | "author": "quercy (https://quercy.co)", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/quercy/metalsmith-mapsite/issues" 21 | }, 22 | "homepage": "https://github.com/quercy/metalsmith-mapsite", 23 | "dependencies": { 24 | "debug": "^4.1.1", 25 | "is": "^3.0.1", 26 | "lodash.isundefined": "^3.0.1", 27 | "lodash.pickby": "^4.6.0", 28 | "multimatch": "^2.0.0", 29 | "sitemap": "^2.1.0", 30 | "slash": "^2.0.0" 31 | }, 32 | "devDependencies": { 33 | "assert-dir-equal": "^1.0.1", 34 | "metalsmith": "^2.0.1", 35 | "mocha": "^5.2.0" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/fixtures/canonical/build/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/canonical/build/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/differentweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/canonical/expected/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/canonical/expected/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/differentweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/canonical/src/index.html: -------------------------------------------------------------------------------- 1 | --- 2 | canonical: 'different' 3 | --- 4 | Hello -------------------------------------------------------------------------------- /test/fixtures/defaults/build/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/defaults/build/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.htmlnever0.0 -------------------------------------------------------------------------------- /test/fixtures/defaults/expected/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/defaults/expected/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.htmlnever0.0 -------------------------------------------------------------------------------- /test/fixtures/defaults/src/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/frontmatter/build/index.html: -------------------------------------------------------------------------------- 1 | Hello 2 | -------------------------------------------------------------------------------- /test/fixtures/frontmatter/build/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.html2014-12-01always1.0http://test.com/img1.jpgLondon, United Kingdomhttps://creativecommons.org/licenses/by/4.0/http://test.com/img2.jpgLondon, United Kingdomhttps://creativecommons.org/licenses/by/4.0/http://test.com/tmbn1.jpg -------------------------------------------------------------------------------- /test/fixtures/frontmatter/expected/index.html: -------------------------------------------------------------------------------- 1 | Hello 2 | -------------------------------------------------------------------------------- /test/fixtures/frontmatter/expected/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.html2014-12-01always1.0http://test.com/img1.jpgLondon, United Kingdomhttps://creativecommons.org/licenses/by/4.0/http://test.com/img2.jpgLondon, United Kingdomhttps://creativecommons.org/licenses/by/4.0/http://test.com/tmbn1.jpg -------------------------------------------------------------------------------- /test/fixtures/frontmatter/src/index.html: -------------------------------------------------------------------------------- 1 | --- 2 | priority: 1.0 3 | changefreq: always 4 | lastmod: 2014-12-01 5 | sitemap: 6 | img: 7 | - url: http://test.com/img1.jpg 8 | caption: An image 9 | title: The Title of Image One 10 | geoLocation: London, United Kingdom 11 | license: https://creativecommons.org/licenses/by/4.0/ 12 | - url: http://test.com/img2.jpg 13 | caption: Another image 14 | title: The Title of Image Two 15 | geoLocation: London, United Kingdom 16 | license: https://creativecommons.org/licenses/by/4.0/ 17 | video: 18 | - thumbnail_loc: http://test.com/tmbn1.jpg 19 | title: A video title 20 | description: This is a video 21 | --- 22 | Hello 23 | -------------------------------------------------------------------------------- /test/fixtures/hostname/build/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/hostname/build/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.htmlweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/hostname/expected/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/hostname/expected/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.htmlweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/hostname/src/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/html/build/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quercy/metalsmith-mapsite/bc3792470c1ccda05dc4a1296318da6e2c369d9c/test/fixtures/html/build/image.jpg -------------------------------------------------------------------------------- /test/fixtures/html/build/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: red; 3 | } -------------------------------------------------------------------------------- /test/fixtures/html/build/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/html/build/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.htmlweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/html/expected/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quercy/metalsmith-mapsite/bc3792470c1ccda05dc4a1296318da6e2c369d9c/test/fixtures/html/expected/image.jpg -------------------------------------------------------------------------------- /test/fixtures/html/expected/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: red; 3 | } -------------------------------------------------------------------------------- /test/fixtures/html/expected/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/html/expected/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.htmlweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/html/src/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quercy/metalsmith-mapsite/bc3792470c1ccda05dc4a1296318da6e2c369d9c/test/fixtures/html/src/image.jpg -------------------------------------------------------------------------------- /test/fixtures/html/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: red; 3 | } -------------------------------------------------------------------------------- /test/fixtures/html/src/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/lastmod/build/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/lastmod/build/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.html1995-12-17weekly0.5 -------------------------------------------------------------------------------- /test/fixtures/lastmod/expected/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/lastmod/expected/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.html1995-12-17weekly0.5 -------------------------------------------------------------------------------- /test/fixtures/lastmod/src/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/omitExtension/build/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/omitExtension/build/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/indexweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/omitExtension/expected/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/omitExtension/expected/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/indexweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/omitExtension/src/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/omitIndex/build/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/omitIndex/build/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.comweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/omitIndex/expected/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/omitIndex/expected/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.comweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/omitIndex/src/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/output/build/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/output/build/mapsite.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.htmlweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/output/expected/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/output/expected/mapsite.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.htmlweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/output/src/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/pattern/build/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quercy/metalsmith-mapsite/bc3792470c1ccda05dc4a1296318da6e2c369d9c/test/fixtures/pattern/build/image.jpg -------------------------------------------------------------------------------- /test/fixtures/pattern/build/index.hbs: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/pattern/build/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/pattern/build/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.hbsweekly0.5http://www.website.com/index.htmlweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/pattern/expected/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quercy/metalsmith-mapsite/bc3792470c1ccda05dc4a1296318da6e2c369d9c/test/fixtures/pattern/expected/image.jpg -------------------------------------------------------------------------------- /test/fixtures/pattern/expected/index.hbs: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/pattern/expected/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/pattern/expected/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.hbsweekly0.5http://www.website.com/index.htmlweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/pattern/src/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quercy/metalsmith-mapsite/bc3792470c1ccda05dc4a1296318da6e2c369d9c/test/fixtures/pattern/src/image.jpg -------------------------------------------------------------------------------- /test/fixtures/pattern/src/index.hbs: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/pattern/src/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/private/build/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/private/build/private.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/private/build/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.htmlweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/private/expected/index.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/private/expected/private.html: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /test/fixtures/private/expected/sitemap.xml: -------------------------------------------------------------------------------- 1 | http://www.website.com/index.htmlweekly0.5 -------------------------------------------------------------------------------- /test/fixtures/private/src/index.html: -------------------------------------------------------------------------------- 1 | --- 2 | changefreq: weekly 3 | priority: 0.5 4 | --- 5 | Hello -------------------------------------------------------------------------------- /test/fixtures/private/src/private.html: -------------------------------------------------------------------------------- 1 | --- 2 | private: true 3 | --- 4 | Hello -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var equal = require('assert-dir-equal'); 3 | var Metalsmith = require('metalsmith'); 4 | var sitemap = require('..'); 5 | 6 | describe('metalsmith-sitemap', function(){ 7 | it('should only process html by default', function(done){ 8 | Metalsmith('test/fixtures/html') 9 | .use(sitemap('http://www.website.com/')) 10 | .build(function(err){ 11 | if (err) { 12 | return done(err); 13 | } 14 | equal('test/fixtures/html/expected', 'test/fixtures/html/build'); 15 | done(); 16 | }); 17 | }); 18 | 19 | it('should accept a string as the hostname', function(done){ 20 | Metalsmith('test/fixtures/hostname') 21 | .use(sitemap('http://www.website.com/')) 22 | .build(function(err){ 23 | if (err) { 24 | return done(err); 25 | } 26 | equal('test/fixtures/hostname/expected', 'test/fixtures/hostname/build'); 27 | done(); 28 | }); 29 | }); 30 | 31 | it('should accept defaults for changefreq and priority', function(done){ 32 | Metalsmith('test/fixtures/defaults') 33 | .use(sitemap({ 34 | hostname: 'http://www.website.com/', 35 | changefreq: 'never', 36 | priority: 0.0 37 | })) 38 | .build(function(err){ 39 | if (err) { 40 | return done(err); 41 | } 42 | equal('test/fixtures/defaults/expected', 'test/fixtures/defaults/build'); 43 | done(); 44 | }); 45 | }); 46 | 47 | it('should allow settings to be overridden from the frontmatter', function(done){ 48 | Metalsmith('test/fixtures/frontmatter') 49 | .use(sitemap({ 50 | hostname: 'http://www.website.com/', 51 | changefreq: 'never', 52 | priority: '0.0', 53 | lastmod: new Date() 54 | })) 55 | .build(function(err){ 56 | if (err) { 57 | return done(err); 58 | } 59 | equal('test/fixtures/frontmatter/expected', 'test/fixtures/frontmatter/build'); 60 | done(); 61 | }); 62 | }); 63 | 64 | it('should allow the sitemap\'s location to be changed', function(done){ 65 | Metalsmith('test/fixtures/output') 66 | .use(sitemap({ 67 | hostname: 'http://www.website.com/', 68 | output: 'mapsite.xml' 69 | })) 70 | .build(function(err){ 71 | if (err) { 72 | return done(err); 73 | } 74 | equal('test/fixtures/output/expected', 'test/fixtures/output/build'); 75 | done(); 76 | }); 77 | }); 78 | 79 | it('should accept a pattern', function(done){ 80 | Metalsmith('test/fixtures/pattern') 81 | .use(sitemap({ 82 | hostname: 'http://www.website.com/', 83 | pattern: ['**/*.html', '**/*.hbs'] 84 | })) 85 | .build(function(err){ 86 | if (err) { 87 | return done(err); 88 | } 89 | equal('test/fixtures/pattern/expected', 'test/fixtures/pattern/build'); 90 | done(); 91 | }); 92 | }); 93 | 94 | it('should allow a canonical url to be set', function(done){ 95 | Metalsmith('test/fixtures/canonical') 96 | .use(sitemap('http://www.website.com/')) 97 | .build(function(err){ 98 | if (err) { 99 | return done(err); 100 | } 101 | equal('test/fixtures/canonical/expected', 'test/fixtures/canonical/build'); 102 | done(); 103 | }); 104 | }); 105 | 106 | it('should allow lastmod to be set', function(done){ 107 | Metalsmith('test/fixtures/lastmod') 108 | .use(sitemap({ 109 | hostname: 'http://www.website.com/', 110 | lastmod: new Date('1995-12-17T03:24:00') 111 | })) 112 | .build(function(err){ 113 | if (err) { 114 | return done(err); 115 | } 116 | equal('test/fixtures/lastmod/expected', 'test/fixtures/lastmod/build'); 117 | done(); 118 | }); 119 | }); 120 | 121 | it('should be able to omit extensions', function(done){ 122 | Metalsmith('test/fixtures/omitExtension') 123 | .use(sitemap({ 124 | hostname: 'http://www.website.com/', 125 | omitExtension: true 126 | })) 127 | .build(function(err){ 128 | if (err) { 129 | return done(err); 130 | } 131 | equal('test/fixtures/omitExtension/expected', 'test/fixtures/omitExtension/build'); 132 | done(); 133 | }); 134 | }); 135 | 136 | it('should be able to omit index.html', function(done){ 137 | Metalsmith('test/fixtures/omitIndex') 138 | .use(sitemap({ 139 | hostname: 'http://www.website.com/', 140 | omitIndex: true 141 | })) 142 | .build(function(err){ 143 | if (err) { 144 | return done(err); 145 | } 146 | equal('test/fixtures/omitIndex/expected', 'test/fixtures/omitIndex/build'); 147 | done(); 148 | }); 149 | }); 150 | 151 | it('should ignore files marked as private', function(done){ 152 | Metalsmith('test/fixtures/private') 153 | .use(sitemap('http://www.website.com/')) 154 | .build(function(err){ 155 | if (err) { 156 | return done(err); 157 | } 158 | equal('test/fixtures/private/expected', 'test/fixtures/private/build'); 159 | done(); 160 | }); 161 | }); 162 | 163 | }); 164 | --------------------------------------------------------------------------------