@bbki.ng/site 5.5.17 → 5.5.18

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,13 @@
1
1
  # @bbki.ng/site
2
2
 
3
+ ## 5.5.18
4
+
5
+ ### Patch Changes
6
+
7
+ - 43fb1e3: add xwy plugin
8
+ - Updated dependencies [43fb1e3]
9
+ - @bbki.ng/ui@0.2.12
10
+
3
11
  ## 5.5.17
4
12
 
5
13
  ### Patch Changes
package/index.d.ts CHANGED
@@ -1,5 +1,18 @@
1
+ import React from 'react';
2
+
1
3
  declare const GLOBAL_BBKING_VERSION: string;
2
4
  declare const GLOBAL_COMMIT_HASH: string;
3
5
  interface ImportMeta {
4
- glob: (pattern: string) => Record<string, () => Promise<any>>;
6
+ glob: (pattern: string) => Record<string, () => Promise<unknown>>;
7
+ }
8
+
9
+ declare global {
10
+ namespace JSX {
11
+ interface IntrinsicElements {
12
+ 'bb-img': React.DetailedHTMLProps<
13
+ React.ImgHTMLAttributes<HTMLImageElement>,
14
+ HTMLImageElement
15
+ >;
16
+ }
17
+ }
5
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/site",
3
- "version": "5.5.17",
3
+ "version": "5.5.18",
4
4
  "description": "code behind bbki.ng",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -14,7 +14,7 @@
14
14
  "react-dom": "^18.0.0",
15
15
  "react-router-dom": "6",
16
16
  "swr": "^2.2.5",
17
- "@bbki.ng/ui": "0.2.11"
17
+ "@bbki.ng/ui": "0.2.12"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@eslint/compat": "^1.0.0",
@@ -57,7 +57,7 @@
57
57
  "vite-plugin-mdx": "^3.5.8",
58
58
  "vite-plugin-pwa": "0.19",
59
59
  "workbox-window": "^6.3.0",
60
- "@bbki.ng/config": "1.0.7"
60
+ "@bbki.ng/config": "1.0.8"
61
61
  },
62
62
  "author": "bbbottle",
63
63
  "license": "MIT",
package/src/blog/app.tsx CHANGED
@@ -1,6 +1,6 @@
1
1
  import React, { useContext } from 'react';
2
- import { Outlet, Route, Routes } from 'react-router-dom';
3
- import { Nav, NotFound, Page, Grid, ErrorBoundary, Container } from '@bbki.ng/ui';
2
+ import { Outlet, Route, Routes, useNavigate } from 'react-router-dom';
3
+ import { Logo, Nav, NotFound, Page, Grid, ErrorBoundary, Container } from '@bbki.ng/ui';
4
4
 
5
5
  import { usePaths } from '@/hooks';
6
6
  import ArticlePage from '@/pages/extensions/txt/article';
@@ -13,12 +13,16 @@ import { usePlugins } from '#/core/hooks/use_plugins';
13
13
  import { SWR } from '@/swr';
14
14
 
15
15
  import { Cover, Streaming } from './pages';
16
- import { useDynamicLogo } from './hooks/use_dynamic_logo';
17
16
 
18
17
  const Layout = () => {
19
18
  const paths = usePaths();
20
19
  const { isLoading } = useContext(GlobalLoadingContext);
21
- const logo = useDynamicLogo();
20
+
21
+ const nav = useNavigate();
22
+
23
+ const defaultLogo = (
24
+ <Logo className="mr-2 cursor-pointer hover:opacity-80" onClick={() => nav('/')} />
25
+ );
22
26
 
23
27
  return (
24
28
  <Page
@@ -27,7 +31,7 @@ const Layout = () => {
27
31
  paths={paths}
28
32
  className="gradient-blur-cover select-none"
29
33
  loading={isLoading}
30
- customLogo={logo}
34
+ customLogo={<Slot name="logo" data={defaultLogo} placeholder={defaultLogo} />}
31
35
  style={{
32
36
  paddingTop: 'var(--safe-top)',
33
37
  transition: 'all .2s ease-in-out',
@@ -59,7 +63,7 @@ const Layout = () => {
59
63
  };
60
64
 
61
65
  export const App = () => {
62
- usePlugins(['sticker', 'fontstyler', 'extra-cd']);
66
+ usePlugins(['sticker', 'xwy', 'extra-cd']);
63
67
 
64
68
  return (
65
69
  <SWR>
@@ -1,15 +1,23 @@
1
1
  import React from 'react';
2
- import { SlotName } from 'src/types/slots';
2
+
3
+ import { SlotName } from '#/types/slots';
4
+
3
5
  import { useSlotComp } from '../hooks/useSlotComp';
4
6
 
5
7
  export interface ISlotProps {
6
8
  name: SlotName;
7
9
  data?: unknown;
10
+
11
+ placeholder?: React.ReactNode;
8
12
  }
9
13
 
10
- export const Slot: React.FC<ISlotProps> = ({ name, data }) => {
14
+ export const Slot: React.FC<ISlotProps> = ({ name, data, placeholder }) => {
11
15
  const components = useSlotComp(name);
12
16
 
17
+ if (components.length === 0) {
18
+ return <>{placeholder}</>;
19
+ }
20
+
13
21
  return (
14
22
  <>
15
23
  {components.map((Component, index) => (
@@ -1,10 +1,4 @@
1
1
  export const PLUGIN_MANIFEST = [
2
- {
3
- name: 'test',
4
- id: 'test',
5
- version: '0.1.0',
6
- description: 'A test plugin',
7
- },
8
2
  {
9
3
  name: 'sticker',
10
4
  id: 'sticker',
@@ -19,9 +13,9 @@ export const PLUGIN_MANIFEST = [
19
13
  'Provides additional change directory functionalities for enhanced user experience.',
20
14
  },
21
15
  {
22
- name: 'fontstyler',
23
- id: 'fontstyler',
16
+ name: 'xwy',
17
+ id: 'xwy',
24
18
  version: '0.1.0',
25
- description: 'Apply custom fonts to specific post',
19
+ description: 'customize for xwy',
26
20
  },
27
21
  ];
@@ -3,17 +3,6 @@ import React from 'react';
3
3
 
4
4
  import { StickerCtx } from '../context';
5
5
 
6
- declare global {
7
- namespace JSX {
8
- interface IntrinsicElements {
9
- 'bb-img': React.DetailedHTMLProps<
10
- React.ImgHTMLAttributes<HTMLImageElement>,
11
- HTMLImageElement
12
- >;
13
- }
14
- }
15
- }
16
-
17
6
  export const StickerCom = ({ data }: { data: PathObj[] }) => {
18
7
  const ctx = StickerCtx.useCtx();
19
8
 
@@ -1,5 +1,6 @@
1
1
  import { IHostContext } from '#/types/hostApi';
2
2
  import { IPlugin } from '#/types/plugin';
3
+
3
4
  import { StickerCom } from './components/StickerCom';
4
5
  import { IStickerCtx, StickerCtx } from './context';
5
6
 
@@ -1,4 +1,5 @@
1
- import React from 'react';
1
+ import React, { ReactNode } from 'react';
2
+ import { useLocation } from 'react-router-dom';
2
3
 
3
4
  export const Crows = () => {
4
5
  return (
@@ -11,3 +12,13 @@ export const Crows = () => {
11
12
  </svg>
12
13
  );
13
14
  };
15
+
16
+ export const XwyLogo = ({ data: defaultLogo }: { data: ReactNode }) => {
17
+ const location = useLocation();
18
+
19
+ if (decodeURIComponent(location.pathname).includes('小乌鸦')) {
20
+ return <Crows />;
21
+ }
22
+
23
+ return <>{defaultLogo}</>;
24
+ };
@@ -0,0 +1,15 @@
1
+ import { FontRule } from '../types';
2
+
3
+ export const FontRules: Array<FontRule> = [
4
+ {
5
+ match: '小乌鸦合集',
6
+ fontFamily: 'xwy',
7
+ fontConfig: {
8
+ name: 'xwy',
9
+ src: '/fonts/xwy.woff2',
10
+ format: 'woff2',
11
+ },
12
+ extraCls: 'text-2xl',
13
+ variant: 'special',
14
+ },
15
+ ];
@@ -0,0 +1,73 @@
1
+ import { IHostContext } from '#/types/hostApi';
2
+ import { IPlugin } from '#/types/plugin';
3
+ import { TitleListItem } from '#/types/posts';
4
+
5
+ import { XwyLogo } from './components/logo';
6
+ import { FontRules } from './const';
7
+ import { loadFont } from './utils';
8
+
9
+ class XwyPlugin implements IPlugin {
10
+ id = 'fontstyler';
11
+ name = 'Font Styler';
12
+ description = 'Apply custom fonts to specific post titles';
13
+ version = '1.0.0';
14
+ author = 'bbki.ng';
15
+
16
+ private loadedFonts = new Set<string>();
17
+
18
+ onInstall = (ctx: IHostContext) => {
19
+ // 加载所有需要的字体文件
20
+ FontRules.forEach(rule => {
21
+ if (rule.fontConfig && !this.loadedFonts.has(rule.fontConfig.name)) {
22
+ loadFont(rule.fontConfig);
23
+ this.loadedFonts.add(rule.fontConfig.name);
24
+ }
25
+ });
26
+
27
+ // 注册中间件,修改标题列表
28
+ ctx.api.registerMiddleware(
29
+ 'transformTitleList',
30
+ this.transformTitleList,
31
+ this.id,
32
+ 10 // weight
33
+ );
34
+
35
+ // 注册logo插槽组件
36
+ ctx.api.registerSlot('logo', XwyLogo, this.id);
37
+ };
38
+
39
+ /**
40
+ * 转换标题列表,为匹配的标题添加字体类名
41
+ */
42
+ private transformTitleList = (titleList: TitleListItem[]): TitleListItem[] => {
43
+ return titleList.map(item => {
44
+ for (const rule of FontRules) {
45
+ const match =
46
+ typeof rule.match === 'string' ? item.name === rule.match : rule.match.test(item.name);
47
+
48
+ if (match) {
49
+ return {
50
+ ...item,
51
+ variant: rule.variant || 'default',
52
+ className: `font-${rule.fontFamily} ${rule.extraCls || ''}`.trim(),
53
+ };
54
+ }
55
+ }
56
+ return item;
57
+ });
58
+ };
59
+
60
+ onDisable = async () => {
61
+ this.loadedFonts.forEach(fontName => {
62
+ const styleEl = document.getElementById(`font-${fontName}`);
63
+ if (styleEl) {
64
+ styleEl.remove();
65
+ }
66
+ });
67
+ this.loadedFonts.clear();
68
+ };
69
+
70
+ onDestroy = () => {};
71
+ }
72
+
73
+ export default new XwyPlugin();
@@ -0,0 +1,15 @@
1
+ export interface FontConfig {
2
+ name: string;
3
+ src: string;
4
+ format: 'woff2' | 'woff' | 'ttf' | 'otf';
5
+ fontWeight?: string;
6
+ fontStyle?: string;
7
+ }
8
+
9
+ export interface FontRule {
10
+ match: string | RegExp;
11
+ fontFamily: string;
12
+ fontConfig?: FontConfig;
13
+ extraCls?: string;
14
+ variant?: 'default' | 'special';
15
+ }
@@ -0,0 +1,22 @@
1
+ import { type FontConfig } from '../types';
2
+
3
+ export const loadFont = (config: FontConfig) => {
4
+ const styleId = `font-${config.name}`;
5
+ if (document.getElementById(styleId)) return;
6
+
7
+ const style = document.createElement('style');
8
+ style.id = styleId;
9
+ style.textContent = `
10
+ @font-face {
11
+ font-family: '${config.name}';
12
+ src: url('${config.src}') format('${config.format}');
13
+ font-weight: ${config.fontWeight || 'normal'};
14
+ font-style: ${config.fontStyle || 'normal'};
15
+ font-display: swap;
16
+ }
17
+ .font-${config.name} {
18
+ font-family: '${config.name}', monospace;
19
+ }
20
+ `;
21
+ document.head.appendChild(style);
22
+ };
@@ -12,4 +12,4 @@ export interface IPlugin {
12
12
  onDestroy?: () => void;
13
13
  }
14
14
 
15
- export type PluginID = 'sticker' | 'fontstyler' | 'extra-cd';
15
+ export type PluginID = 'sticker' | 'xwy' | 'extra-cd';
@@ -3,4 +3,5 @@ export interface TitleListItem {
3
3
  to: string;
4
4
  children: string;
5
5
  className?: string;
6
+ variant?: 'default' | 'special';
6
7
  }
@@ -1,2 +1,2 @@
1
- export type SlotName = 'leftCol' | 'rightCol' | 'articleActionRow';
1
+ export type SlotName = 'leftCol' | 'rightCol' | 'articleActionRow' | 'logo';
2
2
  export type HookPoint = 'filterPosts' | 'transformPostContent' | 'transformTitleList';
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
- import { Role, useRole } from './use_role';
3
- import { useLocation } from 'react-router-dom';
4
- import { Crows } from '@/components/Pochacco/xwy';
5
-
6
- export const useDynamicLogo = () => {
7
- const role = useRole();
8
- const location = useLocation();
9
-
10
- if (decodeURIComponent(location.pathname).includes('小乌鸦')) {
11
- return <Crows />;
12
- }
13
-
14
- return null;
15
- };
@@ -1,132 +0,0 @@
1
- import { IHostContext } from '#/types/hostApi';
2
- import { IPlugin } from '#/types/plugin';
3
-
4
- export interface TitleListItem {
5
- name: string;
6
- to: string;
7
- children: string;
8
- className?: string;
9
- }
10
-
11
- export interface FontConfig {
12
- name: string;
13
- src: string;
14
- format: 'woff2' | 'woff' | 'ttf' | 'otf';
15
- fontWeight?: string;
16
- fontStyle?: string;
17
- }
18
-
19
- export interface FontRule {
20
- match: string | RegExp;
21
- fontFamily: string;
22
- fontConfig?: FontConfig;
23
- extraCls?: string;
24
- }
25
-
26
- class FontStylerPlugin implements IPlugin {
27
- id = 'fontstyler';
28
- name = 'Font Styler';
29
- description = 'Apply custom fonts to specific post titles';
30
- version = '1.0.0';
31
- author = 'bbki.ng';
32
-
33
- /**
34
- * 配置:标题匹配规则 → 字体配置
35
- * 支持精确字符串匹配或正则表达式匹配
36
- *
37
- * 示例:
38
- * - 精确匹配: { match: '某篇文章标题', fontFamily: 'CustomFont1', fontConfig: {...} }
39
- * - 正则匹配: { match: /^示例/, fontFamily: 'CustomFont2', fontConfig: {...} }
40
- */
41
- private fontRules: FontRule[] = [
42
- {
43
- match: '小乌鸦合集',
44
- fontFamily: 'xwy',
45
- fontConfig: {
46
- name: 'xwy',
47
- src: '/fonts/xwy.woff2',
48
- format: 'woff2',
49
- },
50
- extraCls: 'text-2xl',
51
- },
52
- ];
53
-
54
- private loadedFonts = new Set<string>();
55
-
56
- onInstall = (ctx: IHostContext) => {
57
- // 加载所有需要的字体文件
58
- this.fontRules.forEach(rule => {
59
- if (rule.fontConfig && !this.loadedFonts.has(rule.fontConfig.name)) {
60
- this.loadFont(rule.fontConfig);
61
- this.loadedFonts.add(rule.fontConfig.name);
62
- }
63
- });
64
-
65
- ctx.api.registerMiddleware(
66
- 'transformTitleList',
67
- this.transformTitleList,
68
- this.id,
69
- 10 // weight
70
- );
71
- };
72
-
73
- /**
74
- * 动态加载字体文件
75
- * 通过创建 style 标签添加 @font-face 规则
76
- */
77
- private loadFont = (config: FontConfig) => {
78
- const styleId = `font-${config.name}`;
79
- if (document.getElementById(styleId)) return;
80
-
81
- const style = document.createElement('style');
82
- style.id = styleId;
83
- style.textContent = `
84
- @font-face {
85
- font-family: '${config.name}';
86
- src: url('${config.src}') format('${config.format}');
87
- font-weight: ${config.fontWeight || 'normal'};
88
- font-style: ${config.fontStyle || 'normal'};
89
- font-display: swap;
90
- }
91
- .font-${config.name} {
92
- font-family: '${config.name}', monospace;
93
- }
94
- `;
95
- document.head.appendChild(style);
96
- };
97
-
98
- /**
99
- * 转换标题列表,为匹配的标题添加字体类名
100
- */
101
- private transformTitleList = (titleList: TitleListItem[]): TitleListItem[] => {
102
- return titleList.map(item => {
103
- for (const rule of this.fontRules) {
104
- const match =
105
- typeof rule.match === 'string' ? item.name === rule.match : rule.match.test(item.name);
106
-
107
- if (match) {
108
- return {
109
- ...item,
110
- className: `font-${rule.fontFamily} ${rule.extraCls || ''}`.trim(),
111
- };
112
- }
113
- }
114
- return item;
115
- });
116
- };
117
-
118
- onDisable = async () => {
119
- // 清理加载的字体样式
120
- this.loadedFonts.forEach(fontName => {
121
- const styleEl = document.getElementById(`font-${fontName}`);
122
- if (styleEl) {
123
- styleEl.remove();
124
- }
125
- });
126
- this.loadedFonts.clear();
127
- };
128
-
129
- onDestroy = () => {};
130
- }
131
-
132
- export default new FontStylerPlugin();
@@ -1,8 +0,0 @@
1
- import { type PathObj } from '@bbki.ng/ui';
2
- import React from 'react';
3
-
4
- export const Emoji = ({ data }: { data: any }) => {
5
- const path = data as PathObj[];
6
- console.log(path);
7
- return <span>😊</span>;
8
- };
@@ -1,23 +0,0 @@
1
- import { IHostContext } from '#/types/hostApi';
2
- import { IPlugin } from '#/types/plugin';
3
-
4
- import { Emoji } from './components/emoji';
5
-
6
- class TestPlugin implements IPlugin {
7
- id: string = 'test';
8
- name: string = 'Test Plugin';
9
- description?: string | undefined;
10
- version: string = '0.1.0';
11
- author?: string | undefined;
12
-
13
- onInstall?: ((ctx: IHostContext) => void) | undefined = (ctx: IHostContext) => {
14
- ctx.api.registerSlot('leftCol', Emoji, this.id);
15
- };
16
-
17
- onDisable?: (() => Promise<void> | void) | undefined;
18
- onDestroy?: (() => void) | undefined;
19
- }
20
-
21
- const testPlugin = new TestPlugin();
22
-
23
- export default testPlugin;