sitemaps
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "sitemaps", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A simple sitemap.xml generator.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# sitemaps | ||
[![](https://img.shields.io/npm/v/sitemaps.svg)](https://www.npmjs.com/package/sitemaps) | ||
[![NPM](https://img.shields.io/npm/v/sitemaps.svg)](https://www.npmjs.com/package/sitemaps) | ||
[![Build Status](https://travis-ci.org/diogocapela/sitemaps.svg?branch=master)](https://travis-ci.org/diogocapela/sitemaps) | ||
@@ -18,3 +19,5 @@ A simple sitemap.xml generator. | ||
const highPriority = ['https://example.com']; | ||
const highPriority = [ | ||
'https://example.com', | ||
]; | ||
const lowPriority = [ | ||
@@ -33,21 +36,7 @@ 'https://example.com/about', | ||
console.log(`Sitemap.xml generated at: ${filePath}`); | ||
console.log(xml); | ||
}); | ||
``` | ||
## Scripts | ||
```bash | ||
# Install all the dependencies | ||
$ npm i | ||
# Run the tests | ||
$ npm run test | ||
# Delete node_modules and package-lock.json | ||
$ npm run clean | ||
``` | ||
## License | ||
Open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
const fs = require('fs'); | ||
module.exports = (highPriority, lowPriority, filePath, callback) => { | ||
let XML = '<?xml version="1.0" encoding="UTF-8"?>\n\n'; | ||
const timestamp = new Date().toISOString(); | ||
let xml = '<?xml version="1.0" encoding="UTF-8"?>\n\n'; | ||
XML += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"\n'; | ||
XML += '\txmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n'; | ||
XML += '\txsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9\n'; | ||
XML += '\thttp://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">\n\n'; | ||
xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"\n'; | ||
xml += '\txmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n'; | ||
xml += '\txsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9\n'; | ||
xml += '\thttp://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">\n\n'; | ||
highPriority.forEach((link) => { | ||
XML += '\t<url>\n'; | ||
XML += `\t\t<loc>${link}</loc>\n`; | ||
XML += `\t\t<lastmod>${new Date().toISOString()}</lastmod>\n`; | ||
XML += '\t\t<priority>1.00</priority>\n'; | ||
XML += '\t</url>\n'; | ||
xml += '\t<url>\n'; | ||
xml += `\t\t<loc>${link}</loc>\n`; | ||
xml += `\t\t<lastmod>${timestamp}</lastmod>\n`; | ||
xml += '\t\t<priority>1.00</priority>\n'; | ||
xml += '\t</url>\n'; | ||
}); | ||
lowPriority.forEach((link) => { | ||
XML += '\t<url>\n'; | ||
XML += `\t\t<loc>${link}</loc>\n`; | ||
XML += `\t\t<lastmod>${new Date().toISOString()}</lastmod>\n`; | ||
XML += '\t\t<priority>0.80</priority>\n'; | ||
XML += '\t</url>\n'; | ||
xml += '\t<url>\n'; | ||
xml += `\t\t<loc>${link}</loc>\n`; | ||
xml += `\t\t<lastmod>${timestamp}</lastmod>\n`; | ||
xml += '\t\t<priority>0.80</priority>\n'; | ||
xml += '\t</url>\n'; | ||
}); | ||
XML += '\n</urlset>\n'; | ||
xml += '\n</urlset>\n'; | ||
fs.writeFile(filePath, XML, (error) => { | ||
fs.writeFile(filePath, xml, (error) => { | ||
if (error) { | ||
callback(null, error); | ||
} else { | ||
callback(XML, null); | ||
callback(xml, null); | ||
} | ||
}); | ||
}; |
5993
10
90
41