Skip to content

Commit

Permalink
fix(rel): fix bug causes by sitemap.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
uiolee committed May 1, 2023
1 parent 1c29991 commit d2bc10e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/rel.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'use strict';

const { url_for } = require('hexo-util');
const { extname } = require('path');

function relSitemapInject(data) {
const { path, rel } = this.config.sitemap;
const { path, rel, relPath } = this.config.sitemap;
const rPath = relPath ? relPath : path.filter(p => { return extname(p) === '.xml'; })[0];

if (!rel || data.match(/rel=['|"]?sitemap['|"]?/i)) return;
if (!rel || !rPath || data.match(/rel=['|"]?sitemap['|"]?/i)) return;

const relSitemap = `<link rel="sitemap" type="application/xml" title="Sitemap" href="${url_for.call(this, path)}">`;
const relSitemap = `<link rel="sitemap" type="application/xml" title="Sitemap" href="${url_for.call(this, rPath)}">`;

return data.replace(/<head>(?!<\/head>).+?<\/head>/s, str => str.replace('</head>', `${relSitemap}</head>`));
}
Expand Down

0 comments on commit d2bc10e

Please sign in to comment.