-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(meta_generator): drop cheerio (#3671)
* refactor(meta_generator): drop cheerio * fix(meta_generator): append to </title> * test(meta_generator): remove irrelevant head tag test * test(render): disable meta_generator * fix(meta_generator): do not append if there is existing tag, regardless the value of 'content' * test(open_generator): test existing generator tag * test(meta_generator): tag should be added only once Previous commit only works on post, not page This reverts commit 325f303.
- Loading branch information
Showing
3 changed files
with
15 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,14 @@ | ||
'use strict'; | ||
|
||
let cheerio; | ||
const hexoGeneratorTag = '<meta name="generator" content="Hexo %s" />'; | ||
|
||
function hexoMetaGeneratorInject(data) { | ||
const { config } = this; | ||
if (!config.meta_generator) return; | ||
|
||
if (!cheerio) cheerio = require('cheerio'); | ||
const $ = cheerio.load(data, {decodeEntities: false}); | ||
if (!config.meta_generator || | ||
data.match(/<meta\s+name=['|"]?generator['|"]?/i)) return; | ||
|
||
if (!($('meta[name="generator"]').length > 0) && | ||
$('head').contents().length > 0) { | ||
$('head').prepend(hexoGeneratorTag.replace('%s', this.version)); | ||
const hexoGeneratorTag = '<meta name="generator" content="Hexo %s">' | ||
.replace('%s', this.version); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
tomap
Contributor
|
||
|
||
return $.html(); | ||
} | ||
return data.replace('</title>', '</title>' + hexoGeneratorTag); | ||
} | ||
|
||
module.exports = hexoMetaGeneratorInject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@curbengh After reviewing this, I am thinking could we use template string instead of
replace()
?Even without template string is ok: