mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Removed change frequency and priority fields from sitemap generator (#9771)
closes #9765 - Google says that change frequency and priority are not important when search engines crawl through pages. Therefore, these two properties are unimportant and removed from Ghost. Reference: https://www.seroundtable.com/google-priority-change-frequency-xml-sitemap-20273.html - Credits to @damanm24
This commit is contained in:
parent
e3234bce6c
commit
214d682ea3
7 changed files with 7 additions and 92 deletions
|
@ -3,8 +3,7 @@ const _ = require('lodash'),
|
||||||
moment = require('moment'),
|
moment = require('moment'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
urlService = require('../../../services/url'),
|
urlService = require('../../../services/url'),
|
||||||
localUtils = require('./utils'),
|
localUtils = require('./utils');
|
||||||
CHANGE_FREQ = 'weekly';
|
|
||||||
|
|
||||||
// Sitemap specific xml namespace declarations that should not change
|
// Sitemap specific xml namespace declarations that should not change
|
||||||
const XMLNS_DECLS = {
|
const XMLNS_DECLS = {
|
||||||
|
@ -65,10 +64,6 @@ class BaseSiteMapGenerator {
|
||||||
this.lastModified = Date.now();
|
this.lastModified = Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
getPriorityForDatum() {
|
|
||||||
return 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
getLastModifiedForDatum(datum) {
|
getLastModifiedForDatum(datum) {
|
||||||
return datum.updated_at || datum.published_at || datum.created_at;
|
return datum.updated_at || datum.published_at || datum.created_at;
|
||||||
}
|
}
|
||||||
|
@ -82,15 +77,12 @@ class BaseSiteMapGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
createUrlNodeFromDatum(url, datum) {
|
createUrlNodeFromDatum(url, datum) {
|
||||||
const priority = this.getPriorityForDatum(datum);
|
|
||||||
let node, imgNode;
|
let node, imgNode;
|
||||||
|
|
||||||
node = {
|
node = {
|
||||||
url: [
|
url: [
|
||||||
{loc: url},
|
{loc: url},
|
||||||
{lastmod: moment(this.getLastModifiedForDatum(datum)).toISOString()},
|
{lastmod: moment(this.getLastModifiedForDatum(datum)).toISOString()}
|
||||||
{changefreq: CHANGE_FREQ},
|
|
||||||
{priority: priority}
|
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,6 @@ class PageMapGenerator extends BaseMapGenerator {
|
||||||
|
|
||||||
_.extend(this, opts);
|
_.extend(this, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @TODO:
|
|
||||||
* We could influence this with priority or meta information
|
|
||||||
*/
|
|
||||||
getPriorityForDatum(page) {
|
|
||||||
return page && page.staticRoute ? 1.0 : 0.8;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = PageMapGenerator;
|
module.exports = PageMapGenerator;
|
||||||
|
|
|
@ -9,11 +9,6 @@ class PostMapGenerator extends BaseMapGenerator {
|
||||||
|
|
||||||
_.extend(this, opts);
|
_.extend(this, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
getPriorityForDatum(post) {
|
|
||||||
// give a slightly higher priority to featured posts
|
|
||||||
return post.featured ? 0.9 : 0.8;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = PostMapGenerator;
|
module.exports = PostMapGenerator;
|
||||||
|
|
|
@ -8,14 +8,6 @@ class TagsMapGenerator extends BaseMapGenerator {
|
||||||
this.name = 'tags';
|
this.name = 'tags';
|
||||||
_.extend(this, opts);
|
_.extend(this, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @TODO:
|
|
||||||
* We could influence this with priority or meta information
|
|
||||||
*/
|
|
||||||
getPriorityForDatum() {
|
|
||||||
return 0.6;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = TagsMapGenerator;
|
module.exports = TagsMapGenerator;
|
||||||
|
|
|
@ -10,14 +10,6 @@ class UserMapGenerator extends BaseMapGenerator {
|
||||||
_.extend(this, opts);
|
_.extend(this, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @TODO:
|
|
||||||
* We could influence this with priority or meta information
|
|
||||||
*/
|
|
||||||
getPriorityForDatum() {
|
|
||||||
return 0.6;
|
|
||||||
}
|
|
||||||
|
|
||||||
validateImageUrl(imageUrl) {
|
validateImageUrl(imageUrl) {
|
||||||
return imageUrl && validator.isURL(imageUrl, {protocols: ['http', 'https'], require_protocol: true});
|
return imageUrl && validator.isURL(imageUrl, {protocols: ['http', 'https'], require_protocol: true});
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,9 +100,7 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th width="70%">URL (<xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> total)</th>
|
<th width="70%">URL (<xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> total)</th>
|
||||||
<th title="Priority" width="5%">Prio</th>
|
<th width="15%">Images</th>
|
||||||
<th width="5%">Images</th>
|
|
||||||
<th title="Change Frequency" width="5%">Ch. Freq.</th>
|
|
||||||
<th title="Last Modification Time" width="15%">Last Modified</th>
|
<th title="Last Modification Time" width="15%">Last Modified</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -119,15 +117,9 @@
|
||||||
<xsl:value-of select="sitemap:loc"/>
|
<xsl:value-of select="sitemap:loc"/>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
<xsl:value-of select="concat(sitemap:priority*100,'%')"/>
|
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
<xsl:value-of select="count(image:image)"/>
|
<xsl:value-of select="count(image:image)"/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
<xsl:value-of select="concat(translate(substring(sitemap:changefreq, 1, 1),concat($lower, $upper),concat($upper, $lower)),substring(sitemap:changefreq, 2))"/>
|
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
<xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/>
|
<xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -21,9 +21,9 @@ should.Assertion.add('ValidUrlNode', function (options) {
|
||||||
urlNode.url.should.be.an.Array();
|
urlNode.url.should.be.an.Array();
|
||||||
|
|
||||||
if (options.withImage) {
|
if (options.withImage) {
|
||||||
urlNode.url.should.have.lengthOf(5);
|
urlNode.url.should.have.lengthOf(3);
|
||||||
} else {
|
} else {
|
||||||
urlNode.url.should.have.lengthOf(4);
|
urlNode.url.should.have.lengthOf(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,8 +31,6 @@ should.Assertion.add('ValidUrlNode', function (options) {
|
||||||
* { url:
|
* { url:
|
||||||
* [ { loc: 'http://127.0.0.1:2369/author/' },
|
* [ { loc: 'http://127.0.0.1:2369/author/' },
|
||||||
* { lastmod: '2014-12-22T11:54:00.100Z' },
|
* { lastmod: '2014-12-22T11:54:00.100Z' },
|
||||||
* { changefreq: 'weekly' },
|
|
||||||
* { priority: 0.6 },
|
|
||||||
* { 'image:image': [
|
* { 'image:image': [
|
||||||
* { 'image:loc': 'post-100.jpg' },
|
* { 'image:loc': 'post-100.jpg' },
|
||||||
* { 'image:caption': 'post-100.jpg' }
|
* { 'image:caption': 'post-100.jpg' }
|
||||||
|
@ -42,9 +40,9 @@ should.Assertion.add('ValidUrlNode', function (options) {
|
||||||
flatNode = _.extend.apply(_, urlNode.url);
|
flatNode = _.extend.apply(_, urlNode.url);
|
||||||
|
|
||||||
if (options.withImage) {
|
if (options.withImage) {
|
||||||
flatNode.should.be.an.Object().with.keys('loc', 'lastmod', 'changefreq', 'priority', 'image:image');
|
flatNode.should.be.an.Object().with.keys('loc', 'lastmod', 'image:image');
|
||||||
} else {
|
} else {
|
||||||
flatNode.should.be.an.Object().with.keys('loc', 'lastmod', 'changefreq', 'priority');
|
flatNode.should.be.an.Object().with.keys('loc', 'lastmod');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -84,20 +82,6 @@ describe('Generators', function () {
|
||||||
generator = new PostGenerator();
|
generator = new PostGenerator();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('fn: getPriorityForDatum', function () {
|
|
||||||
it('uses 0.9 priority for featured posts', function () {
|
|
||||||
generator.getPriorityForDatum({
|
|
||||||
featured: true
|
|
||||||
}).should.equal(0.9);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('uses 0.8 priority for all other (non-featured) posts', function () {
|
|
||||||
generator.getPriorityForDatum({
|
|
||||||
featured: false
|
|
||||||
}).should.equal(0.8);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('fn: createNodeFromDatum', function () {
|
describe('fn: createNodeFromDatum', function () {
|
||||||
it('adds an image:image element if post has a cover image', function () {
|
it('adds an image:image element if post has a cover image', function () {
|
||||||
const urlNode = generator.createUrlNodeFromDatum('https://myblog.com/test/', testUtils.DataGenerator.forKnex.createPost({
|
const urlNode = generator.createUrlNodeFromDatum('https://myblog.com/test/', testUtils.DataGenerator.forKnex.createPost({
|
||||||
|
@ -221,30 +205,12 @@ describe('Generators', function () {
|
||||||
generator.siteMapContent.match(/<loc>/g).length.should.eql(3);
|
generator.siteMapContent.match(/<loc>/g).length.should.eql(3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('fn: getPriorityForDatum', function () {
|
|
||||||
it('uses 1 priority for static routes', function () {
|
|
||||||
generator.getPriorityForDatum({
|
|
||||||
staticRoute: true
|
|
||||||
}).should.equal(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('uses 0.8 priority for static pages or collection indexes', function () {
|
|
||||||
generator.getPriorityForDatum({}).should.equal(0.8);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('TagGenerator', function () {
|
describe('TagGenerator', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
generator = new TagGenerator();
|
generator = new TagGenerator();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('fn: getPriorityForDatum', function () {
|
|
||||||
it('uses 0.6 priority for all tags', function () {
|
|
||||||
generator.getPriorityForDatum({}).should.equal(0.6);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('UserGenerator', function () {
|
describe('UserGenerator', function () {
|
||||||
|
@ -252,12 +218,6 @@ describe('Generators', function () {
|
||||||
generator = new UserGenerator();
|
generator = new UserGenerator();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('fn: getPriorityForDatum', function () {
|
|
||||||
it('uses 0.6 priority for author links', function () {
|
|
||||||
generator.getPriorityForDatum({}).should.equal(0.6);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('fn: validateImageUrl', function () {
|
describe('fn: validateImageUrl', function () {
|
||||||
it('image url is localhost', function () {
|
it('image url is localhost', function () {
|
||||||
generator.validateImageUrl('http://localhost:2368/content/images/1.jpg').should.be.true();
|
generator.validateImageUrl('http://localhost:2368/content/images/1.jpg').should.be.true();
|
||||||
|
|
Loading…
Add table
Reference in a new issue