@bbki.ng/site 5.5.24 → 5.5.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { FontRule } from '../types';
|
|
2
2
|
|
|
3
|
+
export const LOADING_CLASS = 'fonts-loading';
|
|
4
|
+
|
|
3
5
|
export const FontRules: Array<FontRule> = [
|
|
4
6
|
{
|
|
5
7
|
match: '小乌鸦合集',
|
|
@@ -19,6 +21,7 @@ export const FontRules: Array<FontRule> = [
|
|
|
19
21
|
name: 'xwy-icon',
|
|
20
22
|
src: '/fonts/yao-icons.woff2',
|
|
21
23
|
format: 'woff2',
|
|
24
|
+
hideGlyphOnLoading: true,
|
|
22
25
|
},
|
|
23
26
|
},
|
|
24
27
|
];
|
package/src/plugins/xwy/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { TitleListItem } from '#/types/posts';
|
|
|
6
6
|
|
|
7
7
|
import { SpecialTitle } from './components/article';
|
|
8
8
|
import { XwyLogo } from './components/logo';
|
|
9
|
-
import { FontRules } from './const';
|
|
9
|
+
import { FontRules, LOADING_CLASS } from './const';
|
|
10
10
|
import { loadFont } from './utils';
|
|
11
11
|
|
|
12
12
|
class XwyPlugin implements IPlugin {
|
|
@@ -19,6 +19,9 @@ class XwyPlugin implements IPlugin {
|
|
|
19
19
|
private loadedFonts = new Set<string>();
|
|
20
20
|
|
|
21
21
|
onInstall = (ctx: IHostContext) => {
|
|
22
|
+
// add font loading listener
|
|
23
|
+
this.initFontLoadingListener();
|
|
24
|
+
|
|
22
25
|
// 加载所有需要的字体文件
|
|
23
26
|
FontRules.forEach(rule => {
|
|
24
27
|
if (rule.fontConfig && !this.loadedFonts.has(rule.fontConfig.name)) {
|
|
@@ -58,7 +61,15 @@ class XwyPlugin implements IPlugin {
|
|
|
58
61
|
ctx.api.registerSlot('articleTitle', SpecialTitle, this.id);
|
|
59
62
|
};
|
|
60
63
|
|
|
61
|
-
private
|
|
64
|
+
private initFontLoadingListener() {
|
|
65
|
+
// listen font loading status and add class to body for styling
|
|
66
|
+
document.documentElement.classList.add(LOADING_CLASS);
|
|
67
|
+
document.fonts.ready.then(() => {
|
|
68
|
+
document.documentElement.classList.remove(LOADING_CLASS);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private transformPostContent = (content: string = '') => {
|
|
62
73
|
// 在文章内容中替换特定关键词为特殊样式
|
|
63
74
|
return content
|
|
64
75
|
.replace(
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
import { LOADING_CLASS } from '../const';
|
|
1
2
|
import { type FontConfig } from '../types';
|
|
2
3
|
|
|
3
4
|
export const loadFont = (config: FontConfig) => {
|
|
4
5
|
const styleId = `font-${config.name}`;
|
|
5
6
|
if (document.getElementById(styleId)) return;
|
|
6
7
|
|
|
8
|
+
const hideCssRule = config.hideGlyphOnLoading
|
|
9
|
+
? `
|
|
10
|
+
.${LOADING_CLASS} .font-${config.name} {
|
|
11
|
+
visibility: hidden;
|
|
12
|
+
}
|
|
13
|
+
`
|
|
14
|
+
: '';
|
|
15
|
+
|
|
7
16
|
const style = document.createElement('style');
|
|
8
17
|
style.id = styleId;
|
|
9
18
|
style.textContent = `
|
|
@@ -17,6 +26,7 @@ export const loadFont = (config: FontConfig) => {
|
|
|
17
26
|
.font-${config.name} {
|
|
18
27
|
font-family: '${config.name}', monospace;
|
|
19
28
|
}
|
|
29
|
+
${hideCssRule}
|
|
20
30
|
`;
|
|
21
31
|
document.head.appendChild(style);
|
|
22
32
|
};
|