diff --git a/classes.py b/classes.py index f6eec84..6954b99 100644 --- a/classes.py +++ b/classes.py @@ -19,28 +19,44 @@ class ContentItem: else: footer_data = '' try: - if self.image_file and self.image_file.exists(): - image_targetfile = Path(f"{config.output_dir}/{config.static_dir}/images/{self.image_file.name}") + if self.image_file and Path(self.image_file).exists(): + self.image_file = Path(self.image_file) + image_targetfile = Path(f"{config.output_dir}/{config.static_dir}/images/{self.source_file.stem}.jpg") logger.debug(f"Copying {self.image_file} to {image_targetfile}") shutil.copyfile(self.image_file, image_targetfile) self.image_file = f"{self.image_file.stem}.jpg" - if self.audio_file and self.audio_file.exists(): + except Exception as e: + logger.error(f"Couldn't render image file {self.image_file}: {e}") + try: + if self.audio_file and Path(self.audio_file).exists(): + self.audio_file = Path(self.audio_file) audio_targetfile = Path(f"{config.output_dir}/{config.static_dir}/audio/{self.audio_file.name}") logger.debug(f"Copying {self.audio_file} to {audio_targetfile}") shutil.copyfile(self.audio_file, audio_targetfile) self.audio_file = f"{self.audio_file.stem}.mp3" - if self.css_file and self.css_file.exists(): + except Exception as e: + logger.error(f"Couldn't render audio file {self.audio_file}: {e}") + try: + if self.css_file and Path(self.css_file).exists(): + self.css_file = Path(self.css_file) css_targetfile = Path(f"{config.output_dir}/{config.static_dir}/css/{self.css_file.name}") logger.debug(f"Copying {self.css_file} to {css_targetfile}") shutil.copyfile(self.css_file, css_targetfile) + except Exception as e: + logger.error(f"Couldn't render CSS file {self.css_file}: {e}") + try: if self.js_file and self.js_file.exists(): + self.js_file = Path(self.js_file) js_targetfile = Path(f"{config.output_dir}/{config.static_dir}/js/{self.js_file.name}") logger.debug(f"Copying {self.js_file} to {js_targetfile}") shutil.copyfile(self.js_file, js_targetfile) + except Exception as e: + logger.error(f"Couldn't render CSS file {self.js_file}: {e}") + try: with self.target_file.open("w", encoding="utf-8") as f: f.write(config.content_item_template.render(content_item = self, page_title = f"{config.site_name}: {self.title}", parent_path = '../', categories = categories, footer_data = footer_data)) except Exception as e: - logger.error(f"Renderer: {e}") + logger.error(f"Couldn't render content file: {e}") def parse_content(self): logger.debug(f"Parsing file {self.source_file}") @@ -58,15 +74,14 @@ class ContentItem: self.hidden = self.data.get("hidden", str(False)) self.data.content = self.data.content.replace('\n', ' \n') # For markdown newline rendering self.html = markdown.markdown(self.data.content) - cover_image_path = Path(f"{self.source_file.parent}/{self.source_file.stem}.jpg") - self.image_file = cover_image_path if cover_image_path.exists() else "" - audio_filepath = Path(f"{self.source_file.parent}/{self.source_file.stem}.mp3") - self.audio_file = audio_filepath if audio_filepath.exists() else "" - css_filepath = Path(f"{self.source_file.parent}/{self.source_file.stem}.css") - self.css_file = css_filepath if css_filepath.exists() else "" - js_filepath = Path(f"{self.source_file.parent}/{self.source_file.stem}.js") - self.js_file = js_filepath if js_filepath.exists() else "" - logger.debug(f"CCC {self.source_file.parts} : {self.source_file.parent} / {self.source_file.stem}.jpg") + cover_image_path = f"{self.source_file.parent}/{self.source_file.stem}.jpg" + self.image_file = cover_image_path if Path(cover_image_path).exists() else "" + audio_filepath = f"{self.source_file.parent}/{self.source_file.stem}.mp3" + self.audio_file = audio_filepath if Path(audio_filepath).exists() else "" + css_filepath = f"{self.source_file.parent}/{self.source_file.stem}.css" + self.css_file = css_filepath if Path(css_filepath).exists() else "" + js_filepath = f"{self.source_file.parent}/{self.source_file.stem}.js" + self.js_file = js_filepath if Path(js_filepath).exists() else "" except Exception as e: logger.error(f"Parser error, {e}")