11import path from "path" ;
22import * as fs from "fs" ;
3- import { createSlug , SpeakerData , TopicsData , unsluggify } from "./src/utils" ;
3+ import {
4+ ContentData ,
5+ createSlug ,
6+ SpeakerData ,
7+ TopicsData ,
8+ unsluggify ,
9+ } from "./src/utils" ;
410import {
511 defineDocumentType ,
612 defineNestedType ,
@@ -30,10 +36,10 @@ export interface Topic {
3036
3137// The full processed topic we use internally
3238interface ProcessedTopic {
33- name : string ; // Display name (from topic.title or original tag)
34- slug : string ; // Slugified identifier
35- count : number ; // Number of occurrences
36- categories : string [ ] ; // List of categories it belongs to
39+ name : string ; // Display name (from topic.title or original tag)
40+ slug : string ; // Slugified identifier
41+ count : number ; // Number of occurrences
42+ categories : string [ ] ; // List of categories it belongs to
3743}
3844
3945interface TagInfo {
@@ -46,7 +52,6 @@ interface ContentTree {
4652 [ key : string ] : ContentTree | ContentTranscriptType [ ] ;
4753}
4854
49-
5055const getTranscriptAliases = ( allTranscripts : ContentTranscriptType [ ] ) => {
5156 const aliases : Record < string , string > = { } ;
5257
@@ -69,20 +74,24 @@ const getTopics = () => {
6974 return JSON . parse ( fileContents ) ;
7075} ;
7176
72- function buildTopicsMap ( transcripts : ContentTranscriptType [ ] , topics : Topic [ ] ) : Map < string , ProcessedTopic > {
77+
78+ function buildTopicsMap (
79+ transcripts : ContentTranscriptType [ ] ,
80+ topics : Topic [ ]
81+ ) : Map < string , ProcessedTopic > {
7382 // Create topics lookup map (includes aliases)
7483 const topicsLookup = new Map < string , Topic > ( ) ;
75- topics . forEach ( topic => {
84+ topics . forEach ( ( topic ) => {
7685 topicsLookup . set ( topic . slug , topic ) ;
77- topic . aliases ?. forEach ( alias => topicsLookup . set ( alias , topic ) ) ;
86+ topic . aliases ?. forEach ( ( alias ) => topicsLookup . set ( alias , topic ) ) ;
7887 } ) ;
7988
8089 // Build the main topics map
8190 const processedTopics = new Map < string , ProcessedTopic > ( ) ;
8291
8392 // Process all transcripts
84- transcripts . forEach ( transcript => {
85- transcript . tags ?. forEach ( tag => {
93+ transcripts . forEach ( ( transcript ) => {
94+ transcript . tags ?. forEach ( ( tag ) => {
8695 const slug = createSlug ( tag ) ;
8796 const topic = topicsLookup . get ( slug ) ;
8897
@@ -99,11 +108,12 @@ function buildTopicsMap(transcripts: ContentTranscriptType[], topics: Topic[]):
99108 }
100109 } ) ;
101110 } ) ;
102-
103111 return processedTopics ;
104112}
105113
106- function generateAlphabeticalList ( processedTopics : Map < string , ProcessedTopic > ) : TopicsData [ ] {
114+ function generateAlphabeticalList (
115+ processedTopics : Map < string , ProcessedTopic >
116+ ) : TopicsData [ ] {
107117 const result : TopicsData [ ] = [ ] ;
108118 // The categories property is not needed for this list, so we drop it
109119 for ( const { name, slug, count } of processedTopics . values ( ) ) {
@@ -112,30 +122,35 @@ function generateAlphabeticalList(processedTopics: Map<string, ProcessedTopic>):
112122 return result . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
113123}
114124
115- function generateCategorizedList ( processedTopics : Map < string , ProcessedTopic > ) : Record < string , TopicsData [ ] > {
125+ function generateCategorizedList (
126+ processedTopics : Map < string , ProcessedTopic >
127+ ) : Record < string , TopicsData [ ] > {
116128 const categorizedTopics : Record < string , TopicsData [ ] > = { } ;
117129
118- Array . from ( processedTopics . values ( ) ) . forEach ( ( { name, slug, count, categories } ) => {
119- categories . forEach ( category => {
120- if ( ! categorizedTopics [ category ] ) {
121- categorizedTopics [ category ] = [ ] ;
122- }
123-
124- // Check if topic name contains category name and ends with "(Miscellaneous)"
125- const modifiedName = name . includes ( category ) && name . endsWith ( "(Miscellaneous)" )
126- ? "Miscellaneous"
127- : name ;
128-
129- categorizedTopics [ category ] . push ( { name : modifiedName , slug, count } ) ;
130- } ) ;
131- } ) ;
130+ Array . from ( processedTopics . values ( ) ) . forEach (
131+ ( { name, slug, count, categories } ) => {
132+ categories . forEach ( ( category ) => {
133+ if ( ! categorizedTopics [ category ] ) {
134+ categorizedTopics [ category ] = [ ] ;
135+ }
136+
137+ // Check if topic name contains category name and ends with "(Miscellaneous)"
138+ const modifiedName =
139+ name . includes ( category ) && name . endsWith ( "(Miscellaneous)" )
140+ ? "Miscellaneous"
141+ : name ;
142+
143+ categorizedTopics [ category ] . push ( { name : modifiedName , slug, count } ) ;
144+ } ) ;
145+ }
146+ ) ;
132147
133148 // Sort topics within each category
134- Object . values ( categorizedTopics ) . forEach ( topics => {
149+ Object . values ( categorizedTopics ) . forEach ( ( topics ) => {
135150 topics . sort ( ( a , b ) => {
136151 if ( a . name == "Miscellaneous" ) return 1 ;
137152 if ( b . name == "Miscellaneous" ) return - 1 ;
138- return a . name . localeCompare ( b . name )
153+ return a . name . localeCompare ( b . name ) ;
139154 } ) ;
140155 } ) ;
141156
@@ -331,7 +346,7 @@ function organizeContent(
331346 fs . writeFileSync ( "./public/sources-data.json" , JSON . stringify ( tree , null , 2 ) ) ;
332347}
333348
334- const getLanCode = / [ . ] \w { 2 } $ / gi // Removes the last two characters if there's a dot
349+ const getLanCode = / [ . ] \w { 2 } $ / gi; // Removes the last two characters if there's a dot
335350
336351export const Transcript = defineDocumentType ( ( ) => ( {
337352 name : "Transcript" ,
@@ -363,6 +378,32 @@ export const Transcript = defineDocumentType(() => ({
363378 source_file : { type : "string" } ,
364379 } ,
365380 computedFields : {
381+ tagsDetailed : {
382+ type : "list" ,
383+ resolve : ( doc ) => {
384+ // doc?.tags doesn't give an array in contentLayer so we do _array to get it
385+ const topicsStore = doc ?. tags as any || [ ] ;
386+ const topics = ( topicsStore ?. _array as string [ ] ) ?? [ ] ;
387+
388+ const topicsWithTitles = topics . map ( ( topic ) => {
389+ const currentTopic = getTopics ( ) . find (
390+ ( topicData : ContentData ) => topicData . slug === topic
391+ ) ;
392+
393+ if ( currentTopic ?. title && currentTopic ?. title . includes ( "(Miscellaneous)" ) ) {
394+ return {
395+ name : currentTopic ?. title . replace ( "(Miscellaneous)" , "" ) ,
396+ slug : currentTopic . slug ,
397+ }
398+ }
399+ return {
400+ name : currentTopic ?. title || topic ,
401+ slug : currentTopic ?. slug || topic ,
402+ } ;
403+ } ) ;
404+ return topicsWithTitles ;
405+ } ,
406+ } ,
366407 url : {
367408 type : "string" ,
368409 resolve : ( doc ) => `/${ doc . _raw . flattenedPath } ` ,
@@ -389,7 +430,7 @@ export const Transcript = defineDocumentType(() => ({
389430 ) ;
390431
391432 const lan = transcript ?. match ( getLanCode ) ;
392- const languageCode = ( lan ?. [ 0 ] || "" ) . replace ( "." , "" )
433+ const languageCode = ( lan ?. [ 0 ] || "" ) . replace ( "." , "" ) ;
393434
394435 if ( LanguageCodes . includes ( languageCode ) ) {
395436 return `/${ languageCode } /${ fullPathWithoutDot } ` ;
@@ -401,10 +442,7 @@ export const Transcript = defineDocumentType(() => ({
401442 slugAsParams : {
402443 type : "list" ,
403444 resolve : ( doc ) => {
404- const pathWithoutDot = doc . _raw . flattenedPath . replace (
405- getLanCode ,
406- ""
407- ) ;
445+ const pathWithoutDot = doc . _raw . flattenedPath . replace ( getLanCode , "" ) ;
408446 return pathWithoutDot . split ( "/" ) ;
409447 } ,
410448 } ,
0 commit comments