@@ -5,6 +5,7 @@ import type {ValueOf} from 'type-fest';
5
5
type Article = {
6
6
href : string ;
7
7
title : string ;
8
+ order ?: number ;
8
9
} ;
9
10
10
11
type Section = {
@@ -60,11 +61,12 @@ function toTitleCase(str: string): string {
60
61
/**
61
62
* @param filename - The name of the file
62
63
*/
63
- function getArticleObj ( filename : string ) : Article {
64
+ function getArticleObj ( filename : string , order ?: number ) : Article {
64
65
const href = filename . replace ( '.md' , '' ) ;
65
66
return {
66
67
href,
67
68
title : toTitleCase ( href . replaceAll ( '-' , ' ' ) ) ,
69
+ order,
68
70
} ;
69
71
}
70
72
@@ -90,6 +92,12 @@ function pushOrCreateEntry<TKey extends HubEntriesKey>(hubs: Hub[], hub: string,
90
92
}
91
93
}
92
94
95
+ function getOrderFromArticleFrontMatter ( path : string ) : number | undefined {
96
+ const frontmatter = fs . readFileSync ( path , 'utf8' ) . split ( '---' ) [ 1 ] ;
97
+ const frontmatterObject = yaml . load ( frontmatter ) as Record < string , unknown > ;
98
+ return frontmatterObject . order as number | undefined ;
99
+ }
100
+
93
101
/**
94
102
* Add articles and sections to hubs
95
103
* @param hubs - The hubs inside docs/articles/ for a platform
@@ -113,7 +121,8 @@ function createHubsWithArticles(hubs: string[], platformName: ValueOf<typeof pla
113
121
114
122
// Each subfolder will be a section containing articles
115
123
fs . readdirSync ( `${ docsDir } /articles/${ platformName } /${ hub } /${ section } ` ) . forEach ( ( subArticle ) => {
116
- articles . push ( getArticleObj ( subArticle ) ) ;
124
+ const order = getOrderFromArticleFrontMatter ( `${ docsDir } /articles/${ platformName } /${ hub } /${ section } /${ subArticle } ` ) ;
125
+ articles . push ( getArticleObj ( subArticle , order ) ) ;
117
126
} ) ;
118
127
119
128
pushOrCreateEntry ( routeHubs , hub , 'sections' , {
0 commit comments