-
-
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: Do not check if meta_generator has been injected before.
- Loading branch information
1 parent
584b093
commit 915c507
Showing
2 changed files
with
10 additions
and
7 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,13 +1,16 @@ | ||
'use strict'; | ||
|
||
let hexoGeneratorTag; | ||
function hexoMetaGeneratorInject(data) { | ||
const { config } = this; | ||
if (!config.meta_generator | ||
|| data.match(/<meta([\s]+|[\s]+[^<>]+[\s]+)name=['|"]?generator['|"]?/i)) return; | ||
if (!config.meta_generator) { | ||
this.extend.filter.unregister('after_route_render', hexoMetaGeneratorInject); | ||
return; | ||
} | ||
|
||
const hexoGeneratorTag = `<meta name="generator" content="Hexo ${this.version}">`; | ||
hexoGeneratorTag = hexoGeneratorTag || `<meta name="generator" content="Hexo ${this.version}"></head>`; | ||
|
||
return data.replace(/<head>(?!<\/head>).+?<\/head>/s, str => str.replace('</head>', `${hexoGeneratorTag}</head>`)); | ||
return data.replace('</head>', 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