From 28183e77bf46291cd4c84081f50f4f96b1ce6303 Mon Sep 17 00:00:00 2001 From: D-Sketon <2055272094@qq.com> Date: Sat, 25 May 2024 15:56:17 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=AD=97=E4=BD=93=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layout/_partial/head.ejs | 3 --- scripts/helper/vendorFont.js | 35 +++++++++++++++--------------- source/css/_partial/highlight.styl | 2 +- source/css/_partial/post.styl | 1 - source/css/_variables.styl | 4 +--- source/css/style.styl | 4 ++-- 6 files changed, 22 insertions(+), 27 deletions(-) diff --git a/layout/_partial/head.ejs b/layout/_partial/head.ejs index 94c6d96..884cf5d 100644 --- a/layout/_partial/head.ejs +++ b/layout/_partial/head.ejs @@ -40,9 +40,6 @@ <% if (theme.favicon) { %> <%- favicon_tag(theme.favicon) %> <% } %> - <% if (config.highlight.enable) { %> - <%- css(vendorCdn(theme.vendor.css.highlight)) %> - <% } %> <%- css('css/style') %> <% if (theme.fancybox) { %> <%- css(vendorCdn(theme.vendor.css.fancybox)) %> diff --git a/scripts/helper/vendorFont.js b/scripts/helper/vendorFont.js index dea7058..f53b725 100644 --- a/scripts/helper/vendorFont.js +++ b/scripts/helper/vendorFont.js @@ -1,25 +1,26 @@ const { htmlTag } = require('hexo-util') hexo.extend.helper.register('vendorFont', () => { const fontDisplay = '&display=swap' - const fontSubset = '&subset=latin,latin-ext' const fontStyles = ':400,400italic,700,700italic' const fontHost = 'https://fonts.googleapis.com' - let fontFamilies = ['Mulish', 'Noto Serif SC', 'Ubuntu Mono'].map(item => { - return item + fontStyles - }) - - fontFamilies = fontFamilies.filter(item => item !== '') - fontFamilies = [...new Set(fontFamilies)] - fontFamilies = fontFamilies.join('|') + let fontFamilies = ['Mulish', 'Noto Serif SC', 'Ubuntu Mono'] + .map(item => item + fontStyles) + .filter(item => item !== '') + .join('|') - // Merge extra parameters to the final processed font string - return fontFamilies - ? htmlTag('link', { - rel: 'preload', - href: `${fontHost}/css?family=${fontFamilies.concat(fontDisplay, fontSubset)}`, - as: "style", - onload: "this.onload=null;this.rel='stylesheet'" - }) - : '' + return htmlTag('link', { + rel: 'preconnect', + href: 'https://fonts.gstatic.com', + crossorigin: true, + }) + htmlTag('link', { + rel: 'preload', + as: 'style', + href: `${fontHost}/css?family=${fontFamilies.concat(fontDisplay)}`, + }) + htmlTag('link', { + rel: 'stylesheet', + href: `${fontHost}/css?family=${fontFamilies.concat(fontDisplay)}`, + media: 'print', + onload: "this.media='all'" + }) }) diff --git a/source/css/_partial/highlight.styl b/source/css/_partial/highlight.styl index 93c26ac..8e3e824 100644 --- a/source/css/_partial/highlight.styl +++ b/source/css/_partial/highlight.styl @@ -112,7 +112,7 @@ $line-numbers .gist-file border: none - font-family: font-mono + font-family: "Ubuntu Mono" margin: 0 .gist-data diff --git a/source/css/_partial/post.styl b/source/css/_partial/post.styl index 6642a2d..94b2d00 100644 --- a/source/css/_partial/post.styl +++ b/source/css/_partial/post.styl @@ -157,7 +157,6 @@ $post-cover font-size: 25px font-weight: bold text-decoration: none - text-shadow: 0 1px rgba(0, 0, 0, 0.2) letter-spacing: 1px white-space: nowrap overflow: hidden diff --git a/source/css/_variables.styl b/source/css/_variables.styl index 2a76742..1ac74a0 100644 --- a/source/css/_variables.styl +++ b/source/css/_variables.styl @@ -120,10 +120,8 @@ animation: blur-darken 0.8s ease-in-out forwards // Fonts -font-title = Mulish,'Noto Serif SC','Noto Serif JP',Mulish,-apple-system,'PingFang SC','Microsoft YaHei',sans-serif +font-title = Mulish,'Noto Serif SC','Noto Serif JP',-apple-system,'PingFang SC','Microsoft YaHei',sans-serif font-sans = Mulish,-apple-system,"PingFang SC","Microsoft YaHei",sans-serif -font-serif = Georgia, "Times New Roman", serif -font-mono = "Source Code Pro", Consolas, Monaco, Menlo, Consolas, monospace font-size = 14px line-height = 1.8em diff --git a/source/css/style.styl b/source/css/style.styl index d2b6dc5..1f87cce 100644 --- a/source/css/style.styl +++ b/source/css/style.styl @@ -33,7 +33,7 @@ html, body, #container body background: var(--color-background) -webkit-text-size-adjust: 100% - font-family: font-sans + font-family: font-title transition: background 0.3s ease if reimu_cursor @@ -88,7 +88,7 @@ if reimu_cursor background: var(--color-background) #main - padding: 0 5px + padding: 0 10px max-width: 100% box-sizing: border-box