11import type { Response , NextFunction } from 'express'
22import type { ExtendedRequest , Context } from '@/types'
3- import { resolveJourneyContext } from '../lib/journey-path-resolver'
43
54export default async function journeyTrack (
65 req : ExtendedRequest & { context : Context } ,
@@ -10,8 +9,30 @@ export default async function journeyTrack(
109 if ( ! req . context ) throw new Error ( 'request is not contextualized' )
1110 if ( ! req . context . page ) return next ( )
1211
12+ // Only run journey resolution if the page has journey tracks defined
13+ if ( ! ( req . context . page as any ) . journeyTracks ) {
14+ req . context . currentJourneyTrack = null
15+ return next ( )
16+ }
17+
1318 try {
14- const journeyContext = await resolveJourneyContext (
19+ // Import and use the journey resolver which uses renderContent, need the
20+ // async import since it uses fs Node apis
21+ const journeyResolver = await import ( '../lib/journey-path-resolver' )
22+
23+ // resolve the journey tracks which renders the journey content like the
24+ // description to handle liquid rendering
25+ const resolvedTracks = await journeyResolver . resolveJourneyTracks (
26+ ( req . context . page as any ) . journeyTracks ,
27+ req . context ,
28+ )
29+
30+ // Store resolved tracks on the page context for later use in getServerSideProps
31+ ; ( req . context . page as any ) . resolvedJourneyTracks = resolvedTracks
32+
33+ // resolve the current journey context since we're on a journey track page
34+ // i.e. next/prev articles in the track, this article's position in the track
35+ const journeyContext = await journeyResolver . resolveJourneyContext (
1536 req . pagePath || '' ,
1637 req . context . pages || { } ,
1738 req . context ,
0 commit comments