hexo-plugin-aurora
Advanced tools
Comparing version
@@ -0,1 +1,15 @@ | ||
# [1.8.0](https://github.com/auroral-ui/hexo-plugin-aurora/compare/v1.7.0...v1.8.0) (2023-09-10) | ||
### Bug Fixes | ||
* gitalk cdn unpkg link ([a9ec8e0](https://github.com/auroral-ui/hexo-plugin-aurora/commit/a9ec8e0b93253f71c3e08ab04b284978c9a96dcd)) | ||
### Features | ||
* add algolia search command ([a8ede74](https://github.com/auroral-ui/hexo-plugin-aurora/commit/a8ede7462337893243581991be79bbb22cc44dbc)) | ||
* add shiki code highlight engine replacing prism ([dd066a5](https://github.com/auroral-ui/hexo-plugin-aurora/commit/dd066a5c4c8c62ec8e3929103e690561c95588b1)) | ||
* change all CDN to use unpkg so it auto use latest minor versions ([ea826cc](https://github.com/auroral-ui/hexo-plugin-aurora/commit/ea826cc12dbaf49adf43db153b0fe4da3fb7f269)) | ||
# [1.7.0](https://github.com/auroral-ui/hexo-plugin-aurora/compare/v1.6.0...v1.7.0) (2023-08-18) | ||
@@ -2,0 +16,0 @@ |
@@ -8,2 +8,3 @@ const appRoot = require('app-root-path'); | ||
require('./lib/injector')(hexo); | ||
require('./lib/commands')(hexo); | ||
@@ -10,0 +11,0 @@ var themePack; |
@@ -1,107 +0,4 @@ | ||
const chalk = require('chalk'); | ||
const { throwError } = require('../helpers/utils'); | ||
const QUOTE_REGEX = | ||
/<p>:{3}([a-zA-Z0-9]+)\s?([\s\S]*?)(?:<\/p>\n|<br>)([\s\S]*?)(?:<p>|<br>):{3}<\/p>/gm; | ||
const QUOTE_TYPES = ['tip', 'warning', 'danger', 'details']; | ||
const TAG_REGEX = /^<\/?([ul|ol|p]+)>/g; | ||
const BLOCKQUOTE_REGEX = /<blockquote>\n([\s\S]*?)\n<\/blockquote>/gm; | ||
const QUOTE_LANG = { | ||
en: { | ||
tip: 'TIP', | ||
warning: 'WARNING', | ||
danger: 'WARNING', | ||
details: 'Details' | ||
}, | ||
cn: { | ||
tip: '提示', | ||
warning: '注意', | ||
danger: '特别注意', | ||
details: '隐藏内容' | ||
} | ||
}; | ||
const SVG = { | ||
tip: `<svg width="24" height="24" viewBox="0 0 24 24" fill="" xmlns="http://www.w3.org/2000/svg" data-reactroot=""> | ||
<path fill="" d="M20.86 14.13C20 14.7 19.56 15.74 19.77 16.76C20.13 18.55 18.55 20.13 16.76 19.77C15.74 19.57 14.7 20 14.13 20.86C13.12 22.38 10.89 22.38 9.88 20.86C9.3 20 8.26 19.56 7.24 19.77C5.45 20.13 3.87 18.55 4.23 16.76C4.43 15.74 4 14.7 3.14 14.13C1.62 13.12 1.62 10.89 3.14 9.88C4 9.3 4.44 8.26 4.23 7.24C3.87 5.45 5.45 3.87 7.24 4.23C8.26 4.44 9.3 4 9.87 3.14C10.88 1.62 13.11 1.62 14.12 3.14C14.7 4 15.74 4.44 16.76 4.23C18.55 3.87 20.13 5.45 19.77 7.24C19.56 8.26 20 9.3 20.86 9.87C22.38 10.88 22.38 13.12 20.86 14.13Z" undefined="1"></path> | ||
<path stroke-linejoin="round" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" stroke="" d="M12.01 15C12.01 14.5 12.01 14.5 12.01 14.5C12.04 13.75 13 13.46 14.04 12.2C14.41 11.74 14.69 11.41 14.86 10.85C15.15 9.95 14.92 9.18 14.86 9.02C14.8 8.79 14.52 8 13.72 7.46C13.06 7.02 12.42 7 12.14 7C11.9 7 11.36 7 10.78 7.3C10.28 7.56 9.98 7.9 9.83 8.1C9.24 8.82 9.06 9.63 9 10.06"></path> | ||
<path stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" stroke="" d="M11.99 18H12.01"></path> | ||
</svg>`, | ||
warning: `<svg width="24" height="24" viewBox="0 0 24 24" fill="" xmlns="http://www.w3.org/2000/svg" data-reactroot=""> | ||
<path fill="" d="M20.86 14.13C20 14.7 19.56 15.74 19.77 16.76C20.13 18.55 18.55 20.13 16.76 19.77C15.74 19.57 14.7 20 14.13 20.86C13.12 22.38 10.89 22.38 9.88 20.86C9.3 20 8.26 19.56 7.24 19.77C5.45 20.13 3.87 18.55 4.23 16.76C4.43 15.74 4 14.7 3.14 14.13C1.62 13.12 1.62 10.89 3.14 9.88C4 9.3 4.44 8.26 4.23 7.24C3.87 5.45 5.45 3.87 7.24 4.23C8.26 4.44 9.3 4 9.87 3.14C10.88 1.62 13.11 1.62 14.12 3.14C14.7 4 15.74 4.44 16.76 4.23C18.55 3.87 20.13 5.45 19.77 7.24C19.56 8.26 20 9.3 20.86 9.87C22.38 10.88 22.38 13.12 20.86 14.13Z" undefined="1"></path> | ||
<path stroke-linejoin="round" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" stroke="" d="M12 8V13"></path> | ||
<path stroke-linejoin="round" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" stroke="" d="M12 15.99V16.01"></path> | ||
</svg> | ||
`, | ||
danger: `<svg width="24" height="24" viewBox="0 0 24 24" fill="" xmlns="http://www.w3.org/2000/svg" data-reactroot=""> | ||
<path fill="" d="M19.76 5.23C15.84 5.23 12 2 12 2C12 2 8.15996 5.23 4.23996 5.23C4.23996 5.23 1.86996 16.99 12 22C22.13 16.99 19.76 5.23 19.76 5.23Z" undefined="1"></path> | ||
<path stroke-linejoin="round" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" stroke="" d="M12 8V13"></path> | ||
<path stroke-linejoin="round" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" stroke="" d="M11.99 16H12"></path> | ||
</svg> | ||
`, | ||
blockquote: `<svg width="24" height="24" viewBox="0 0 24 24" fill="" xmlns="http://www.w3.org/2000/svg" data-reactroot=""> | ||
<path fill="" d="M22 12C22 6.5 17.5 2 12 2C6.5 2 2 6.5 2 12C2 17.5 6.5 22 12 22C13.8 22 15.5 21.5 17 20.6L22 22L20.7 17C21.5 15.5 22 13.8 22 12Z" undefined="1"></path> | ||
<path fill="" d="M15.97 11.5H16.04C17.12 11.5 18 12.38 18 13.47V13.53C18 14.62 17.12 15.5 16.03 15.5H15.96C14.88 15.5 14 14.62 14 13.53V13.46C14 12.38 14.88 11.5 15.97 11.5Z" undefined="1"></path> | ||
<path fill="" d="M7.97 11.5H8.04C9.12 11.5 10 12.38 10 13.47V13.53C10 14.62 9.12 15.5 8.03 15.5H7.97C6.88 15.5 6 14.62 6 13.53V13.46C6 12.38 6.88 11.5 7.97 11.5Z" undefined="1"></path> | ||
<path stroke-linejoin="round" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" stroke="" d="M17 8.5C15.23 8.97 14.07 10.84 14.01 13.27C14 13.33 14 13.4 14 13.47V13.5"></path> | ||
<path stroke-linejoin="round" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" stroke="" d="M9 8.5C7.23 8.97 6.07 10.84 6.01 13.27C6 13.33 6 13.4 6 13.47V13.5"></path> | ||
<path stroke-linejoin="round" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" stroke="" d="M15.97 11.5H16.04C17.12 11.5 18 12.38 18 13.47V13.53C18 14.62 17.12 15.5 16.03 15.5H15.96C14.88 15.5 14 14.62 14 13.53V13.46C14 12.38 14.88 11.5 15.97 11.5Z"></path> | ||
<path stroke-linejoin="round" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" stroke="" d="M7.97 11.5H8.04C9.12 11.5 10 12.38 10 13.47V13.53C10 14.62 9.12 15.5 8.03 15.5H7.97C6.88 15.5 6 14.62 6 13.53V13.46C6 12.38 6.88 11.5 7.97 11.5Z"></path> | ||
</svg> | ||
` | ||
}; | ||
module.exports = function (hexo) { | ||
const themeConfig = Object.assign(hexo.theme.config || {}, hexo.config.theme_config); | ||
if (!themeConfig.site) { | ||
throwError( | ||
'Aurora Config Error', | ||
`Theme config ${chalk.cyan( | ||
'site' | ||
)} attribute is missing, please check the theme config template here: https://github.com/auroral-ui/hexo-theme-aurora/blob/main/_config.yml.` | ||
); | ||
return; | ||
} | ||
if (!themeConfig.site.language) { | ||
throwError( | ||
'Aurora Config Error', | ||
`Theme config ${chalk.cyan( | ||
'site -> language' | ||
)} attribute is missing, please check the theme config template here: https://github.com/auroral-ui/hexo-theme-aurora/blob/main/_config.yml.` | ||
); | ||
return; | ||
} | ||
const lang = themeConfig.site.language; | ||
hexo.extend.filter.register('after_post_render', function (data) { | ||
/** Filter and render Custom Quote Blocks */ | ||
data.content = data.content.replace(QUOTE_REGEX, (matchedQuote, p1, p2, p3) => { | ||
let context, | ||
template = matchedQuote; | ||
if (p1 && QUOTE_TYPES.indexOf(p1) !== -1) { | ||
context = { | ||
type: p1, | ||
title: p2 ? p2 : QUOTE_LANG[lang][p1], | ||
content: TAG_REGEX.test(p3) ? p3 : `<p>${p3}</p>` | ||
}; | ||
if (context.type === 'details') { | ||
template = `<details class="custom-details">\n<summary>${context.title}</summary>\n${context.content}\n</details>`; | ||
} else { | ||
template = `<div class="custom-quote ${context.type}">\n<span class="custom-quote-svg">${ | ||
SVG[context.type] | ||
}</span>\n<p class="custom-quote-title">${context.title}</p>\n${context.content}\n</div>`; | ||
} | ||
} | ||
return template; | ||
}); | ||
/** Filter and render BlockQuote */ | ||
data.content = data.content.replace( | ||
BLOCKQUOTE_REGEX, | ||
`<blockquote><span class="custom-blockquote-svg">${SVG['blockquote']}</span>$1</blockquote>` | ||
); | ||
return data; | ||
}); | ||
require('./afterPostRender')(hexo); | ||
require('./beforePostRender')(hexo); | ||
}; |
@@ -94,5 +94,2 @@ /** | ||
const siteG = new SiteGenerator(configs); | ||
apiData = siteG.addSiteConfig(apiData); | ||
const categories = new CategoryGenerator(site.categories, site.posts, configs); | ||
@@ -117,7 +114,10 @@ apiData = categories.addCategories(apiData); | ||
const search = new SearchGenerator(posts.data); | ||
const search = new SearchGenerator(posts.data, configs); | ||
apiData = search.addSearchIndex(apiData); | ||
const siteG = new SiteGenerator(configs); | ||
apiData = siteG.addSiteConfig(apiData); | ||
return apiData; | ||
} | ||
}; |
@@ -15,3 +15,3 @@ const { postMapper, postListMapper } = require('../helpers/mapper'); | ||
constructor(posts, configs) { | ||
constructor(posts, configs, options = { sort: true }) { | ||
this.data = posts; | ||
@@ -22,3 +22,3 @@ this.fullData = posts; | ||
this.isFeature = this.configs.theme_config.theme.feature; | ||
this.transform(); | ||
this.transform(options); | ||
} | ||
@@ -30,3 +30,3 @@ | ||
*/ | ||
transform() { | ||
transform(options = { sort: true }) { | ||
if (this.count() <= 0) return; | ||
@@ -39,3 +39,5 @@ | ||
// Used when feature posts is not enough | ||
this.sortByDate(); | ||
if (options.sort) { | ||
this.sortByDate(); | ||
} | ||
this.reorderFeaturePosts(); | ||
@@ -42,0 +44,0 @@ |
@@ -1,20 +0,21 @@ | ||
const { searchMapper } = require('../helpers/mapper') | ||
const { searchMapper } = require('../helpers/mapper'); | ||
class SearchGenerator { | ||
data = [] | ||
data = []; | ||
configs = {}; | ||
constructor(posts) { | ||
this.data = posts.map(searchMapper) | ||
constructor(posts, configs) { | ||
this.data = configs.theme_config.algolia?.enable ? [] : posts.map((post) => searchMapper(post)); | ||
} | ||
addSearchIndex(data) { | ||
if (this.data.length <= 0) return data | ||
if (this.data.length <= 0) return data; | ||
data.push({ | ||
path: 'api/search.json', | ||
data: JSON.stringify(this.data) | ||
}) | ||
return data | ||
}); | ||
return data; | ||
} | ||
} | ||
module.exports = SearchGenerator | ||
module.exports = SearchGenerator; |
@@ -33,9 +33,12 @@ const appRoot = require('app-root-path'); | ||
addSiteConfig(data) { | ||
const configs = this.data; | ||
const tempConfigs = this.data; | ||
// Removed privacy data from site configs | ||
delete configs.deploy; | ||
delete configs.server; | ||
delete tempConfigs.deploy; | ||
delete tempConfigs.server; | ||
tempConfigs.theme_config.algolia = { | ||
enable: this.data.theme_config.algolia?.enable ?? false | ||
}; | ||
data.push({ | ||
path: 'api/site.json', | ||
data: JSON.stringify(configs) | ||
data: JSON.stringify(tempConfigs) | ||
}); | ||
@@ -42,0 +45,0 @@ return data; |
@@ -39,3 +39,3 @@ const symbolsCountTime = require('./symbols-count-time'); | ||
text: truncateHTML(abstract, abstractLength), | ||
link: post.link, | ||
permalink: `/post/${pathSlug}`, | ||
photos: post.photos, | ||
@@ -110,3 +110,3 @@ count_time: symbolsCountTime(post.content), | ||
text: post.text, | ||
link: post.link, | ||
permalink: post.permalink, | ||
photos: post.photos, | ||
@@ -113,0 +113,0 @@ count_time: post.count_time, |
@@ -144,2 +144,6 @@ const crypto = require('crypto'); | ||
exports.throwWarning = function (type, msg) { | ||
console.warn(`${chalk.yellow(`[${type}]`)} ${chalk.white(msg)}`); | ||
}; | ||
exports.throwInfo = function (type, msg) { | ||
@@ -146,0 +150,0 @@ console.error(`${chalk.blue(`[${type}]`)} ${chalk.white(msg)}`); |
{ | ||
"name": "hexo-plugin-aurora", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "A plugin for Hexo Aurora theme", | ||
@@ -17,2 +17,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"algoliasearch": "^4.19.1", | ||
"app-root-path": "^3.1.0", | ||
@@ -23,2 +24,4 @@ "chalk": "^4", | ||
"js-yaml": "^4.1.0", | ||
"shiki": "^0.14.4", | ||
"striptags": "^3.2.0", | ||
"truncate-html": "^1.0.4" | ||
@@ -25,0 +28,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
70773
25.81%28
33.33%1862
31.68%9
50%10
66.67%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added