@bbki.ng/site 5.5.23 → 5.5.24

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,11 @@
1
1
  # @bbki.ng/site
2
2
 
3
+ ## 5.5.24
4
+
5
+ ### Patch Changes
6
+
7
+ - 48e4f2d: add new transformer to xwy plugin
8
+
3
9
  ## 5.5.23
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/site",
3
- "version": "5.5.23",
3
+ "version": "5.5.24",
4
4
  "description": "code behind bbki.ng",
5
5
  "main": "index.js",
6
6
  "type": "module",
Binary file
@@ -5,6 +5,7 @@ import { useParams } from 'react-router-dom';
5
5
  import { usePosts } from '@/hooks/use_posts';
6
6
  import { ArticlePage } from '@/components/article';
7
7
  import { useBlogScrollReset } from '@/hooks/use_blog_scroll_pos_restoration';
8
+ import { useMiddlewareTransformedData } from '#/core/hooks/useMiddlewareTransData';
8
9
 
9
10
  function TxtArticle() {
10
11
  const { title } = useParams();
@@ -12,6 +13,8 @@ function TxtArticle() {
12
13
 
13
14
  useBlogScrollReset();
14
15
 
16
+ const transformedContent = useMiddlewareTransformedData('transformPostContent', posts?.content);
17
+
15
18
  if (!title) {
16
19
  return <NotFound />;
17
20
  }
@@ -28,7 +31,7 @@ function TxtArticle() {
28
31
 
29
32
  return (
30
33
  <ArticlePage title={title} date={date}>
31
- <div dangerouslySetInnerHTML={{ __html: posts.content }} />
34
+ <div dangerouslySetInnerHTML={{ __html: transformedContent }} />
32
35
  </ArticlePage>
33
36
  );
34
37
  }
@@ -53,18 +53,16 @@ export function useMiddlewareRunner<T>({
53
53
  return { loading, error, run };
54
54
  }
55
55
 
56
- export const useMiddlewareTransformedData = <T>(hookPoint: HookPoint, defaultValue: Array<T>) => {
57
- const [result, setResult] = useState<Array<T>>(defaultValue);
56
+ export const useMiddlewareTransformedData = <T>(hookPoint: HookPoint, defaultValue: T) => {
57
+ const [result, setResult] = useState<T>(defaultValue);
58
58
 
59
- const runRef = useRef<(input: Array<T>) => Promise<Array<T>>>(() =>
60
- Promise.resolve(defaultValue)
61
- );
59
+ const runRef = useRef<(input: T) => Promise<T>>(() => Promise.resolve(defaultValue));
62
60
 
63
61
  const onMiddlewareChange = useCallback(() => {
64
62
  runRef.current(defaultValue).then(setResult);
65
63
  }, [defaultValue]);
66
64
 
67
- const { run } = useMiddlewareRunner<Array<T>>({
65
+ const { run } = useMiddlewareRunner<T>({
68
66
  hookPoint,
69
67
  onMiddlewareChange,
70
68
  });
@@ -12,4 +12,13 @@ export const FontRules: Array<FontRule> = [
12
12
  extraCls: 'text-2xl w-[81px]',
13
13
  variant: 'special',
14
14
  },
15
+ {
16
+ match: '',
17
+ fontFamily: 'xwy-icon',
18
+ fontConfig: {
19
+ name: 'xwy-icon',
20
+ src: '/fonts/yao-icons.woff2',
21
+ format: 'woff2',
22
+ },
23
+ },
15
24
  ];
@@ -1,9 +1,10 @@
1
+ import { PathObj } from '@bbki.ng/ui';
2
+
1
3
  import { IHostContext } from '#/types/hostApi';
2
4
  import { IPlugin } from '#/types/plugin';
3
5
  import { TitleListItem } from '#/types/posts';
4
- import { PathObj } from '@bbki.ng/ui';
5
- import { SpecialTitle } from './components/article';
6
6
 
7
+ import { SpecialTitle } from './components/article';
7
8
  import { XwyLogo } from './components/logo';
8
9
  import { FontRules } from './const';
9
10
  import { loadFont } from './utils';
@@ -42,6 +43,14 @@ class XwyPlugin implements IPlugin {
42
43
  10 // weight
43
44
  );
44
45
 
46
+ // 注册中间件,修改文章内容
47
+ ctx.api.registerMiddleware(
48
+ 'transformPostContent',
49
+ this.transformPostContent,
50
+ this.id,
51
+ 10 // weight
52
+ );
53
+
45
54
  // 注册logo插槽组件
46
55
  ctx.api.registerSlot('logo', XwyLogo, this.id);
47
56
 
@@ -49,6 +58,19 @@ class XwyPlugin implements IPlugin {
49
58
  ctx.api.registerSlot('articleTitle', SpecialTitle, this.id);
50
59
  };
51
60
 
61
+ private transformPostContent = (content: string) => {
62
+ // 在文章内容中替换特定关键词为特殊样式
63
+ return content
64
+ .replace(
65
+ /小乌鸦/g,
66
+ `<span class="font-xwy text-content-special text-[1.6rem] align-middle">小乌鸦</span>`
67
+ )
68
+ .replace(
69
+ /公园/,
70
+ `公园 <span class="font-xwy-icon text-[#679867] text-[1.6rem] align-middle">&#xE01A&#xE003</span>`
71
+ );
72
+ };
73
+
52
74
  private transformBreadcrumbPaths = (paths: PathObj[]) => {
53
75
  const result = paths.map(p => {
54
76
  if (p.name === '小乌鸦合集') {
@@ -12,7 +12,7 @@ export const loadFont = (config: FontConfig) => {
12
12
  src: url('${config.src}') format('${config.format}');
13
13
  font-weight: ${config.fontWeight || 'normal'};
14
14
  font-style: ${config.fontStyle || 'normal'};
15
- font-display: swap;
15
+ font-display: block;
16
16
  }
17
17
  .font-${config.name} {
18
18
  font-family: '${config.name}', monospace;