@@ -357,7 +357,17 @@ async function getPublicAuthorDocuments() {
357357 }
358358}
359359
360- async function getPublishedArticleDocuments ( ) : Promise < ContentDocument [ ] > {
360+ function normalizeRouteSlug ( slug : string ) {
361+ try {
362+ return decodeURIComponent ( slug ) . trim ( ) ;
363+ } catch {
364+ return slug . trim ( ) ;
365+ }
366+ }
367+
368+ async function getPublishedArticleDocuments (
369+ revalidateSeconds : number | false = 300 ,
370+ ) : Promise < ContentDocument [ ] > {
361371 const { apiKey, projectId } = getRequiredFirebaseConfig ( ) ;
362372 const params = new URLSearchParams ( { key : apiKey } ) ;
363373 const response = await fetch (
@@ -379,7 +389,9 @@ async function getPublishedArticleDocuments(): Promise<ContentDocument[]> {
379389 } ,
380390 } ,
381391 } ) ,
382- next : { revalidate : 300 } ,
392+ ...( revalidateSeconds === false
393+ ? { cache : "no-store" as const }
394+ : { next : { revalidate : revalidateSeconds } } ) ,
383395 } ,
384396 ) ;
385397
@@ -532,10 +544,16 @@ export async function getPublishedArticles(limitCount?: number) {
532544}
533545
534546export async function getPublishedArticleBySlug ( slug : string ) {
547+ const normalizedSlug = normalizeRouteSlug ( slug ) ;
535548 const authors = await getAllAuthors ( ) ;
536549 const authorLookup = createAuthorLookup ( authors ) ;
537550 const documents = await getPublishedArticleDocuments ( ) ;
538- const document = documents . find ( ( entry ) => entry . data . slug === slug ) ;
551+ const cached = documents . find ( ( entry ) => entry . data . slug === normalizedSlug ) ;
552+ const document =
553+ cached ||
554+ ( await getPublishedArticleDocuments ( false ) ) . find (
555+ ( entry ) => entry . data . slug === normalizedSlug ,
556+ ) ;
539557
540558 if ( ! document ) return null ;
541559
0 commit comments