mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Closes #623 - Add basic init and eventing scaffold - Add sitemap-index.xml generation - Broke out generators to individual files, added request handler - Add page, author and tag xml files; add index mapping - Add SiteMapManager unit tests - Add Generators tests - Cache invalidation headers for sitemap-*.xml - Redirect sitemap.xml to index and rename to sitemap-index - Handle page convert and publish/draft changes - Add very basic functional test for route existence - Add cache headers to sitemap routes
65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
var _ = require('lodash'),
|
|
path = require('path'),
|
|
api = require('../../api'),
|
|
BaseMapGenerator = require('./base-generator'),
|
|
config = require('../../config');
|
|
|
|
// A class responsible for generating a sitemap from posts and keeping it updated
|
|
function UserMapGenerator(opts) {
|
|
_.extend(this, _.defaults(opts || {}, UserMapGenerator.Defaults));
|
|
|
|
BaseMapGenerator.apply(this, arguments);
|
|
}
|
|
|
|
UserMapGenerator.Defaults = {
|
|
// TODO?
|
|
};
|
|
|
|
// Inherit from the base generator class
|
|
_.extend(UserMapGenerator.prototype, BaseMapGenerator.prototype);
|
|
|
|
_.extend(UserMapGenerator.prototype, {
|
|
getData: function () {
|
|
return api.users.browse({
|
|
context: {
|
|
internal: true
|
|
}
|
|
}).then(function (resp) {
|
|
return resp.users;
|
|
});
|
|
},
|
|
|
|
getUrlForDatum: function (user, permalinks) {
|
|
return config.urlFor('author', {author: user, permalinks: permalinks}, true);
|
|
},
|
|
|
|
getPriorityForDatum: function () {
|
|
// TODO: We could influence this with meta information
|
|
return 0.6;
|
|
},
|
|
|
|
createUrlNodeFromDatum: function (datum) {
|
|
var orig = BaseMapGenerator.prototype.createUrlNodeFromDatum.apply(this, arguments),
|
|
imageUrl,
|
|
imageEl;
|
|
|
|
// Check for image and add it
|
|
if (datum.image) {
|
|
// Grab the image url
|
|
imageUrl = this.getUrlForImage(datum.image);
|
|
// Create the weird xml node syntax structure that is expected
|
|
imageEl = [
|
|
{'image:loc': imageUrl},
|
|
{'image:caption': path.basename(imageUrl)}
|
|
];
|
|
// Add the node to the url xml node
|
|
orig.url.push({
|
|
'image:image': imageEl
|
|
});
|
|
}
|
|
|
|
return orig;
|
|
}
|
|
});
|
|
|
|
module.exports = UserMapGenerator;
|