22
33"""Generates epub and pdf from sources."""
44
5+ import datetime
56import pathlib
67import re
78import shutil
@@ -102,7 +103,7 @@ def build_pdf_book(self, language: str, markdown_filepath: pathlib.Path) -> None
102103 "-H" , "./ebook/listings-setup.tex" ,
103104 "-o" , f"./ebook/Vulkan Tutorial { language } .pdf" ,
104105 "--pdf-engine=xelatex" ,
105- "--metadata=title:Vulkan Tutorial"
106+ # "--metadata=title:Vulkan Tutorial"
106107 ]
107108 )
108109 except subprocess .CalledProcessError as error :
@@ -124,7 +125,7 @@ def build_epub_book(self, language: str, markdown_filepath: pathlib.Path) -> Non
124125 "--toc" ,
125126 "-o" , f"./ebook/Vulkan Tutorial { language } .epub" ,
126127 "--epub-cover-image=ebook/cover.png" ,
127- "--metadata=title:Vulkan Tutorial"
128+ # "--metadata=title:Vulkan Tutorial"
128129 ]
129130 )
130131 except subprocess .CalledProcessError as error :
@@ -174,8 +175,14 @@ def generate_joined_markdown(self, language: str, output_filename: pathlib.Path)
174175 md_files = self ._collect_markdown_files_from_source (language )
175176 md_files = sorted (md_files , key = lambda file : file .prefix )
176177
177- temp_markdown : str = str ()
178+ # Add title.
179+ current_date : str = datetime .datetime .now ().strftime ('%B %Y' )
178180
181+ temp_markdown : str = (
182+ "% Vulkan Tutorial\n "
183+ "% Alexander Overvoorde\n "
184+ f"% { current_date } \n \n "
185+ )
179186
180187 def repl_hash (match ):
181188 """Calculates the proper `Markdown` heading depth (#)."""
@@ -185,32 +192,33 @@ def repl_hash(match):
185192 return f"{ original_prefix } { additional_prefix } "
186193
187194 for entry in md_files :
188- # Add title.
195+ # Add chapter title.
189196 content : str = f"# { entry .title } \n \n { entry .content } "
190197
191198 # Fix depth.
192199 if entry .depth > 0 :
193200 content = re .sub (r"(#+) " , repl_hash , content )
194201
195202 # Fix image links.
196- content = re .sub (r' \/images\/' , ' images/' , content )
197- content = re .sub (r' \.svg' , ' .png' , content )
203+ content = re .sub (r" \/images\/" , " images/" , content )
204+ content = re .sub (r" \.svg" , " .png" , content )
198205
199206 # Fix remaining relative links (e.g. code files).
200- content = re .sub (r' \]\(\/' , ' ](https://vulkan-tutorial.com/' , content )
207+ content = re .sub (r" \]\(\/" , " ](https://vulkan-tutorial.com/" , content )
201208
202209 # Fix chapter references.
203210 def repl (match ):
204211 target = match .group (1 )
205212 target = target .lower ()
206- target = re .sub ('_' , '-' , target )
207- target = target .split ('/' )[- 1 ]
213+ target = re .sub ("_" , "-" , target )
214+ target = target .split ("/" )[- 1 ]
208215
209- return ' ](#' + target + ')'
216+ return f" ](#{ target } )"
210217
211- content = re .sub (r' \]\(!([^)]+)\)' , repl , content )
218+ content = re .sub (r" \]\(!([^)]+)\)" , repl , content )
212219
213- temp_markdown += content + '\n \n '
220+ # temp_markdown += f"{content}\n\n"
221+ temp_markdown += content + "\n \n "
214222
215223 log .info ("Writing markdown file..." )
216224
@@ -229,13 +237,13 @@ def _collect_markdown_files_from_source(
229237 markdown_files = list [VTEMarkdownFile ]()
230238
231239 for entry in pathlib .Path (directory_path ).iterdir ():
232- title_tokens = entry .stem .replace ('_' , ' ' ).split (" " )
240+ title_tokens = entry .stem .replace ("_" , " " ).split (" " )
233241 prefix = f"{ parent_prefix } { title_tokens [0 ]} ."
234242
235243 if entry .is_dir () is True :
236244 log .detail (f"Processing directory: { entry } " )
237245
238- title = ' ' .join (title_tokens [1 :])
246+ title = " " .join (title_tokens [1 :])
239247
240248 markdown_files .append (VTEMarkdownFile ("" , current_depth , prefix , title ))
241249
@@ -247,9 +255,9 @@ def _collect_markdown_files_from_source(
247255 else :
248256 log .detail (f"Processing: { entry } " )
249257
250- title = ' ' .join (title_tokens [1 :])
258+ title = " " .join (title_tokens [1 :])
251259
252- with open (entry , 'r' , encoding = "utf-8" ) as file :
260+ with open (entry , "r" , encoding = "utf-8" ) as file :
253261 content = file .read ()
254262 markdown_files .append (VTEMarkdownFile (content , current_depth , prefix , title ))
255263
0 commit comments