Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryaang committed Nov 2, 2023
2 parents 159bdf3 + a3bea54 commit 9eae35d
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 83 deletions.
28 changes: 0 additions & 28 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
## [1.0.4](https://github.com/Tim-Saijun/hexo-plugin-aurora-s/compare/v1.0.3...v1.0.4) (2023-11-01)


### Bug Fixes

* 混滚到1.7.0以使用primjs高亮 ([9adb207](https://github.com/Tim-Saijun/hexo-plugin-aurora-s/commit/9adb207004f90e5cfbb2725c2042c2a002328f33))

## [1.0.3](https://github.com/Tim-Saijun/hexo-plugin-aurora-s/compare/v1.0.2...v1.0.3) (2023-11-01)


### Reverts

* Revert "fix: shiki回滚" ([ab679db](https://github.com/Tim-Saijun/hexo-plugin-aurora-s/commit/ab679dbde988d7e915b9da75bb725f52a4c3b015))

## [1.0.2](https://github.com/Tim-Saijun/hexo-plugin-aurora-s/compare/v1.0.1...v1.0.2) (2023-11-01)


### Bug Fixes

* shiki回滚 ([86c56af](https://github.com/Tim-Saijun/hexo-plugin-aurora-s/commit/86c56af83abb8798bf0d67c8f00539b09d07cc57))

## [1.0.1](https://github.com/Tim-Saijun/hexo-plugin-aurora-s/compare/v1.0.0...v1.0.1) (2023-10-31)


### Bug Fixes

* 增加重命名提示 ([9335d52](https://github.com/Tim-Saijun/hexo-plugin-aurora-s/commit/9335d5267bd7ce0b887aae2c7f80219d14a221e7))

# 1.0.0 (2023-10-31)


Expand Down
22 changes: 14 additions & 8 deletions data/cn.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
scripts:
- <script rel="prefetch" async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
- <script rel="preload" src="https://unpkg.com/blueimp-md5@^2.19.0/js/md5.min.js"></script>
- <script rel="preload" src="https://unpkg.com/lodash@^4.17.21/lodash.min.js"></script>
- <script rel="preload" src="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/prism/1.29.0/components/prism-core.js" data-manual></script>
- <script rel="preload" src="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.js"></script>
- <script rel="preload" src="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/prism/1.29.0/plugins/toolbar/prism-toolbar.min.js"></script>
- <script rel="preload" src="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/prism/1.29.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js"></script>
- <script rel="preload" src="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/blueimp-md5/2.19.0/js/md5.min.js"></script>
- <script rel="preload" src="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>

css:
- <link rel="stylesheet" href="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/prism/1.29.0/themes/prism.min.css"/>
- <link rel="stylesheet" href="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/prism/1.29.0/plugins/toolbar/prism-toolbar.min.css"/>
- <link rel="stylesheet" href="https://fonts.loli.net/css?family=Rubik" />

plugins:
gitalk:
- <script rel="preload" src="https://unpkg.com/gitalk@^1.8.0/dist/gitalk.min.js"></script>
- <link rel="stylesheet" href="https://unpkg.com/gitalk@^1.8.0/dist/gitalk.css"/>
- <script rel="preload" src="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/gitalk/1.8.0/gitalk.min.js"></script>
- <link rel="stylesheet" href="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/gitalk/1.8.0/gitalk.min.css"/>
valine:
- <script rel="preload" src="https://unpkg.com/valine@^1.5.1/dist/Valine.min.js"></script>
- <script rel="preload" src="https://unpkg.com/leancloud-storage@^4.15.0/dist/av-min.js"></script>
- <script rel="preload" src="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/valine/1.5.1/Valine.min.js"></script>
- <script rel="preload" src="https://cdn.jsdelivr.net/npm/leancloud-storage@latest/dist/av-min.js"></script>
twikoo:
- <script rel="preload" src="https://unpkg.com/twikoo@^1.6.17/dist/twikoo.all.min.js"></script>
- <script rel="preload" src="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/twikoo/1.6.17/twikoo.all.min.js"></script>
waline:
- <link rel="stylesheet" href="https://unpkg.com/@waline/client@v2/dist/waline.css"/>
- <link rel="stylesheet" href="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/waline/2.15.5/waline.min.css"/>
24 changes: 15 additions & 9 deletions data/en.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
scripts:
- <script rel="prefetch" async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
- <script rel="preload" src="https://unpkg.com/blueimp-md5@^2.19.0/js/md5.min.js"></script>
- <script rel="preload" src="https://unpkg.com/lodash@^4.17.21/lodash.min.js"></script>
- <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/[email protected]/components/prism-core.min.js" data-manual></script>
- <script src="https://cdn.jsdelivr.net/npm/[email protected]/plugins/autoloader/prism-autoloader.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/[email protected]/plugins/toolbar/prism-toolbar.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/[email protected]/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/[email protected]/js/md5.min.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script>

css:
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/themes/prism.min.css"/>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/plugins/toolbar/prism-toolbar.css"/>
- <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Rubik"/>

plugins:
gitalk:
- <script rel="preload" src="https://unpkg.com/gitalk@^1.8.0/dist/gitalk.min.js"></script>
- <link rel="stylesheet" href="https://unpkg.com/gitalk@^1.8.0/dist/gitalk.css"/>
- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/gitalk.min.js"></script>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/gitalk.css">
valine:
- <script rel="preload" src="https://unpkg.com/valine@^1.5.1/dist/Valine.min.js"></script>
- <script rel="preload" src="https://unpkg.com/leancloud-storage@^4.15.0/dist/av-min.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Valine.min.js"></script>
- <script rel="preload" src="https://cdn.jsdelivr.net/npm/leancloud-storage@latest/dist/av-min.js"></script>
twikoo:
- <script rel="preload" src="https://unpkg.com/twikoo@^1.6.17/dist/twikoo.all.min.js"></script>
- <script rel="preload" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/twikoo.all.min.js"></script>
waline:
- <link rel="stylesheet" href="https://unpkg.com/@waline/client@v2/dist/waline.css"/>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@waline/client@2.15.5/dist/waline.min.css"/>
107 changes: 105 additions & 2 deletions lib/filters/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,107 @@
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) {
require('./afterPostRender')(hexo);
require('./beforePostRender')(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;
});
};
8 changes: 4 additions & 4 deletions lib/generators/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ module.exports = function (hexo) {
// Updated feature status.
configs.theme_config.theme.feature = posts.isFeature;

const siteG = new SiteGenerator(configs);
apiData = siteG.addSiteConfig(apiData);

const categories = new CategoryGenerator(site.categories, site.posts, configs);
apiData = categories.addCategories(apiData);

Expand All @@ -110,12 +113,9 @@ module.exports = function (hexo) {
);
apiData = statistic.addStatistics(apiData);

const search = new SearchGenerator(posts.data, configs);
const search = new SearchGenerator(posts.data);
apiData = search.addSearchIndex(apiData);

const siteG = new SiteGenerator(configs);
apiData = siteG.addSiteConfig(apiData);

return apiData;
}
};
10 changes: 4 additions & 6 deletions lib/generators/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,28 @@ class PostGenerator {
featureCapacity = 3;
isFeature = true;

constructor(posts, configs, options = { sort: true }) {
constructor(posts, configs) {
this.data = posts;
this.fullData = posts;
this.configs = configs;
this.authors = this.configs.theme_config.authors || {};
this.isFeature = this.configs.theme_config.theme.feature;
this.transform(options);
this.transform();
}

/**
* Transform post data into API formats.
* @returns void
*/
transform(options = { sort: true }) {
transform() {
if (this.count() <= 0) return;

let prevPost = {};
let dummyList = [];
let featureIndexes = [];

// Used when feature posts is not enough
if (options.sort) {
this.sortByDate();
}
this.sortByDate();
this.reorderFeaturePosts();

this.data.data.forEach((post, index) => {
Expand Down
17 changes: 8 additions & 9 deletions lib/generators/search.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
const { searchMapper } = require('../helpers/mapper');
const { searchMapper } = require('../helpers/mapper')

class SearchGenerator {
data = [];
configs = {};
data = []

constructor(posts, configs) {
this.data = configs.theme_config.algolia?.enable ? [] : posts.map((post) => searchMapper(post));
constructor(posts) {
this.data = posts.map(searchMapper)
}

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
13 changes: 5 additions & 8 deletions lib/generators/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ try {
`Aurora Plugin fail to get current Aurora Theme version from package location, trying to get from themes folder instead...`
);
try {
themePack = require(appRoot + '/themes/aurora/package.json');
themePack = require(appRoot + '/themes/aurora-s/package.json');
} catch (error) {
throwError(
'Aurora Plugin Error',
Expand All @@ -30,16 +30,13 @@ class SiteGenerator {
}

addSiteConfig(data) {
const tempConfigs = this.data;
const configs = this.data;
// Removed privacy data from site configs
delete tempConfigs.deploy;
delete tempConfigs.server;
tempConfigs.theme_config.algolia = {
enable: this.data.theme_config.algolia?.enable ?? false
};
delete configs.deploy;
delete configs.server;
data.push({
path: 'api/site.json',
data: JSON.stringify(tempConfigs)
data: JSON.stringify(configs)
});
return data;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/helpers/mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function postMapper(post, configs) {
feature: post.feature,
pinned: post.pinned,
text: truncateHTML(abstract, abstractLength),
permalink: `/post/${pathSlug}`,
link: post.link,
photos: post.photos,
count_time: symbolsCountTime(post.content),
categories: post.categories ? postCategoryMapper(post) : [],
Expand Down Expand Up @@ -106,7 +106,7 @@ function postListMapper(post, configs) {
keywords: configs.keywords,
cover: post.cover,
text: post.text,
permalink: post.permalink,
link: post.link,
photos: post.photos,
count_time: post.count_time,
categories: post.categories,
Expand Down
4 changes: 0 additions & 4 deletions lib/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ exports.throwError = function (type, msg) {
);
};

exports.throwWarning = function (type, msg) {
console.warn(`${chalk.yellow(`[${type}]`)} ${chalk.white(msg)}`);
};

exports.throwInfo = function (type, msg) {
console.error(`${chalk.blue(`[${type}]`)} ${chalk.white(msg)}`);
};
Expand Down
6 changes: 4 additions & 2 deletions lib/highlighter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ function cleanup(str, bg) {
_.replace(style, bg ? `style="background-color: ${bg}"` : '')
);
}

console.log("cleanup function has been executed.");
return cleanedStr;
}

function renderCodeBlock(codeHtml, lang) {
console.log("renderCodeBlock function has been executed.");
return `<div class="language-${lang}"><button title="Copy code" class="copy"></button><span class="lang">${lang}</span>${codeHtml}</div>`;
}

Expand Down Expand Up @@ -57,6 +58,7 @@ function filterIntoShiki(
lang,
theme
});
console.log("filterIntoShiki function has been executed.");
return cleanup(renderCodeBlock(codeHtml, lang), backgroundColor);
}

Expand All @@ -69,7 +71,7 @@ function parseFence(infoString) {
}

const tokens = lex(infoString);

console.log("parseFence function has been executed.");
return {
lang: tokens.shift() ?? '',
meta: parse(tokens)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-plugin-aurora-s",
"version": "1.0.4",
"version": "1.0.5",
"description": "Modified plugin for Hexo Aurora theme",
"main": "index.js",
"keywords": [
Expand Down

0 comments on commit 9eae35d

Please sign in to comment.