@@ -8,24 +8,23 @@ import { getSpeakerById } from "./speakers";
88import { Conference , Day , Speaker , Track } from "types/con" ;
99import { Locale , i18n } from "i18n/i18n-config" ;
1010import MarkdownIt from "markdown-it" ;
11+ import { memoizeAsync } from "utils/memoizeAsync" ;
1112
12- export const getAllConferences = async (
13- edition : string ,
14- withSpeakers : boolean ,
15- locale : Locale
16- ) => {
17- const slugs = (
18- await readdir ( path . join ( process . cwd ( ) , `data/con/${ edition } /conferences` ) )
19- )
20- . filter ( ( el ) => path . extname ( el ) === ".md" )
21- . map ( ( slug ) => slug . replace ( / \. m d $ / , "" ) ) ;
22-
23- return Promise . all (
24- slugs . map ( ( slug ) =>
25- getConferenceData ( edition , slug , false , withSpeakers , locale )
13+ export const getAllConferences = memoizeAsync (
14+ async ( edition : string , withSpeakers : boolean , locale : Locale ) => {
15+ const slugs = (
16+ await readdir ( path . join ( process . cwd ( ) , `data/con/${ edition } /conferences` ) )
2617 )
27- ) ;
28- } ;
18+ . filter ( ( el ) => path . extname ( el ) === ".md" )
19+ . map ( ( slug ) => slug . replace ( / \. m d $ / , "" ) ) ;
20+
21+ return Promise . all (
22+ slugs . map ( ( slug ) =>
23+ getConferenceData ( edition , slug , false , withSpeakers , locale )
24+ )
25+ ) ;
26+ }
27+ ) ;
2928
3029export const getConferencesBySpeaker = async (
3130 edition : string ,
@@ -48,51 +47,58 @@ export const getAllConferenceSlugs = async (edition = "2022") => {
4847 . map ( ( slug : string ) => slug . replace ( / \. m d $ / , "" ) ) ;
4948} ;
5049
51- export const getConferenceData = async (
52- edition : string ,
53- slug : string ,
54- withDescription = true ,
55- withSpeakers = false ,
56- locale : Locale = i18n . defaultLocale
57- ) => {
58- const fileContents = await readFile (
59- path . join ( process . cwd ( ) , `data/con/${ edition } /conferences/${ slug } .md` ) ,
60- "utf8"
61- ) ;
50+ export const getConferenceData = memoizeAsync (
51+ async (
52+ edition : string ,
53+ slug : string ,
54+ withDescription = true ,
55+ withSpeakers = false ,
56+ locale : Locale = i18n . defaultLocale
57+ ) => {
58+ const fileContents = await readFile (
59+ path . join ( process . cwd ( ) , `data/con/${ edition } /conferences/${ slug } .md` ) ,
60+ "utf8"
61+ ) ;
6262
63- const days = ( await import ( `data/con/${ edition } /days` ) ) . default ;
64- const tracks = ( await import ( `data/con/${ edition } /tracks` ) ) . default ;
65- // Use gray-matter to parse the post metadata section
66- const matterResult = matter ( fileContents ) ;
63+ const days = ( await import ( `data/con/${ edition } /days` ) ) . default ;
64+ const tracks = ( await import ( `data/con/${ edition } /tracks` ) ) . default ;
65+ // Use gray-matter to parse the post metadata section
66+ const matterResult = matter ( fileContents ) ;
6767
68- const md = new MarkdownIt ( {
69- html : true ,
70- linkify : true ,
71- typographer : true ,
72- } ) ;
68+ const md = new MarkdownIt ( {
69+ html : true ,
70+ linkify : true ,
71+ typographer : true ,
72+ } ) ;
7373
74- const contentHtml = withDescription ? md . render ( matterResult . content ) : "" ;
74+ const contentHtml = withDescription ? md . render ( matterResult . content ) : "" ;
7575
76- const speakers = matterResult . data . speakers
77- . split ( " " )
78- . map ( ( slug : string ) => slug . substring ( 1 ) ) ;
76+ const speakers = matterResult . data . speakers
77+ . split ( " " )
78+ . map ( ( slug : string ) => slug . substring ( 1 ) ) ;
7979
80- const fullSpeakers = await Promise . all (
81- speakers . map ( ( id : string ) => getSpeakerById ( edition , id , locale ) )
82- ) ;
80+ const fullSpeakers = await Promise . all (
81+ speakers . map ( ( id : string ) => getSpeakerById ( edition , id , locale ) )
82+ ) ;
8383
84- // Combine the data with the id and contentHtml
85- return {
86- slug,
87- edition,
88- description : contentHtml ,
89- url : edition === '2026' ? `/con/${ edition } /conferences/#${ slug } ` : `/con/${ edition } /conferences/${ slug } ` ,
90- ...matterResult . data ,
91- title : unbreakable ( extractTitleFromMarkdown ( matterResult . content ) || "" ) ,
92- speakers : withSpeakers ? fullSpeakers : speakers ,
93- track : tracks . find ( ( track : Track ) => track . id === matterResult . data . track ) ,
94- day :
95- days . length > 1 &&
96- days . find ( ( day : Day ) => day . date === matterResult . data . date ) ,
97- } as unknown as Conference ;
98- } ;
84+ // Combine the data with the id and contentHtml
85+ return {
86+ slug,
87+ edition,
88+ description : contentHtml ,
89+ url :
90+ edition === "2026"
91+ ? `/con/${ edition } /conferences/#${ slug } `
92+ : `/con/${ edition } /conferences/${ slug } ` ,
93+ ...matterResult . data ,
94+ title : unbreakable ( extractTitleFromMarkdown ( matterResult . content ) || "" ) ,
95+ speakers : withSpeakers ? fullSpeakers : speakers ,
96+ track : tracks . find (
97+ ( track : Track ) => track . id === matterResult . data . track
98+ ) ,
99+ day :
100+ days . length > 1 &&
101+ days . find ( ( day : Day ) => day . date === matterResult . data . date ) ,
102+ } as unknown as Conference ;
103+ }
104+ ) ;
0 commit comments