@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
@@ -1,5 +1,17 @@
1
1
  # @bbki.ng/site
2
2
 
3
+ ## 5.5.26
4
+
5
+ ### Patch Changes
6
+
7
+ - 368b207: fix npe
8
+
9
+ ## 5.5.25
10
+
11
+ ### Patch Changes
12
+
13
+ - 942ce66: hide icon on fonts loading
14
+
3
15
  ## 5.5.24
4
16
 
5
17
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/site",
3
- "version": "5.5.24",
3
+ "version": "5.5.26",
4
4
  "description": "code behind bbki.ng",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -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
  ];
@@ -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 transformPostContent = (content: string) => {
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(
@@ -4,6 +4,7 @@ export interface FontConfig {
4
4
  format: 'woff2' | 'woff' | 'ttf' | 'otf';
5
5
  fontWeight?: string;
6
6
  fontStyle?: string;
7
+ hideGlyphOnLoading?: boolean;
7
8
  }
8
9
 
9
10
  export interface FontRule {
@@ -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
  };