Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	package.json
  • Loading branch information
zkz098 committed Feb 25, 2023
2 parents 8f1c592 + 96efe65 commit 781f289
Show file tree
Hide file tree
Showing 23 changed files with 396 additions and 376 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ root = true

[{*.js,*.ts,*.json,*.html,*.css}]
indent_style = space
indent_size = 4
indent_size = 2
6 changes: 4 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ module.exports = {
camelcase: 'off',
'n/no-callback-literal': 'off',
'@typescript-eslint/ban-types': 'off',
// '@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-var-requires': 'off'
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'prefer-const': 'warn'
}
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,8 @@ GPL许可证主要目的是限制修改后的分发行为,避免未经许可
| Hexo | Hexo contributors | 为本项目提供了良好的基础 |
| hexo-theme-shoka | amehime | 本项目的父主题 |

## 开发者们
[![](https://contributors-img.web.app/image?repo=zkz098/hexo-theme-shokaX)](https://github.com/zkz098/hexo-theme-shokaX/graphs/contributors)

## 特别鸣谢
[<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" width="25%">](https://jb.gg/OpenSourceSupport)
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pwa:

# 实验性特性
experiments:
noIE: true # 阻止IE浏览器访问(ShokaX不支持IE的任何版本)
noIE: true # TODO 阻止IE浏览器访问(ShokaX不支持IE的任何版本)
noPlayer: false # 禁用音乐播放器
gradient: false # 使用CSS渐变作为文章封面
fixedCover: "" # 主页面cover(为空则使用bing随机图片)
Expand Down
15 changes: 14 additions & 1 deletion docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@ import navbar from './nav/navbar'
import sidebar from './nav/sidebar'
import {defaultTheme, defineUserConfig} from 'vuepress'
// @ts-ignore
import { sitemapPlugin } from "vuepress-plugin-sitemap2";
import { sitemapPlugin } from "vuepress-plugin-sitemap2"
// @ts-ignore
import { docsearchPlugin } from '@vuepress/plugin-docsearch'

export default defineUserConfig({
plugins: [
sitemapPlugin({
hostname: "https://docs.kaitaku.xyz"
}),
docsearchPlugin({
apiKey: 'c30c4d59605d21483f6b76cdde63ce96',
appId: 'MTVNNUDZBE',
indexName: 'kaitaku',
placeholder: '请输入您需要搜索的内容',
translations: {
button: {
buttonText: '搜索文档'
}
}
})
],
lang: 'zh-CN',
Expand Down
16 changes: 13 additions & 3 deletions docs/guide/performance.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# 性能优化
## 性能报告
:::info
正在准备
:::tip
性能报告的测试网站均为较有特点的Shoka(X)网站 \
报告中的symlpigeon和shoka较有横向对比性(除LCP)
:::
![性能测试报告-谷歌移动](./perf-mobile.png)

## 优化网页
:::info
:::tip
下方数据均基于google pagespeed移动设备规格测试
:::
Shoka系主题的图片都是性能影响的最大因素,可通过如下方法优化:
Expand All @@ -22,3 +24,11 @@ Shoka系主题的图片都是性能影响的最大因素,可通过如下方法
#### 减少插件使用
平均每个插件都会让FCP增加0.1-0.3秒并让SI增加0.3-0.8秒,尤其是qweather类插件
会发起大量的HTTP请求并拖慢加载速度。

#### 自编译typescript和调整压缩配置
ShokaX 稳定版提供了预编译的 javascript ES2017 版本,如果你的站点需要 ES6 兼容或希望拥有更高的性能,请参考二次开发或typescript官方文档自编译ts \
ShokaX 默认 terser 使用 ES2018 作为压缩配置,可自行调整

#### 关闭不使用的功能
ShokaX 提供了关闭部分功能的配置,例如`noPlayer``disableVL`,这两项都可以提高 js 运行时效率并缩小 js 体积。
`noPlayer`理论上可以减少20%的 js 大小。`disableVL`的性能优化几乎为0,但提高了多标签页下的用户体验
31 changes: 15 additions & 16 deletions layout/_partials/sidebar/menu.pug
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mixin item(name, path, parent, dropdown, sublist)
- var trimn = (str)=>{if (str!=null) return str.trim(); else return ""}
mixin item(name, path, parent, sublist)
- var trimn = (str)=>{return str!=null?str.trim():"";}
- var path = path.split('||')
- var itemURL = path[0].trim()
- if (!itemURL.startsWith('http')){ itemURL = itemURL.replace('//', '/') }
Expand All @@ -12,19 +12,18 @@ mixin item(name, path, parent, dropdown, sublist)
!= menuIcon + menuText
else
!= _url(itemURL, menuIcon + menuText, {rel: 'section'})
if dropdown
ul(class="submenu")
each subvalue, subname in sublist
- var path = subvalue.split('||')
- var itemURL = path[0].trim()
- if (itemURL==='/') itemURL='javascript:void(0)'
- var menuText = __('menu.' + subname).replace('menu.', '')
if subname == 'default'
- var menuText = __('menu.' + name).replace('menu.', '')
else
- var menuIcon = '<i class="ic i-' + trimn(path[1]) + '"></i>'
li(class="item")
!= _url(itemURL, menuIcon + menuText, {rel: 'section'})
ul(class="submenu")
each subvalue, subname in sublist
- var path = subvalue.split('||')
- var itemURL = path[0].trim()
- if (itemURL==='/') itemURL='javascript:void(0)'
- var menuText = __('menu.' + subname).replace('menu.', '')
if subname == 'default'
- var menuText = __('menu.' + name).replace('menu.', '')
else
- var menuIcon = '<i class="ic i-' + trimn(path[1]) + '"></i>'
li(class="item")
!= _url(itemURL, menuIcon + menuText, {rel: 'section'})
else
li(class="item")
!= _url(itemURL, menuIcon + menuText, {rel: 'section'})
Expand All @@ -33,6 +32,6 @@ each value, name in theme.menu
if value == '[object Object]'
each subvalue, subname in value
if subname == 'default'
+item(name, subvalue, true, true, value)
+item(name, subvalue, true, value)
else
+item(name, value)
10 changes: 3 additions & 7 deletions scripts/filters/post.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
/* global hexo */
'use strict'

hexo.extend.filter.register('after_post_render', data => {
const { config } = hexo
const theme = hexo.theme.config

data.content = data.content.replace(/(<img[^>]*) src=/img, '$1 data-src=')

const url = require('url')
// eslint-disable-next-line n/no-deprecated-api
const siteHost = url.parse(config.url).hostname || config.url
const siteHost = new URL(config.url).hostname || config.url
data.content = data.content.replace(/<a[^>]* href="([^"]+)"[^>]*>([^<]*)<\/a>/img, (match, href, html) => {
// Exit if the href attribute doesn't exists.
if (!href) return match

// Exit if the url has same host with `config.url`, which means it's an internal link.
// eslint-disable-next-line n/no-deprecated-api
const link = url.parse(href)
const link = new URL(href, config.url)
if (!link.protocol || link.hostname === siteHost) return match

return `<span class="exturl" data-url="${Buffer.from(href).toString('base64')}">${html}</span>`
Expand Down
1 change: 0 additions & 1 deletion scripts/generaters/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ hexo.extend.filter.register('before_generate', () => {
const data = hexo.locals.get('data')

if (data.languages) {
const { language } = hexo.config
const { i18n } = hexo.theme

const mergeLang = lang => {
Expand Down
1 change: 0 additions & 1 deletion scripts/generaters/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
const fs = require('hexo-fs')

hexo.extend.generator.register('images', function (locals) {
const config = hexo.config
const theme = hexo.theme.config
const dir = 'source/_data/' + theme.assets + '/'

Expand Down
5 changes: 2 additions & 3 deletions scripts/generaters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ hexo.extend.generator.register('index', function (locals) {
const catlist = []
let pages
const config = hexo.config
const theme = hexo.theme.config
const sticky = locals.posts.find({ sticky: true }).sort(config.index_generator.order_by)
const posts = locals.posts.find({ sticky: { $exists: false } }).sort(config.index_generator.order_by)
const paginationDir = config.pagination_dir || 'page'
Expand Down Expand Up @@ -69,9 +68,9 @@ hexo.extend.generator.register('index', function (locals) {
cat.subs = child.sort({ name: 1 }).limit(6).toArray()
pl = Math.max(0, pl - child.length)
if (pl > 0) {
// eslint-disable-next-line array-callback-return
// TODO 需要测试
cat.subs.push.apply(cat.subs, cat.posts.sort({ title: 1 }).filter(function (item, i) {
if (item.categories.last()._id === cat._id) { return true }
return item.categories.last()._id === cat._id
}).limit(pl).toArray())
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion scripts/generaters/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ hexo.extend.generator.register('script', function (locals) {
},
loader: theme.loader,
search: null,
valine: theme.valine,
valine: theme.valine, // TODO 废弃属性
outime: {
enable: theme.outime.enable,
days: theme.outime.days
Expand Down
53 changes: 31 additions & 22 deletions scripts/helpers/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
'use strict'

const { htmlTag, url_for } = require('hexo-util')
const url = require('url')
const crypto = require('crypto')

const randomServer = parseInt(Math.random() * 4, 10) + 1
const randomServer = parseInt(String(Math.random() * 4), 10) + 1

const randomBG = function (count = 1, image_server = null, image_list = []) {
let i
Expand Down Expand Up @@ -53,24 +51,27 @@ const randomBG = function (count = 1, image_server = null, image_list = []) {
return parseImage(image_list[Math.floor(Math.random() * image_list.length)], 'mw690')
}

// 注册hexo主题中的URL帮助方法
hexo.extend.helper.register('_url', function (path, text, options = {}) {
// 如果未提供URL路径,则返回
if (!path) { return }

// 获取hexo配置和URL路径信息
const { config } = this
// eslint-disable-next-line n/no-deprecated-api
const data = url.parse(path)
// eslint-disable-next-line n/no-deprecated-api
const siteHost = url.parse(config.url).hostname || config.url
const data = new URL(path, hexo.config.url)
const siteHost = new URL(config.url).hostname || config.url

// 获取主题配置
const theme = hexo.theme.config
let exturl = ''
let tag = 'a'
let attrs = { href: url_for.call(this, path) }

// If `exturl` enabled, set spanned links only on external links.
// 如果启用了 `exturl`,则只为外部链接设置spanned链接。
if (theme.exturl && data.protocol && data.hostname !== siteHost) {
tag = 'span'
exturl = 'exturl'
// 编码URL字符串,并将其存储在数据属性中。
const encoded = Buffer.from(path).toString('base64')
attrs = {
class: exturl,
Expand All @@ -80,8 +81,8 @@ hexo.extend.helper.register('_url', function (path, text, options = {}) {

for (const key in options) {
/**
* If option have `class` attribute, add it to
* 'exturl' class if `exturl` option enabled.
* 如果选项包含 `class` 属性,则将其添加到 `exturl` 类中(如果启用了 `exturl` 选项)。
* 否则,将其添加到属性集中。
*/
if (exturl !== '' && key === 'class') {
attrs[key] += ' ' + options[key]
Expand All @@ -94,20 +95,21 @@ hexo.extend.helper.register('_url', function (path, text, options = {}) {
attrs.class = attrs.class.join(' ')
}

// If it's external link, rewrite attributes.
// 如果是外部链接,则重写属性
if (data.protocol && data.hostname !== siteHost) {
attrs.external = null

if (!theme.exturl) {
// Only for simple link need to rewrite/add attributes.
// 仅需要为简单链接重写/添加属性。
attrs.rel = 'noopener'
attrs.target = '_blank'
} else {
// Remove rel attributes for `exturl` in main menu.
// 在主菜单中移除 `exturl` 的 rel 属性。
attrs.rel = null
}
}

// 返回HTML标记字符串
return htmlTag(tag, attrs, decodeURI(text), false)
})

Expand All @@ -123,7 +125,7 @@ hexo.extend.helper.register('_image_url', function (img, path = '') {
})

hexo.extend.helper.register('_cover', function (item, num) {
const { statics, js, image_server, image_list } = hexo.theme.config
const { image_server, image_list } = hexo.theme.config

if (item.cover) {
return this._image_url(item.cover, item.path)
Expand All @@ -134,20 +136,17 @@ hexo.extend.helper.register('_cover', function (item, num) {
}
})

// TODO 此函数已被废弃
hexo.extend.helper.register('_md5', function (path) {
const str = url_for.call(this, path)
str.replace('index.html', '')
return crypto.createHash('md5').update(str).digest('hex')
})

// 注册hexo主题的永久链接帮助方法
hexo.extend.helper.register('_permapath', function (str) {
// https://support.google.com/webmasters/answer/139066
// 获取hexo的永久链接配置
const { permalink } = hexo.config
// 将输入字符串中的'index.html'替换为空字符串
let url = str.replace(/index\.html$/, '')
// 如果永久链接不以'.html'结尾,将输入字符串中的'.html'替换为空字符串
if (!permalink.endsWith('.html')) {
url = url.replace(/\.html$/, '')
}
// 返回处理后的URL字符串
return url
})

Expand All @@ -158,21 +157,31 @@ hexo.extend.helper.register('canonical', function () {
/**
* Get page path given a certain language tag
*/
// 注册hexo主题的国际化路径帮助方法
hexo.extend.helper.register('i18n_path', function (language) {
// 获取当前页面的path和lang
const { path, lang } = this.page
// 如果path以lang开头,则截取掉lang部分,作为基础路径
const base = path.startsWith(lang) ? path.slice(lang.length + 1) : path
// 通过调用url_for方法,生成国际化路径
return url_for.call(this, `${this.languages.indexOf(language) === 0 ? '' : '/' + language}/${base}`)
})

/**
* Get the language name
*/
// 注册hexo主题的语言名称帮助方法
hexo.extend.helper.register('language_name', function (language) {
// 从主题配置中获取指定语言的名称
const name = hexo.theme.i18n.__(language)('name')
// 如果名称为默认值'name',则返回语言代码,否则返回语言名称
return name === 'name' ? language : name
})

hexo.extend.helper.register('random_color', function () {
/**
@type {number[]}
*/
const arr = []
for (let i = 0; i < 3; i++) {
arr.push(Math.floor(Math.random() * 128 + 128))
Expand Down
1 change: 0 additions & 1 deletion scripts/tags/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
const fs = require('fs')
const path = require('path')
const yaml = require('js-yaml')
// const url = require('url')

function linkGrid (args, content) {
const theme = hexo.theme.config
Expand Down
5 changes: 4 additions & 1 deletion source/css/_common/components/post/expand.styl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
img,
.tabs,
.links {

content-visibility: auto;
contain-intrinsic-size: 979px 1.2em;
&:last-child {
margin-bottom: 0;
}
}

ul, dd, ol {
content-visibility: auto;
contain-intrinsic-size: 979px 3.5em;
ul, ol {
margin-top: 0;
}
Expand Down
Loading

0 comments on commit 781f289

Please sign in to comment.