hopefully fixed bad images in content_item

template
This commit is contained in:
sg
2025-06-30 20:21:03 +03:00
parent 664a6adb77
commit 162b45809b

View File

@@ -19,28 +19,44 @@ class ContentItem:
else: else:
footer_data = '' footer_data = ''
try: try:
if self.image_file and self.image_file.exists(): if self.image_file and Path(self.image_file).exists():
image_targetfile = Path(f"{config.output_dir}/{config.static_dir}/images/{self.image_file.name}") 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}") logger.debug(f"Copying {self.image_file} to {image_targetfile}")
shutil.copyfile(self.image_file, image_targetfile) shutil.copyfile(self.image_file, image_targetfile)
self.image_file = f"{self.image_file.stem}.jpg" 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}") 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}") logger.debug(f"Copying {self.audio_file} to {audio_targetfile}")
shutil.copyfile(self.audio_file, audio_targetfile) shutil.copyfile(self.audio_file, audio_targetfile)
self.audio_file = f"{self.audio_file.stem}.mp3" 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}") 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}") logger.debug(f"Copying {self.css_file} to {css_targetfile}")
shutil.copyfile(self.css_file, 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(): 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}") 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}") logger.debug(f"Copying {self.js_file} to {js_targetfile}")
shutil.copyfile(self.js_file, 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: 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)) 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: except Exception as e:
logger.error(f"Renderer: {e}") logger.error(f"Couldn't render content file: {e}")
def parse_content(self): def parse_content(self):
logger.debug(f"Parsing file {self.source_file}") logger.debug(f"Parsing file {self.source_file}")
@@ -58,15 +74,14 @@ class ContentItem:
self.hidden = self.data.get("hidden", str(False)) self.hidden = self.data.get("hidden", str(False))
self.data.content = self.data.content.replace('\n', ' \n') # For markdown newline rendering self.data.content = self.data.content.replace('\n', ' \n') # For markdown newline rendering
self.html = markdown.markdown(self.data.content) self.html = markdown.markdown(self.data.content)
cover_image_path = Path(f"{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 cover_image_path.exists() else "" self.image_file = cover_image_path if Path(cover_image_path).exists() else ""
audio_filepath = Path(f"{self.source_file.parent}/{self.source_file.stem}.mp3") audio_filepath = f"{self.source_file.parent}/{self.source_file.stem}.mp3"
self.audio_file = audio_filepath if audio_filepath.exists() else "" self.audio_file = audio_filepath if Path(audio_filepath).exists() else ""
css_filepath = Path(f"{self.source_file.parent}/{self.source_file.stem}.css") css_filepath = f"{self.source_file.parent}/{self.source_file.stem}.css"
self.css_file = css_filepath if css_filepath.exists() else "" self.css_file = css_filepath if Path(css_filepath).exists() else ""
js_filepath = Path(f"{self.source_file.parent}/{self.source_file.stem}.js") js_filepath = f"{self.source_file.parent}/{self.source_file.stem}.js"
self.js_file = js_filepath if js_filepath.exists() else "" self.js_file = js_filepath if Path(js_filepath).exists() else ""
logger.debug(f"CCC {self.source_file.parts} : {self.source_file.parent} / {self.source_file.stem}.jpg")
except Exception as e: except Exception as e:
logger.error(f"Parser error, {e}") logger.error(f"Parser error, {e}")