@bbki.ng/site 5.5.21 → 5.5.23

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,21 @@
1
1
  # @bbki.ng/site
2
2
 
3
+ ## 5.5.23
4
+
5
+ ### Patch Changes
6
+
7
+ - e2181b3: add new slots and data hook point
8
+ - Updated dependencies [e2181b3]
9
+ - @bbki.ng/ui@0.2.15
10
+
11
+ ## 5.5.22
12
+
13
+ ### Patch Changes
14
+
15
+ - 20b3d36: update font
16
+ - Updated dependencies [20b3d36]
17
+ - @bbki.ng/ui@0.2.14
18
+
3
19
  ## 5.5.21
4
20
 
5
21
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/site",
3
- "version": "5.5.21",
3
+ "version": "5.5.23",
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.13"
17
+ "@bbki.ng/ui": "0.2.15"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@eslint/compat": "^1.0.0",
Binary file
@@ -5,10 +5,12 @@ import { Logo, Nav, Page, Grid, ErrorBoundary, Container } from '@bbki.ng/ui';
5
5
  import { Slot } from '#/core/components/SlotComp';
6
6
  import { usePaths } from '@/hooks';
7
7
  import { GlobalLoadingContext } from '@/context/global_loading_state_provider';
8
+ import { useMiddlewareTransformedData } from '#/core/hooks/useMiddlewareTransData';
8
9
 
9
10
  export const BaseLayout = () => {
10
11
  const paths = usePaths();
11
12
  const { isLoading } = useContext(GlobalLoadingContext);
13
+ const transformedPaths = useMiddlewareTransformedData('transformBreadcrumbPath', paths);
12
14
 
13
15
  const nav = useNavigate();
14
16
 
@@ -20,7 +22,7 @@ export const BaseLayout = () => {
20
22
  <Page
21
23
  nav={
22
24
  <Nav
23
- paths={paths}
25
+ paths={transformedPaths}
24
26
  className="gradient-blur-cover select-none"
25
27
  loading={isLoading}
26
28
  customLogo={<Slot name="logo" data={defaultLogo} placeholder={defaultLogo} />}
@@ -1,21 +1,22 @@
1
- import React, { ReactElement } from 'react';
1
+ import React, { ReactElement, ReactNode } from 'react';
2
2
  import { Article, Link } from '@bbki.ng/ui';
3
3
  import classNames from 'classnames';
4
- import { useNavigate } from 'react-router-dom';
4
+
5
+ import { Slot } from '#/core/components/SlotComp';
5
6
 
6
7
  export type ArticlePageProps = {
7
8
  tags?: string[];
8
9
  title: string;
9
10
  date?: string;
10
- description?: any;
11
+ description?: ReactNode;
11
12
  headless?: boolean;
12
13
  className?: string;
13
14
  children: ReactElement;
14
15
  };
15
16
 
16
17
  export const ArticlePage = (props: ArticlePageProps) => {
17
- const { tags: tagNames, title, description, headless } = props;
18
- const navgation = useNavigate();
18
+ const { title, description, headless } = props;
19
+ // const navgation = useNavigate();
19
20
 
20
21
  if (headless) {
21
22
  return props.children;
@@ -26,7 +27,7 @@ export const ArticlePage = (props: ArticlePageProps) => {
26
27
  return (
27
28
  <>
28
29
  <Article
29
- title={title}
30
+ title={<Slot name="articleTitle" data={title} placeholder={<>{title}</>} />}
30
31
  date={props.date}
31
32
  description={description}
32
33
  className={`${props.className || ''}`}
@@ -1,12 +1,12 @@
1
- import { pathObj } from '@/types/path';
1
+ import { useLocation } from 'react-router-dom';
2
+ import { useMemo } from 'react';
3
+
2
4
  import { usePathName } from '@/hooks/use_pathname';
5
+ import { pathObj } from '@/types/path';
3
6
 
4
7
  export const usePaths = (): pathObj[] => {
5
8
  const pathname = usePathName();
6
-
7
- if (pathname === '/') {
8
- return [{ name: '~' }];
9
- }
9
+ const { pathname: locationPathname } = useLocation();
10
10
 
11
11
  const pathNameArr = pathname.split('/');
12
12
 
@@ -17,14 +17,22 @@ export const usePaths = (): pathObj[] => {
17
17
  .replace(/^$/, '/');
18
18
  });
19
19
 
20
- return pathsArr.map((path, index) => {
21
- const isLast = index === pathsArr.length - 1;
22
- const name = decodeURIComponent(pathNameArr[index].replace(/^$/, '~'));
23
- return isLast
24
- ? { name }
25
- : {
26
- name,
27
- path,
28
- };
29
- });
20
+ const result = useMemo(() => {
21
+ return pathsArr.map((path, index) => {
22
+ const isLast = index === pathsArr.length - 1;
23
+ const name = decodeURIComponent(pathNameArr[index].replace(/^$/, '~'));
24
+ return isLast
25
+ ? { name }
26
+ : {
27
+ name,
28
+ path,
29
+ };
30
+ });
31
+ }, [locationPathname]);
32
+
33
+ if (pathname === '/') {
34
+ return [{ name: '~' }];
35
+ }
36
+
37
+ return result;
30
38
  };
@@ -1,5 +1,5 @@
1
1
  import { API_ENDPOINT } from '@/constants/routes';
2
- import { FontType } from '@/types/font';
2
+
3
3
  import { getStableDeviceId } from './fingerprints';
4
4
 
5
5
  type Fetcher = (resource: string, init?: any) => Promise<any>;
@@ -1,4 +1,4 @@
1
- import { useState, useEffect, useCallback } from 'react';
1
+ import { useState, useEffect, useCallback, useRef } from 'react';
2
2
 
3
3
  import { registry } from '#/core/registry';
4
4
  import type { HookPoint } from '#/types/slots';
@@ -52,3 +52,28 @@ export function useMiddlewareRunner<T>({
52
52
 
53
53
  return { loading, error, run };
54
54
  }
55
+
56
+ export const useMiddlewareTransformedData = <T>(hookPoint: HookPoint, defaultValue: Array<T>) => {
57
+ const [result, setResult] = useState<Array<T>>(defaultValue);
58
+
59
+ const runRef = useRef<(input: Array<T>) => Promise<Array<T>>>(() =>
60
+ Promise.resolve(defaultValue)
61
+ );
62
+
63
+ const onMiddlewareChange = useCallback(() => {
64
+ runRef.current(defaultValue).then(setResult);
65
+ }, [defaultValue]);
66
+
67
+ const { run } = useMiddlewareRunner<Array<T>>({
68
+ hookPoint,
69
+ onMiddlewareChange,
70
+ });
71
+
72
+ runRef.current = run;
73
+
74
+ useEffect(() => {
75
+ run(defaultValue).then(setResult);
76
+ }, [defaultValue, run]);
77
+
78
+ return result;
79
+ };
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+
3
+ import { IComPropsRegisteredToSlot } from '#/types/slots';
4
+
5
+ export const SpecialTitle = (props: IComPropsRegisteredToSlot) => {
6
+ const title = props.data as string;
7
+
8
+ if (title === '小乌鸦合集') {
9
+ return <span className="font-xwy text-content-special text-4xl">{title}</span>;
10
+ }
11
+
12
+ return <>{title}</>;
13
+ };
@@ -9,7 +9,7 @@ export const FontRules: Array<FontRule> = [
9
9
  src: '/fonts/xwy.woff2',
10
10
  format: 'woff2',
11
11
  },
12
- extraCls: 'text-2xl w-[113px]',
12
+ extraCls: 'text-2xl w-[81px]',
13
13
  variant: 'special',
14
14
  },
15
15
  ];
@@ -1,6 +1,8 @@
1
1
  import { IHostContext } from '#/types/hostApi';
2
2
  import { IPlugin } from '#/types/plugin';
3
3
  import { TitleListItem } from '#/types/posts';
4
+ import { PathObj } from '@bbki.ng/ui';
5
+ import { SpecialTitle } from './components/article';
4
6
 
5
7
  import { XwyLogo } from './components/logo';
6
8
  import { FontRules } from './const';
@@ -32,8 +34,37 @@ class XwyPlugin implements IPlugin {
32
34
  10 // weight
33
35
  );
34
36
 
37
+ // 注册中间件,修改面包屑路径显示
38
+ ctx.api.registerMiddleware(
39
+ 'transformBreadcrumbPath',
40
+ this.transformBreadcrumbPaths,
41
+ this.id,
42
+ 10 // weight
43
+ );
44
+
35
45
  // 注册logo插槽组件
36
46
  ctx.api.registerSlot('logo', XwyLogo, this.id);
47
+
48
+ // 注册「小乌鸦合集」标题组件
49
+ ctx.api.registerSlot('articleTitle', SpecialTitle, this.id);
50
+ };
51
+
52
+ private transformBreadcrumbPaths = (paths: PathObj[]) => {
53
+ const result = paths.map(p => {
54
+ if (p.name === '小乌鸦合集') {
55
+ return {
56
+ ...p,
57
+ name: '小乌鸦合集',
58
+ className: 'font-xwy text-content-special text-[1.2rem]',
59
+ };
60
+ }
61
+
62
+ return p;
63
+ });
64
+
65
+ console.log('Transformed breadcrumb paths:', result);
66
+
67
+ return result;
37
68
  };
38
69
 
39
70
  /**
@@ -1,8 +1,15 @@
1
- export type SlotName = 'leftCol' | 'rightCol' | 'articleActionRow' | 'logo' | 'route';
1
+ export type SlotName =
2
+ | 'leftCol'
3
+ | 'rightCol'
4
+ | 'articleActionRow'
5
+ | 'logo'
6
+ | 'route'
7
+ | 'articleTitle';
2
8
 
3
9
  export type HookPoint =
4
10
  | 'filterPosts'
5
11
  | 'transformPostContent'
12
+ | 'transformBreadcrumbPath'
6
13
  | 'transformTitleList'
7
14
  | 'extendedRoutes'
8
15
  | 'transformCoverEntry';