updates
This commit is contained in:
20
classes.py
20
classes.py
@@ -14,15 +14,18 @@ class ContentItem:
|
|||||||
logger.debug(f"Rendering {self.source_filename} to {self.target_filename}")
|
logger.debug(f"Rendering {self.source_filename} to {self.target_filename}")
|
||||||
try:
|
try:
|
||||||
if self.image_file and self.image_file.exists():
|
if self.image_file and self.image_file.exists():
|
||||||
logger.debug(f"Copying {self.image_file} to {Path(Config.OUTPUT_DIR) / self.image_file}")
|
image_targetfile = Path(f"{Config.OUTPUT_DIR}/{Config.STATIC_DIR}/images/{self.image_file.name}")
|
||||||
shutil.copyfile(self.image_file, Path(Config.OUTPUT_DIR) / self.image_file)
|
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"
|
self.image_file = f"{self.image_file.stem}.jpg"
|
||||||
if self.css_file and self.css_file.exists():
|
if self.css_file and self.css_file.exists():
|
||||||
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)
|
||||||
if self.js_file and self.js_file.exists():
|
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:
|
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))
|
f.write(content_item_template.render(content_item = self, page_title = self.title, parent_path = '../', categories = categories))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -40,15 +43,16 @@ class ContentItem:
|
|||||||
self.title = self.data.get("title", self.slug)
|
self.title = self.data.get("title", self.slug)
|
||||||
self.omit_second_title = self.data.get("omit_second_title", False)
|
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.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.hidden = self.data.get("hidden", str(False))
|
||||||
self.data.content = self.data.content.replace('\n', ' \n')
|
self.data.content = self.data.content.replace('\n', ' \n')
|
||||||
self.html = markdown.markdown(self.data.content)
|
self.html = markdown.markdown(self.data.content)
|
||||||
cover_image_path = Path(self.source_filename.parent) / Path(self.source_filename.stem + ".jpg")
|
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 None
|
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")
|
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.css_file = css_filepath if css_filepath.exists() else ""
|
||||||
self.js_file = Path(self.source_filename.stem + ".js") if Path(self.source_filename.stem + ".js").exists else None
|
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:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="container mt-4 mb-5">
|
<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 %}
|
{% if not content_item.omit_second_title %}
|
||||||
<h1>{{ content_item.title }}</h1>
|
<h1>{{ content_item.title }}</h1>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -24,8 +24,8 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block footer_includes %}
|
{% block footer_includes %}
|
||||||
{% if content_item.custom_js %}
|
{% if content_item.js_file %}
|
||||||
<script src="{{ content_item.custom_js }}"></script>
|
<script src="{{ parent_path}}static/js/{{ content_item.slug }}.js"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<div class="card h-100 rounded mx-1 my-3" style="width: 400px;">
|
<div class="card h-100 rounded mx-1 my-3" style="width: 400px;">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
{% if content_item.image_file %}
|
{% 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 %}
|
{% 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;">
|
<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 %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user