11import { createDomain } from "~/utils/http"
22import { loadContentCollections } from "~/utils/load-content-collections"
3- import type { PageRec , SectionRec } from "../../content-collections"
3+ import type { PageRecord , SectionRecord } from "../../content-collections"
44import { pageUrl } from "./version-links"
55import { versions } from "./versions"
66import type { Version } from "./versions-utils"
@@ -15,20 +15,20 @@ async function loadVersionData(version: Version) {
1515}
1616
1717async function loadAllVersions ( ) {
18- const acc : Record < string , { pages : PageRec [ ] ; sections : SectionRec [ ] } > = { }
18+ const acc : Record < string , { pages : PageRecord [ ] ; sections : SectionRecord [ ] } > = { }
1919 for ( const v of versions ) {
2020 const loaded = await loadVersionData ( v )
2121 if ( loaded ) acc [ v ] = loaded
2222 }
2323 return acc
2424}
2525
26- function buildSectionTitles ( sections : SectionRec [ ] ) {
26+ function buildSectionTitles ( sections : SectionRecord [ ] ) {
2727 return new Map ( sections . map ( ( s ) => [ s . slug . split ( "/" ) . pop ( ) || "" , s . title ] ) )
2828}
2929
30- function groupPagesByFolder ( pages : PageRec [ ] ) {
31- const groups = new Map < string , PageRec [ ] > ( )
30+ function groupPagesByFolder ( pages : PageRecord [ ] ) {
31+ const groups = new Map < string , PageRecord [ ] > ( )
3232
3333 for ( const p of pages ) {
3434 const id = p . section ?? p . _meta ?. path ?. split ( "/" ) [ 0 ]
@@ -45,25 +45,25 @@ function groupPagesByFolder(pages: PageRec[]) {
4545 return groups
4646}
4747
48- function renderVersionBlock ( domain : string , version : string , pages : PageRec [ ] , sections : SectionRec [ ] ) {
48+ function renderVersionBlock ( domain : string , version : string , pages : PageRecord [ ] , sections : SectionRecord [ ] ) {
4949 if ( ! pages . length ) return `## ${ version } \n\n_No pages found._`
5050
5151 const sectionTitles = buildSectionTitles ( sections )
5252 const groups = groupPagesByFolder ( pages )
5353
54- const blocks = Array . from ( groups . entries ( ) )
55- . map ( ( [ id , list ] ) => {
56- const label = sectionTitles . get ( id ) ?? id
57- const lines = list
58- . map ( ( p ) => {
59- const url = pageUrl ( domain , version , p . slug )
60- const note = p . summary || p . description || ""
61- return `- [ ${ p . title } ]( ${ url } ) ${ note ? `: ${ note } ` : "" } `
62- } )
63- . join ( "\n" )
64- return `### ${ label } \n\n ${ lines } `
65- } )
66- . join ( "\n\n" )
54+ const renderPageLink = ( p : PageRecord ) => {
55+ const url = pageUrl ( domain , version , p . slug )
56+ const note = p . summary || p . description || ""
57+ return `- [ ${ p . title } ]( ${ url } ) ${ note ? `: ${ note } ` : "" } `
58+ }
59+
60+ const renderSection = ( [ id , list ] : [ string , PageRecord [ ] ] ) => {
61+ const label = sectionTitles . get ( id ) ?? id
62+ const lines = list . map ( renderPageLink ) . join ( "\n" )
63+ return `### ${ label } \n\n ${ lines } `
64+ }
65+
66+ const blocks = Array . from ( groups . entries ( ) ) . map ( renderSection ) . join ( "\n\n" )
6767
6868 return `\n## ${ version } \n\n${ blocks } `
6969}
0 commit comments