Skip to content

Commit

Permalink
perf: 字体优化
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Sketon committed May 25, 2024
1 parent ad8d0bb commit 28183e7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 27 deletions.
3 changes: 0 additions & 3 deletions layout/_partial/head.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) %>
Expand Down
35 changes: 18 additions & 17 deletions scripts/helper/vendorFont.js
Original file line number Diff line number Diff line change
@@ -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'"
})
})
2 changes: 1 addition & 1 deletion source/css/_partial/highlight.styl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ $line-numbers

.gist-file
border: none
font-family: font-mono
font-family: "Ubuntu Mono"
margin: 0

.gist-data
Expand Down
1 change: 0 additions & 1 deletion source/css/_partial/post.styl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions source/css/_variables.styl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions source/css/style.styl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 28183e7

Please sign in to comment.