@@ -2,150 +2,116 @@ import meta from "../../pages/learn/_meta"
22
33type LearnPagePath = Exclude < keyof typeof meta , `-- ${string } ` | "index" >
44
5- function getTitle ( path : LearnPagePath ) : string {
6- const entry = meta [ path as keyof typeof meta ]
7- if ( typeof entry === "string" ) {
8- return (
9- entry || path . replace ( / - / g, " " ) . replace ( / \b \w / g, c => c . toUpperCase ( ) )
10- )
11- } else if ( typeof entry === "object" && "title" in entry ) {
12- return entry . title
13- }
14- return path . replace ( / - / g, " " ) . replace ( / \b \w / g, c => c . toUpperCase ( ) )
5+ interface LearnPageItem {
6+ title : string
7+ description : string
8+ icon : string
9+ section : "getting-started" | "best-practices"
1510}
1611
17- export const learnPages : Record <
18- LearnPagePath ,
19- {
20- title : string
21- description : string
22- icon : string
23- section : "getting-started" | "best-practices"
24- } | null
25- > = {
12+ const _items : Record < LearnPagePath , Omit < LearnPageItem , "title" > | null > = {
2613 introduction : {
27- title : getTitle ( "introduction" ) ,
2814 description : "" ,
2915 icon : "" ,
3016 section : "getting-started" ,
3117 } ,
3218 schema : {
33- title : getTitle ( "schema" ) ,
3419 description : "" ,
3520 icon : "" ,
3621 section : "getting-started" ,
3722 } ,
3823 queries : {
39- title : getTitle ( "queries" ) ,
4024 description : "" ,
4125 icon : "" ,
4226 section : "getting-started" ,
4327 } ,
4428 mutations : {
45- title : getTitle ( "mutations" ) ,
4629 description : "" ,
4730 icon : "" ,
4831 section : "getting-started" ,
4932 } ,
5033 subscriptions : {
51- title : getTitle ( "subscriptions" ) ,
5234 description : "" ,
5335 icon : "" ,
5436 section : "getting-started" ,
5537 } ,
5638 validation : {
57- title : getTitle ( "validation" ) ,
5839 description : "" ,
5940 icon : "" ,
6041 section : "getting-started" ,
6142 } ,
6243 execution : {
63- title : getTitle ( "execution" ) ,
6444 description : "" ,
6545 icon : "" ,
6646 section : "getting-started" ,
6747 } ,
6848 response : {
69- title : getTitle ( "response" ) ,
7049 description : "" ,
7150 icon : "" ,
7251 section : "getting-started" ,
7352 } ,
7453 introspection : {
75- title : getTitle ( "introspection" ) ,
7654 description : "" ,
7755 icon : "" ,
7856 section : "getting-started" ,
7957 } ,
8058 // ---
8159 "best-practices" : {
82- title : getTitle ( "best-practices" ) ,
8360 description : "" ,
8461 icon : "" ,
8562 section : "best-practices" ,
8663 } ,
8764 "thinking-in-graphs" : {
88- title : getTitle ( "thinking-in-graphs" ) ,
8965 description : "" ,
9066 icon : "" ,
9167 section : "best-practices" ,
9268 } ,
9369 "serving-over-http" : {
94- title : getTitle ( "serving-over-http" ) ,
9570 description : "" ,
9671 icon : "" ,
9772 section : "best-practices" ,
9873 } ,
9974 "file-uploads" : {
100- title : getTitle ( "file-uploads" ) ,
10175 description : "" ,
10276 icon : "" ,
10377 section : "best-practices" ,
10478 } ,
10579 authorization : {
106- title : getTitle ( "authorization" ) ,
10780 description : "" ,
10881 icon : "" ,
10982 section : "best-practices" ,
11083 } ,
11184 pagination : {
112- title : getTitle ( "pagination" ) ,
11385 description : "" ,
11486 icon : "" ,
11587 section : "best-practices" ,
11688 } ,
11789 "schema-design" : {
118- title : getTitle ( "schema-design" ) ,
11990 description : "" ,
12091 icon : "" ,
12192 section : "best-practices" ,
12293 } ,
12394 "global-object-identification" : {
124- title : getTitle ( "global-object-identification" ) ,
12595 description : "" ,
12696 icon : "" ,
12797 section : "best-practices" ,
12898 } ,
12999 caching : {
130- title : getTitle ( "caching" ) ,
131100 description : "" ,
132101 icon : "" ,
133102 section : "best-practices" ,
134103 } ,
135104 performance : {
136- title : getTitle ( "performance" ) ,
137105 description : "" ,
138106 icon : "" ,
139107 section : "best-practices" ,
140108 } ,
141109 security : {
142- title : getTitle ( "security" ) ,
143110 description : "" ,
144111 icon : "" ,
145112 section : "best-practices" ,
146113 } ,
147114 federation : {
148- title : getTitle ( "federation" ) ,
149115 description : "" ,
150116 icon : "" ,
151117 section : "best-practices" ,
@@ -154,3 +120,21 @@ export const learnPages: Record<
154120 // omitted on Learn index page
155121 "debug-errors" : null ,
156122}
123+
124+ export const learnPages = _items as Record < LearnPagePath , LearnPageItem | null >
125+
126+ for ( const path in learnPages ) {
127+ const page = learnPages [ path as LearnPagePath ]
128+ if ( page === null ) continue
129+ const metaEntry = meta [ path as keyof typeof meta ]
130+
131+ if ( typeof metaEntry === "string" ) {
132+ page . title =
133+ metaEntry ||
134+ path . replace ( / - / g, " " ) . replace ( / \b \w / g, c => c . toUpperCase ( ) )
135+ } else if ( typeof metaEntry === "object" && "title" in metaEntry ) {
136+ page . title = metaEntry . title
137+ } else {
138+ page . title = path . replace ( / - / g, " " ) . replace ( / \b \w / g, c => c . toUpperCase ( ) )
139+ }
140+ }
0 commit comments