@@ -167,15 +167,27 @@ export async function getPagesList(): Promise<LanguageEntry[]> {
167167 ) ;
168168}
169169
170- export async function getSectionsList (
170+ export async function getRevisions (
171+ sectionId : SectionId
172+ ) : Promise < RevisionYmlEntry | undefined > {
173+ const revisionsYml = await readPublicFile ( `docs/revisions.yml` ) ;
174+ return ( yaml . load ( revisionsYml ) as Record < string , RevisionYmlEntry > ) [
175+ sectionId
176+ ] ;
177+ }
178+
179+ /**
180+ * public/docs/{lang}/{pageId}/ 以下のmdファイルを結合して MarkdownSection[] を返す。
181+ */
182+ export async function getMarkdownSections (
171183 lang : LangId ,
172184 page : PageSlug
173- ) : Promise < string [ ] > {
185+ ) : Promise < MarkdownSection [ ] > {
174186 if ( isCloudflare ( ) ) {
175187 const sectionsJson = await readPublicFile (
176188 `docs/${ lang } /${ page } /sections.json`
177189 ) ;
178- return JSON . parse ( sectionsJson ) as string [ ] ;
190+ return JSON . parse ( sectionsJson ) as MarkdownSection [ ] ;
179191 } else {
180192 function naturalSortMdFiles ( a : string , b : string ) : number {
181193 // -intro.md always comes first
@@ -191,48 +203,29 @@ export async function getSectionsList(
191203 }
192204 return a . localeCompare ( b ) ;
193205 }
194- return ( await readdir ( join ( process . cwd ( ) , "public" , "docs" , lang , page ) ) )
206+ const files = ( await readdir ( join ( process . cwd ( ) , "public" , "docs" , lang , page ) ) )
195207 . filter ( ( f ) => f . endsWith ( ".md" ) )
196208 . sort ( naturalSortMdFiles ) ;
197- }
198- }
199209
200- export async function getRevisions (
201- sectionId : SectionId
202- ) : Promise < RevisionYmlEntry | undefined > {
203- const revisionsYml = await readPublicFile ( `docs/revisions.yml` ) ;
204- return ( yaml . load ( revisionsYml ) as Record < string , RevisionYmlEntry > ) [
205- sectionId
206- ] ;
207- }
208-
209- /**
210- * public/docs/{lang}/{pageId}/ 以下のmdファイルを結合して MarkdownSection[] を返す。
211- */
212- export async function getMarkdownSections (
213- lang : LangId ,
214- page : PageSlug
215- ) : Promise < MarkdownSection [ ] > {
216- const files = await getSectionsList ( lang , page ) ;
217-
218- const sections : MarkdownSection [ ] = [ ] ;
219- for ( const file of files ) {
220- const raw = await readPublicFile ( `docs/${ lang } /${ page } /${ file } ` ) ;
221- if ( file === "-intro.md" ) {
222- // イントロセクションはフロントマターなし・見出しなし
223- sections . push ( {
224- file,
225- id : introSectionId ( { lang, page } ) ,
226- level : 1 ,
227- title : "" ,
228- rawContent : raw ,
229- md5 : crypto . createHash ( "md5" ) . update ( raw ) . digest ( "base64" ) ,
230- } ) ;
231- } else {
232- sections . push ( parseFrontmatter ( raw , file ) ) ;
210+ const sections : MarkdownSection [ ] = [ ] ;
211+ for ( const file of files ) {
212+ const raw = await readPublicFile ( `docs/${ lang } /${ page } /${ file } ` ) ;
213+ if ( file === "-intro.md" ) {
214+ // イントロセクションはフロントマターなし・見出しなし
215+ sections . push ( {
216+ file,
217+ id : introSectionId ( { lang, page } ) ,
218+ level : 1 ,
219+ title : "" ,
220+ rawContent : raw ,
221+ md5 : crypto . createHash ( "md5" ) . update ( raw ) . digest ( "base64" ) ,
222+ } ) ;
223+ } else {
224+ sections . push ( parseFrontmatter ( raw , file ) ) ;
225+ }
233226 }
227+ return sections ;
234228 }
235- return sections ;
236229}
237230export function introSectionId ( path : PagePath ) {
238231 return `${ path . lang } -${ path . page } -intro` as SectionId ;
0 commit comments