updates - content_item.css_file not working in
'content_item.html' template
This commit is contained in:
11
classes.py
11
classes.py
@@ -11,10 +11,8 @@ from jinja_env import env, content_item_template, index_template
|
||||
|
||||
class ContentItem:
|
||||
def render_content(self, categories):
|
||||
logger.debug(f"categ: {categories}")
|
||||
logger.debug(f"Rendering {self.source_filename} to {self.target_filename}")
|
||||
try:
|
||||
logger.debug(f"Title: {self.title}")
|
||||
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)
|
||||
@@ -23,7 +21,6 @@ class ContentItem:
|
||||
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)
|
||||
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)
|
||||
with self.target_filename.open("w", encoding="utf-8") as f:
|
||||
@@ -39,8 +36,7 @@ class ContentItem:
|
||||
self.slug = self.source_filename.stem
|
||||
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.url = "<a href=" + f"{self.subdir}/{self.slug}.html" + "> ...read more</a>"
|
||||
self.preview = self.data.content.replace('\n', '<br>')[:300]# + self.url
|
||||
self.preview = self.data.content.replace('\n', '<br>')[:300]
|
||||
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")
|
||||
@@ -77,7 +73,6 @@ class ContentItem:
|
||||
class Site:
|
||||
def __init__(self):
|
||||
self.output_dir = Path(Config.OUTPUT_DIR)
|
||||
logger.info("Initializing new site")
|
||||
self.content_dir = Path(Config.CONTENT_DIR)
|
||||
self.static_dir = Path(Config.STATIC_DIR)
|
||||
self.templates_dir = Path(Config.TEMPLATES_DIR)
|
||||
@@ -89,7 +84,7 @@ class Site:
|
||||
self.categories = defaultdict(list)
|
||||
|
||||
def init_site(self):
|
||||
|
||||
logger.info("Initializing new site")
|
||||
# Create directories
|
||||
for subdir in [self.content_dir, self.static_dir, self.templates_dir,
|
||||
self.images_dir, self.css_dir, self.js_dir]:
|
||||
@@ -108,7 +103,6 @@ class Site:
|
||||
self.get_content_items = []
|
||||
logger.debug(f"Scanning {Path(Config.CONTENT_DIR)}")
|
||||
for md_file in Path(Config.CONTENT_DIR).glob("*.md"):
|
||||
logger.debug(f"Loading {md_file}")
|
||||
content_item = ContentItem(md_file)
|
||||
content_item.parse_content()
|
||||
self.content_items.append(content_item)
|
||||
@@ -142,7 +136,6 @@ class Site:
|
||||
self.map_categories()
|
||||
|
||||
# Render the content files
|
||||
logger.debug(f"Content items: {self.content_items}")
|
||||
for content_item in self.content_items:
|
||||
content_item.render_content(categories = self.categories)
|
||||
|
||||
|
||||
@@ -3,18 +3,13 @@
|
||||
|
||||
{% block head_includes %}
|
||||
{% 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 %}
|
||||
{% endblock %}
|
||||
|
||||
{% block menu_links %}
|
||||
<a href="../index.html">Home</a>
|
||||
<a href="../static/about.html">About</a>
|
||||
{% endblock %}
|
||||
|
||||
{% 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" 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 %}
|
||||
<h1>{{ content_item.title }}</h1>
|
||||
{% endif %}
|
||||
@@ -28,3 +23,4 @@
|
||||
<script src="{{ content_item.custom_js }}"></script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user