@@ -37,19 +37,23 @@ def standardize_data(content_type: tContentType, content: dict) -> dict:
3737 is_featured = content ["slug" ] == featured_post or content ["location" ].endswith (
3838 featured_post
3939 )
40+ # `frontmatter.get(key, default)` only falls back when the key is missing —
41+ # but YAML parses `thumbnail:` (empty value) as None, which then propagates
42+ # into convert_paths() and crashes the string concatenation. Coerce here
43+ # so downstream sees "" / [] consistently.
4044 return {
4145 "version" : content ["version" ],
4246 "slug" : content ["slug" ],
4347 "location" : content ["location" ],
4448 "featured" : is_featured ,
4549 # frontmatter fields
46- "title" : frontmatter .get ("title" , "" ) ,
47- "description" : frontmatter .get ("description" , "" ) ,
48- "tags" : frontmatter .get ("tags" , []) ,
49- "date" : frontmatter .get ("date" , "" ) ,
50- "thumbnail" : frontmatter .get ("thumbnail" , "" ) ,
51- "thumbnailOptimized" : frontmatter .get ("thumbnailOptimized" , "" ) ,
52- "authors" : frontmatter .get ("authors" , []) ,
50+ "title" : frontmatter .get ("title" ) or "" ,
51+ "description" : frontmatter .get ("description" ) or "" ,
52+ "tags" : frontmatter .get ("tags" ) or [] ,
53+ "date" : frontmatter .get ("date" ) or "" ,
54+ "thumbnail" : frontmatter .get ("thumbnail" ) or "" ,
55+ "thumbnailOptimized" : frontmatter .get ("thumbnailOptimized" ) or "" ,
56+ "authors" : frontmatter .get ("authors" ) or [] ,
5357 }
5458
5559
@@ -63,11 +67,15 @@ def convert_paths(content_type: tContentType, output_file: Path):
6367
6468 for item in content :
6569 if not item .get ("thumbnailOptimized" ):
66- item ["thumbnailOptimized" ] = item ["thumbnail" ]
67- item ["thumbnail" ] = f"/{ content_type } /build" + item ["thumbnail" ]
68- item ["thumbnailOptimized" ] = (
69- f"/{ content_type } /build" + item ["thumbnailOptimized" ]
70- )
70+ item ["thumbnailOptimized" ] = item .get ("thumbnail" ) or ""
71+ # Skip path prefixing when there's no thumbnail — prepending to "" would
72+ # produce a bogus "/blog/build" URL that 404s in the frontend.
73+ if item .get ("thumbnail" ):
74+ item ["thumbnail" ] = f"/{ content_type } /build" + item ["thumbnail" ]
75+ if item .get ("thumbnailOptimized" ):
76+ item ["thumbnailOptimized" ] = (
77+ f"/{ content_type } /build" + item ["thumbnailOptimized" ]
78+ )
7179
7280 with open (output_file , "w" , encoding = "utf-8" ) as f :
7381 json .dump (content , f , indent = 2 , ensure_ascii = False )
0 commit comments