Merge branch 'zenoven-feat-optimize-font'

This commit is contained in:
pipipi-pikachu 2022-12-02 10:35:50 +08:00
commit 6cafd88270
25 changed files with 56 additions and 40 deletions

View File

@ -6,7 +6,8 @@
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-service lint"
"lint": "vue-cli-service lint",
"build:fonts": "node scripts/build-fonts"
},
"dependencies": {
"@icon-park/vue-next": "^1.4.0",

45
scripts/build-fonts.js Normal file
View File

@ -0,0 +1,45 @@
// 自动获取 src\assets\fonts 路径下的字体文件列表,并替换相关的 SCSS 变量
/* eslint-disable no-console */
const fs = require('fs')
const path = require('path')
const assetsPath = path.join(__dirname, '../src/assets')
const fontVarPath = path.join(assetsPath, 'styles/font.scss')
const fontsPath = path.join(assetsPath, 'fonts')
const scssFontListVar = '$fontList'
const replaceSCSSVariable = (names) => {
fs.readFile(fontVarPath, 'utf-8', (errs, content) => {
if (errs) {
console.error(errs)
process.exit(1)
}
const reg = new RegExp(`(\\${scssFontListVar}:\\s*)(.*)(;.*)`, 'g')
const newContent = content.replace(reg, `$1${names}$3`)
fs.writeFile(fontVarPath, newContent, errs => {
if (errs) {
console.error(errs)
process.exit(1)
}
console.log('自动生成自定义字体列表完成')
})
})
}
fs.readdir(fontsPath, { withFileTypes: true }, (errs, files) => {
if (errs) {
console.error(errs)
process.exit(1)
}
const woff2Fonts = files.filter(({ name }) => name.endsWith('.woff2'))
const fontList = woff2Fonts.map(({ name }) => name.replace('.woff2', ''))
const names = fontList.reduce((result, name, i) => {
if (i === 0) return `'${name}'`
return `${result}, '${name}'`
}, '')
replaceSCSSVariable(names)
})

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,40 +1,9 @@
@font-face {
font-family: '仓耳小丸子';
src: url(../fonts/仓耳小丸子.ttf);
}
@font-face {
font-family: '优设标题黑';
src: url(../fonts/优设标题黑.ttf);
}
@font-face {
font-family: '峰广明锐体';
src: url(../fonts/峰广明锐体.ttf);
}
@font-face {
font-family: '摄图摩登小方体';
src: url(../fonts/摄图摩登小方体.ttf);
}
@font-face {
font-family: '站酷快乐体';
src: url(../fonts/站酷快乐体.ttf);
}
@font-face {
font-family: '字制区喜脉体';
src: url(../fonts/字制区喜脉体.ttf);
}
@font-face {
font-family: '素材集市康康体';
src: url(../fonts/素材集市康康体.ttf);
}
@font-face {
font-family: '素材集市酷方体';
src: url(../fonts/素材集市酷方体.ttf);
}
@font-face {
font-family: '途牛类圆体';
src: url(../fonts/途牛类圆体.ttf);
}
@font-face {
font-family: '锐字真言体';
src: url(../fonts/锐字真言体.ttf);
$fontList: '仓耳小丸子', '优设标题黑', '字制区喜脉体', '峰广明锐体', '得意黑', '摄图摩登小方体', '站酷快乐体', '素材集市康康体', '素材集市酷方体', '途牛类圆体', '锐字真言体';
@each $font in $fontList {
@font-face {
font-display: swap;
font-family: $font;
src: url('../fonts/#{$font}.woff2') format('woff2');
}
}

View File

@ -30,6 +30,7 @@ export const SYS_FONTS = [
]
export const WEB_FONTS = [
{ label: '得意黑', value: '得意黑' },
{ label: '仓耳小丸子', value: '仓耳小丸子' },
{ label: '优设标题黑', value: '优设标题黑' },
{ label: '峰广明锐体', value: '峰广明锐体' },