在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):pgilad/gulp-sitemap开源软件地址(OpenSource Url):https://github.com/pgilad/gulp-sitemap开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):gulp-sitemap
Easily generate a search engine friendly sitemap.xml from your project. Search engines love the sitemap.xml and it helps SEO as well. For information about sitemap properties and structure, see the wiki for sitemaps InstallInstall with npm $ npm install --save-dev gulp-sitemap Examplevar gulp = require('gulp');
var sitemap = require('gulp-sitemap');
gulp.task('sitemap', function () {
gulp.src('build/**/*.html', {
read: false
})
.pipe(sitemap({
siteUrl: 'http://www.amazon.com'
}))
.pipe(gulp.dest('./build'));
});
Let's see an example of how we can create and output a sitemap, and then return to the original stream files: var gulp = require('gulp');
var sitemap = require('gulp-sitemap');
var save = require('gulp-save');
gulp.task('html', function() {
gulp.src('*.html', {
read: false
})
.pipe(save('before-sitemap'))
.pipe(sitemap({
siteUrl: 'http://www.amazon.com'
})) // Returns sitemap.xml
.pipe(gulp.dest('./dist'))
.pipe(save.restore('before-sitemap')) //restore all files to the state when we cached them
// -> continue stream with original html files
// ...
}); OptionssiteUrlYour website's base url. This gets prepended to all documents locations. Type: Required: fileNameDetermine the output filename for the sitemap. Type: Default: Required: changefreqGets filled inside the sitemap in the tag Type: Default: Valid Values: Required: Note: any falsey value is also valid and will skip this xml tag priorityGets filled inside the sitemap in the tag Type: Default: Valid Values: Required: Note: any falsey (non-zero) value is also valid and will skip this xml tag Example using a function as priority: function(siteUrl, loc, entry) {
// Give pages inside root path (i.e. no slashes) a higher priority
return loc.split('/').length === 0 ? 1 : 0.5;
} lastmodThe file last modified time.
Type: Default: Required: Example that uses git to get lastmod from the latest commit of a file: lastmod: function(file) {
var cmd = 'git log -1 --format=%cI "' + file.relative + '"';
return execSync(cmd, {
cwd: file.base
}).toString().trim();
} Note: any falsey (other than null) value is also valid and will skip this xml tag newLineHow to join line in the target sitemap file. Type: Default: Your OS's new line, mostly: Required: spacingHow should the sitemap xml file be spaced. You can use Type: Default: Required: noindexExclude pages from the sitemap when the Type: Default: Required: imagesFor generate sitemap for images per page, just enable images flag to Type: Default: Required: mappingsAn object to custom map pages to their own configuration. This should be an array with the following structure: Type: Default: Required: Example: mappings: [{
pages: [ 'minimatch pattern' ],
changefreq: 'hourly',
priority: 0.5,
lastmod: Date.now(),
getLoc(siteUrl, loc, entry) {
// Removes the file extension if it exists
return loc.replace(/\.\w+$/, '');
},
hreflang: [{
lang: 'ru',
getHref(siteUrl, file, lang, loc) {
return 'http://www.amazon.ru/' + file;
}
}]
},
//....
]
pagesType: Required: This is an array with minimatch patterns to match the relevant pages to override. Every file will be matched against the supplied patterns. Uses multimatch to match patterns against filenames. Example: hreflangMatching pages can get their The input is an array like so: hreflang: [{
lang: 'ru',
getHref: function(siteUrl, file, lang, loc) {
// return href src for the hreflang. For example:
return 'http://www.amazon.ru/' + file;
}
}] getLocMatching pages can get their getLoc: function(siteUrl, loc, entry) {
return loc.replace(/\.\w+$/, '');
} verboseType: Required: Default: If true, will log the number of files that where handled. Complementary plugins
ThanksTo grunt-sitemap for the inspiration on writing this. LicenseMIT © Gilad Peleg |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论