diff --git a/classes.py b/classes.py index 87dddfd..77346af 100644 --- a/classes.py +++ b/classes.py @@ -14,15 +14,18 @@ class ContentItem: logger.debug(f"Rendering {self.source_filename} to {self.target_filename}") try: if self.image_file and self.image_file.exists(): - logger.debug(f"Copying {self.image_file} to {Path(Config.OUTPUT_DIR) / self.image_file}") - shutil.copyfile(self.image_file, Path(Config.OUTPUT_DIR) / self.image_file) + image_targetfile = Path(f"{Config.OUTPUT_DIR}/{Config.STATIC_DIR}/images/{self.image_file.name}") + 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.css_file and self.css_file.exists(): 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) if self.js_file and self.js_file.exists(): - shutil.copyfile(self.js_file, Path(Config.OUTPUT_DIR) / 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) with self.target_filename.open("w", encoding="utf-8") as f: f.write(content_item_template.render(content_item = self, page_title = self.title, parent_path = '../', categories = categories)) except Exception as e: @@ -40,15 +43,16 @@ class ContentItem: self.title = self.data.get("title", self.slug) self.omit_second_title = self.data.get("omit_second_title", False) self.date = self.data.get("date", "2000-01-01T00:00:00+03:00") - self.categories = [c for c in self.data.get("categories", str([])) if c != 'default'] + self.categories = [c for c in self.data.get("categories", []) if c != 'default'] self.hidden = self.data.get("hidden", str(False)) self.data.content = self.data.content.replace('\n', ' \n') self.html = markdown.markdown(self.data.content) - cover_image_path = Path(self.source_filename.parent) / Path(self.source_filename.stem + ".jpg") - self.image_file = cover_image_path if cover_image_path.exists() else None + cover_image_path = Path(f"{self.source_filename.parent}/{self.source_filename.stem}.jpg") + self.image_file = cover_image_path if cover_image_path.exists() else "" css_filepath = Path(f"{self.source_filename.parent}/{self.source_filename.stem}.css") - self.css_file = css_filepath if css_filepath.exists() else None - self.js_file = Path(self.source_filename.stem + ".js") if Path(self.source_filename.stem + ".js").exists else None + self.css_file = css_filepath if css_filepath.exists() else "" + js_filepath = Path(f"{self.source_filename.parent}/{self.source_filename.stem}.js") + self.js_file = js_filepath if js_filepath.exists() else "" except Exception as e: logger.error(e) diff --git a/templates/content_item.html b/templates/content_item.html index e4a6ce5..df7c7e3 100644 --- a/templates/content_item.html +++ b/templates/content_item.html @@ -9,7 +9,7 @@ {% block content %}
- {% if content_item.image_file %}{% endif %} + {% if content_item.image_file %}{% endif %} {% if not content_item.omit_second_title %}

{{ content_item.title }}

{% endif %} @@ -24,8 +24,8 @@ {% endblock %} {% block footer_includes %} - {% if content_item.custom_js %} - + {% if content_item.js_file %} + {% endif %} {% endblock %} diff --git a/templates/default.html b/templates/default.html index 5f6fff5..1585d80 100644 --- a/templates/default.html +++ b/templates/default.html @@ -93,7 +93,7 @@ -