updates - content_item.css_file not working in

'content_item.html' template
This commit is contained in:
SG
2025-06-12 02:41:31 +03:00
parent 141060368c
commit a0e858f416
2 changed files with 5 additions and 16 deletions

View File

@@ -11,10 +11,8 @@ from jinja_env import env, content_item_template, index_template
class ContentItem: class ContentItem:
def render_content(self, categories): def render_content(self, categories):
logger.debug(f"categ: {categories}")
logger.debug(f"Rendering {self.source_filename} to {self.target_filename}") logger.debug(f"Rendering {self.source_filename} to {self.target_filename}")
try: try:
logger.debug(f"Title: {self.title}")
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}") 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) shutil.copyfile(self.image_file, Path(Config.OUTPUT_DIR) / self.image_file)
@@ -23,7 +21,6 @@ class ContentItem:
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)
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) shutil.copyfile(self.js_file, Path(Config.OUTPUT_DIR) / self.js_file)
with self.target_filename.open("w", encoding="utf-8") as f: with self.target_filename.open("w", encoding="utf-8") as f:
@@ -39,8 +36,7 @@ class ContentItem:
self.slug = self.source_filename.stem self.slug = self.source_filename.stem
self.target_filename = Path(f"{Config.OUTPUT_DIR}/{self.source_filename.parent}/{self.source_filename.stem}.html") self.target_filename = Path(f"{Config.OUTPUT_DIR}/{self.source_filename.parent}/{self.source_filename.stem}.html")
self.data = frontmatter.load(self.source_filename) self.data = frontmatter.load(self.source_filename)
#self.url = "<a href=" + f"{self.subdir}/{self.slug}.html" + "> ...read more</a>" self.preview = self.data.content.replace('\n', '<br>')[:300]
self.preview = self.data.content.replace('\n', '<br>')[:300]# + self.url
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")
@@ -77,7 +73,6 @@ class ContentItem:
class Site: class Site:
def __init__(self): def __init__(self):
self.output_dir = Path(Config.OUTPUT_DIR) self.output_dir = Path(Config.OUTPUT_DIR)
logger.info("Initializing new site")
self.content_dir = Path(Config.CONTENT_DIR) self.content_dir = Path(Config.CONTENT_DIR)
self.static_dir = Path(Config.STATIC_DIR) self.static_dir = Path(Config.STATIC_DIR)
self.templates_dir = Path(Config.TEMPLATES_DIR) self.templates_dir = Path(Config.TEMPLATES_DIR)
@@ -89,7 +84,7 @@ class Site:
self.categories = defaultdict(list) self.categories = defaultdict(list)
def init_site(self): def init_site(self):
logger.info("Initializing new site")
# Create directories # Create directories
for subdir in [self.content_dir, self.static_dir, self.templates_dir, for subdir in [self.content_dir, self.static_dir, self.templates_dir,
self.images_dir, self.css_dir, self.js_dir]: self.images_dir, self.css_dir, self.js_dir]:
@@ -108,7 +103,6 @@ class Site:
self.get_content_items = [] self.get_content_items = []
logger.debug(f"Scanning {Path(Config.CONTENT_DIR)}") logger.debug(f"Scanning {Path(Config.CONTENT_DIR)}")
for md_file in Path(Config.CONTENT_DIR).glob("*.md"): for md_file in Path(Config.CONTENT_DIR).glob("*.md"):
logger.debug(f"Loading {md_file}")
content_item = ContentItem(md_file) content_item = ContentItem(md_file)
content_item.parse_content() content_item.parse_content()
self.content_items.append(content_item) self.content_items.append(content_item)
@@ -142,7 +136,6 @@ class Site:
self.map_categories() self.map_categories()
# Render the content files # Render the content files
logger.debug(f"Content items: {self.content_items}")
for content_item in self.content_items: for content_item in self.content_items:
content_item.render_content(categories = self.categories) content_item.render_content(categories = self.categories)

View File

@@ -3,18 +3,13 @@
{% block head_includes %} {% block head_includes %}
{% if content_item.css_file %} {% if content_item.css_file %}
<link rel="stylesheet" href="/{{ content_item.css_file }}"> <link rel="stylesheet" href="{{ parent_path }}static/css/{{ content_item.slug }}.css">
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block menu_links %}
<a href="../index.html">Home</a>
<a href="../static/about.html">About</a>
{% endblock %}
{% 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" style="border-radius: 5px;">{% endif %} {% if content_item.image_file %}<img src="{{ 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 %}
@@ -28,3 +23,4 @@
<script src="{{ content_item.custom_js }}"></script> <script src="{{ content_item.custom_js }}"></script>
{% endif %} {% endif %}
{% endblock %} {% endblock %}