updates - categories
This commit is contained in:
26
classes.py
26
classes.py
@@ -10,7 +10,8 @@ from config import Config
|
|||||||
from jinja_env import env, content_item_template, index_template
|
from jinja_env import env, content_item_template, index_template
|
||||||
|
|
||||||
class ContentItem:
|
class ContentItem:
|
||||||
def render_content(self):
|
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}")
|
logger.debug(f"Title: {self.title}")
|
||||||
@@ -26,7 +27,7 @@ class ContentItem:
|
|||||||
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:
|
||||||
f.write(content_item_template.render(content_item = self, page_title = self.title))
|
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:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|
||||||
@@ -103,6 +104,8 @@ class Site:
|
|||||||
# Create static/about.md
|
# Create static/about.md
|
||||||
|
|
||||||
def get_content_items(self):
|
def get_content_items(self):
|
||||||
|
logger.debug("Getting 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}")
|
logger.debug(f"Loading {md_file}")
|
||||||
@@ -113,9 +116,9 @@ class Site:
|
|||||||
def map_categories(self):
|
def map_categories(self):
|
||||||
for content_item in self.content_items:
|
for content_item in self.content_items:
|
||||||
for category in content_item.data.get("categories"):
|
for category in content_item.data.get("categories"):
|
||||||
|
print(f"!!!!!!! {category}")
|
||||||
if not category == "default":
|
if not category == "default":
|
||||||
self.categories[category].append(content_item.slug)
|
self.categories[category].append(content_item.slug)
|
||||||
print(self.categories)
|
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
# Recreate the output dir if needed
|
# Recreate the output dir if needed
|
||||||
@@ -133,32 +136,33 @@ class Site:
|
|||||||
if self.static_dir.exists():
|
if self.static_dir.exists():
|
||||||
shutil.copytree(self.static_dir, self.output_dir / self.static_dir, dirs_exist_ok=True)
|
shutil.copytree(self.static_dir, self.output_dir / self.static_dir, dirs_exist_ok=True)
|
||||||
|
|
||||||
# Parse the content files
|
# Get content items
|
||||||
logger.debug("Getting content items")
|
|
||||||
self.get_content_items()
|
self.get_content_items()
|
||||||
logger.debug(f"Content items: {self.content_items}")
|
|
||||||
for content_item in self.content_items:
|
|
||||||
content_item.render_content()
|
|
||||||
|
|
||||||
# Build categories map
|
# Build categories map
|
||||||
self.map_categories()
|
self.map_categories()
|
||||||
|
|
||||||
|
# Parse 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)
|
||||||
|
|
||||||
# Render the index file
|
# Render the index file
|
||||||
with (self.output_dir / "index.html").open("w", encoding="utf-8") as f:
|
with (self.output_dir / "index.html").open("w", encoding="utf-8") as f:
|
||||||
f.write(index_template.render(page_title = Config.MAIN_PAGE_TITLE, content_items=self.content_items, categories = self.categories))
|
f.write(index_template.render(page_title = Config.MAIN_PAGE_TITLE, content_items=self.content_items, categories = self.categories))
|
||||||
|
|
||||||
# Render the categories indices
|
# Render the categories indices
|
||||||
for category in self.categories:
|
for category in self.categories:
|
||||||
|
print(F"CREATING CATEGORY {category}.html")
|
||||||
category_index = Path(f"{self.output_dir}/categories/{category}.html")
|
category_index = Path(f"{self.output_dir}/categories/{category}.html")
|
||||||
category_items = [i for i in self.content_items if category in i.data.get("categories")]
|
category_items = [i for i in self.content_items if category in i.data.get("categories")]
|
||||||
with (category_index).open(mode="w", encoding="utf-8") as f:
|
with (category_index).open(mode="w", encoding="utf-8") as f:
|
||||||
f.write(index_template.render(page_title=category, content_items=category_items, categories = self.categories))
|
f.write(index_template.render(page_title=category, content_items=category_items, categories = self.categories, parent_path = '../'))
|
||||||
|
|
||||||
|
|
||||||
# Render the about file
|
# Render the about file
|
||||||
about_content = ContentItem(Path('static/about.md'))
|
about_content = ContentItem(Path('static/about.md'))
|
||||||
about_content.parse_content()
|
about_content.parse_content()
|
||||||
about_content.render_content()
|
about_content.render_content(categories = self.categories)
|
||||||
|
|
||||||
logger.info(f"Created {len(self.content_items)} content items.")
|
logger.info(f"Created {len(self.content_items)} content items.")
|
||||||
|
|
||||||
@@ -5,5 +5,4 @@ from config import Config
|
|||||||
env = Environment(loader=FileSystemLoader(Config.TEMPLATES_DIR))
|
env = Environment(loader=FileSystemLoader(Config.TEMPLATES_DIR))
|
||||||
env.globals['header_image'] = Config.HEADER_IMAGE
|
env.globals['header_image'] = Config.HEADER_IMAGE
|
||||||
index_template = env.get_template("index.html")
|
index_template = env.get_template("index.html")
|
||||||
content_item_template = env.get_template("content_item.html")
|
content_item_template = env.get_template("content_item.html")
|
||||||
categories_index_template = env.get_template("categories_index.html")
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
{% extends "default.html" %}
|
|
||||||
|
|
||||||
{% block menu_links %}
|
|
||||||
<a href="index.html">Home</a>
|
|
||||||
<a href="static/about.html">About</a>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="container">
|
|
||||||
<div class="row"></div>
|
|
||||||
{% for category in categories_list %}
|
|
||||||
<a href="{{category}}.html">{{ category }}</a>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -74,10 +74,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="top_menu d-flex justify-content-end" style="margin-bottom: 20px;">
|
<div class="top_menu d-flex justify-content-end" style="margin-bottom: 20px;">
|
||||||
{% block menu_links %}
|
<a href="{{ parent_path }}index.html">Home</a>
|
||||||
{% endblock %}
|
<a id="categories_toggle" href="#">Categories</a>
|
||||||
|
<a href="{{ parent_path }}static/about.html">About</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="categories_container" class="container">
|
||||||
|
<div id="categories_menu" class="row justify-content-around mx-auto" style="visibility: hidden">
|
||||||
|
{% for category in categories %}
|
||||||
|
<a href="{{ parent_path }}categories/{{ category }}.html" class="mx-2">{{ category }}</a>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="content">{% block content %}{% endblock %}</div>
|
<div id="content">{% block content %}{% endblock %}</div>
|
||||||
|
|
||||||
@@ -92,4 +99,16 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row small text-muted justify-content-end"><p class="mx-4">Page created with <a href="">microgen</a></p></div>
|
<div class="row small text-muted justify-content-end"><p class="mx-4">Page created with <a href="">microgen</a></p></div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
<script defer>
|
||||||
|
document.getElementById("categories_toggle").onclick = function() {
|
||||||
|
categories_menu_item = document.getElementById("categories_menu")
|
||||||
|
console.log(categories_menu_item.style.visibility)
|
||||||
|
if (categories_menu_item.style.visibility == "hidden") {
|
||||||
|
categories_menu_item.style.visibility = "visible"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
categories_menu_item.style.visibility = "hidden"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|||||||
@@ -5,20 +5,10 @@
|
|||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block menu_links %}
|
|
||||||
<a href="index.html">Home</a>
|
|
||||||
<a id="categories_toggle" href="#">Categories</a>
|
|
||||||
<a href="static/about.html">About</a>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="container">
|
|
||||||
<div id="categories_menu" class="row justify-content-around mx-auto" style="visibility: hidden">
|
|
||||||
{% for category in categories %}
|
|
||||||
<a href="categories/{{ category }}.html" class="mx-2">{{ category }}</a>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="container-fluid content-row mx-auto">
|
<div class="container-fluid content-row mx-auto">
|
||||||
<div class="row justify-content-start mx-auto">
|
<div class="row justify-content-start mx-auto">
|
||||||
{% for content_item in content_items %}
|
{% for content_item in content_items %}
|
||||||
@@ -42,19 +32,4 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block footer_includes %}
|
|
||||||
<script defer>
|
|
||||||
document.getElementById("categories_toggle").onclick = function() {
|
|
||||||
categories_menu_item = document.getElementById("categories_menu")
|
|
||||||
console.log(categories_menu_item.style.visibility)
|
|
||||||
if (categories_menu_item.style.visibility == "hidden") {
|
|
||||||
categories_menu_item.style.visibility = "visible"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
categories_menu_item.style.visibility = "hidden"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user