This commit is contained in:
SG
2025-06-12 14:12:46 +03:00
parent 095424f252
commit 47badd9d5a
4 changed files with 17 additions and 13 deletions

View File

@@ -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)

View File

@@ -9,7 +9,7 @@
{% block content %}
<div class="container mt-4 mb-5">
{% if content_item.image_file %}<img src="{{ content_item.image_file }}" class="img-fluid mb-5 rounded w-100 h-auto">{% endif %}
{% if content_item.image_file %}<img src="{{ parent_path }}static/images/{{ content_item.image_file }}" class="img-fluid mb-5 rounded w-100 h-auto">{% endif %}
{% if not content_item.omit_second_title %}
<h1>{{ content_item.title }}</h1>
{% endif %}
@@ -24,8 +24,8 @@
{% endblock %}
{% block footer_includes %}
{% if content_item.custom_js %}
<script src="{{ content_item.custom_js }}"></script>
{% if content_item.js_file %}
<script src="{{ parent_path}}static/js/{{ content_item.slug }}.js"></script>
{% endif %}
{% endblock %}

View File

@@ -93,7 +93,7 @@
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.min.js" integrity="sha384-VHvPCCyXqtD5DqJeNxl2dtTyhF78xXNXdkwX1CZeRusQfRKp+tA7hAShOK/B/fQ2" crossorigin="anonymous"></script>
<div id="footer"class="container-fluid">
<div id="footer" class="container-fluid">
<div id="footer-data" class="row">
{% block footer_includes %}
{% endblock %}

View File

@@ -16,7 +16,7 @@
<div class="card h-100 rounded mx-1 my-3" style="width: 400px;">
<div class="card-header">
{% if content_item.image_file %}
<img src="{{ parent_path }}content/{{ content_item.image_file }}" alt="{{ content_item.title }}" class="card-img-top img-fluid mx-auto d-block object-fit-scale rounded" style="max-height: 200px; width: auto;">
<img src="{{ parent_path }}static/images/{{ content_item.image_file }}" alt="{{ content_item.title }}" class="card-img-top img-fluid mx-auto d-block object-fit-scale rounded" style="max-height: 200px; width: auto;">
{% else %}
<img src="static/images/1x1.png" alt="{{ content_item.title }}" class="card-img-top img-fluid mx-auto d-block object-fit-scale rounded" style="height: 200px; width: auto;">
{% endif %}