File tree 6 files changed +39
-12
lines changed
6 files changed +39
-12
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ export async function waitForApp(path: string): Promise<PageData> {
19
19
const pagePath = cleanUrl ( ( matched [ 0 ] . route as Route ) . filePath ) ;
20
20
const relativePagePath = getRelativePagePath ( path , pagePath , siteData . base ) ;
21
21
// API Page
22
- if ( mod . api || mod . pageType === 'api' ) {
22
+ if ( mod ?. meta ?. api || mod ?. meta ? .pageType === 'api' ) {
23
23
const subModules = await Promise . all (
24
24
routes
25
25
. filter (
@@ -38,16 +38,18 @@ export async function waitForApp(path: string): Promise<PageData> {
38
38
siteData,
39
39
pagePath,
40
40
relativePagePath,
41
- pageType : 'api' ,
42
- subModules
41
+ subModules,
42
+ ...omit ( mod , [ 'default' ] ) ,
43
+ pageType : 'api'
43
44
} ;
44
45
} else {
45
46
// Doc/Custom Page
46
47
return {
47
48
siteData,
48
49
pagePath,
49
50
relativePagePath,
50
- ...omit ( mod , [ 'default' ] )
51
+ ...omit ( mod , [ 'default' ] ) ,
52
+ pageType : mod ?. meta ?. pageType || 'doc'
51
53
} as PageData ;
52
54
}
53
55
} else {
Original file line number Diff line number Diff line change @@ -146,19 +146,30 @@ export type ComponentPropsWithIsland<T = unknown> = T & { __island: boolean };
146
146
147
147
export interface PageModule < T extends ComponentType < unknown > > {
148
148
default : T ;
149
+ meta ?: FrontMatterMeta ;
149
150
[ key : string ] : unknown ;
150
151
}
151
152
153
+ export type PageType = 'home' | 'doc' | 'api' | 'custom' | '404' ;
154
+
155
+ export interface FrontMatterMeta {
156
+ title : string ;
157
+ description : string ;
158
+ api : boolean ;
159
+ pageType : PageType ;
160
+ features ?: Feature [ ] ;
161
+ hero ?: Hero ;
162
+ }
163
+
152
164
export interface PageData {
153
165
siteData : SiteData < DefaultTheme . Config > ;
154
166
pagePath : string ;
155
167
relativePagePath : string ;
156
168
title ?: string ;
169
+ meta ?: FrontMatterMeta ;
157
170
description ?: string ;
158
- pageType : 'home' | 'doc' | 'api' | 'custom' | '404' ;
171
+ pageType : PageType ;
159
172
toc ?: Header [ ] ;
160
- features ?: Feature [ ] ;
161
- hero ?: Hero ;
162
173
icon ?: string ;
163
174
subModules ?: PageModule < ComponentType < unknown > > [ ] ;
164
175
}
Original file line number Diff line number Diff line change @@ -16,7 +16,8 @@ const getGridClass = (count?: number) => {
16
16
} ;
17
17
18
18
export function HomeFeature ( ) {
19
- const { features } = usePageData ( ) ;
19
+ const { meta } = usePageData ( ) ;
20
+ const features = meta ?. features ;
20
21
const gridClass = getGridClass ( features ?. length ) ;
21
22
return (
22
23
< div className = { styles . features } >
Original file line number Diff line number Diff line change @@ -12,7 +12,8 @@ const DEFAULT_HERO = {
12
12
} ;
13
13
14
14
export function HomeHero ( ) {
15
- const { hero = DEFAULT_HERO } = usePageData ( ) ;
15
+ const { meta } = usePageData ( ) ;
16
+ const hero = meta ?. hero || DEFAULT_HERO ;
16
17
const hasImage = hero . image !== undefined ;
17
18
18
19
return (
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ interface GroupItem {
13
13
14
14
export function APILayout ( ) {
15
15
const { subModules = [ ] } = usePageData ( ) ;
16
+
16
17
const initialGroups = subModules . map ( ( subModule ) => {
17
18
const { routePath, title } = subModule ;
18
19
return {
@@ -23,17 +24,21 @@ export function APILayout() {
23
24
} ) ;
24
25
const [ groups , setGroups ] = useState ( initialGroups ) ;
25
26
27
+ console . log ( groups ) ;
28
+
26
29
useEffect ( ( ) => {
27
30
// Handle title hmr
28
31
if ( import . meta. env . DEV ) {
29
32
import . meta. hot ?. on ( 'md(x)-changed' , ( { routePath, filePath } ) => {
33
+ console . log ( routePath ) ;
30
34
const group = groups . find ( ( group ) => group . link === routePath ) ;
31
35
if ( ! group ) {
32
36
return ;
33
37
}
34
38
import ( /* @vite -ignore */ `${ filePath } ?import&t=${ Date . now ( ) } ` ) . then (
35
39
( mod ) => {
36
40
group . headers = mod . toc ;
41
+ group . text = mod . title ;
37
42
setGroups ( [ ...groups ] ) ;
38
43
}
39
44
) ;
Original file line number Diff line number Diff line change @@ -8,9 +8,16 @@ import { Helmet } from 'react-helmet-async';
8
8
import { APILayout } from '../APILayout' ;
9
9
10
10
export const Layout : React . FC = ( ) => {
11
- const { pageType, title : pageTitle , description, siteData } = usePageData ( ) ;
12
- // Priority page title > site title
13
- const title = pageTitle || siteData ?. title ;
11
+ const {
12
+ // Inject by remark-plugin-toc
13
+ title : articleTitle ,
14
+ meta,
15
+ siteData,
16
+ pageType
17
+ } = usePageData ( ) ;
18
+ // Priority: front matter title > h1 title > site title
19
+ const title = ( meta ?. title ?? articleTitle ) || siteData ?. title ;
20
+ const description = meta ?. description || siteData . description ;
14
21
// Use doc layout by default
15
22
const getContentLayout = ( ) => {
16
23
switch ( pageType ) {
You can’t perform that action at this time.
0 commit comments