2222tag: {tag}
2323resources:{resources}
2424---
25+ {markdown_content}
26+
2527{shortcodes}\
2628 '''
2729
@@ -132,11 +134,40 @@ def get_images_snippet(year: str, content_id: str) -> (str, str):
132134 return (resources , shortcodes )
133135
134136
135- def create_index_file (year : str , content_id : str , date : datetime , thumbnail : str , tag : str , resources : str ,
136- shortcodes : str ):
137+ def find_markdown_content (input_path : Path ) -> str :
138+ """Find and read the content of a markdown file in the given directory."""
139+ for file_path in input_path .iterdir ():
140+ if file_path .is_file () and file_path .suffix == '.md' :
141+ print (f'Use markdown file: { file_path .name } ' )
142+ with open (file_path , 'r' ) as md_file :
143+ content = md_file .read ()
144+ return content
145+
146+ print ('No markdown file found.' )
147+ return ''
148+
149+
150+ def create_index_file (year : str ,
151+ content_id : str ,
152+ date : datetime ,
153+ thumbnail : str ,
154+ tag : str ,
155+ resources : str ,
156+ shortcodes : str ,
157+ markdown_content : str = '' ):
137158 content_path = _TARGET_BASE_PATH .joinpath (year ).joinpath (content_id )
138159 index_file = content_path .joinpath ('index.md' )
139- index = _INDEX_TEMPLATE .format (date = date , tag = tag , thumbnail = thumbnail , resources = resources , shortcodes = shortcodes )
160+
161+ # Add a newline after markdown content if it exists
162+ if markdown_content and not markdown_content .endswith ('\n ' ):
163+ markdown_content += '\n '
164+
165+ index = _INDEX_TEMPLATE .format (date = date ,
166+ tag = tag ,
167+ thumbnail = thumbnail ,
168+ resources = resources ,
169+ shortcodes = shortcodes ,
170+ markdown_content = markdown_content )
140171
141172 with open (index_file , 'w' ) as file :
142173 file .write (index )
@@ -158,8 +189,13 @@ def create_index_file(year: str, content_id: str, date: datetime, thumbnail: str
158189 date = parse_date_from_path (input_path )
159190 copy_images (args .year , args .id , input_path )
160191 (resources , shortcodes ) = get_images_snippet (args .year , args .id )
192+
193+ # Find and read markdown content
194+ markdown_content = find_markdown_content (input_path )
195+
161196 thumbnail_path = _THUMBNAIL_BASE_PATH .joinpath (args .year ).joinpath (f'{ args .id } .jpg' )
162- create_index_file (args .year , args .id , date , str (thumbnail_path ), tag , resources , shortcodes )
197+ create_index_file (args .year , args .id , date , str (thumbnail_path ), tag , resources , shortcodes ,
198+ markdown_content )
163199
164200 elif args .command == 'print' :
165201 print_content (args .year , args .id )
0 commit comments