diff --git a/classes.py b/classes.py index 7be5b1d..0514b4b 100644 --- a/classes.py +++ b/classes.py @@ -10,7 +10,8 @@ from config import Config from jinja_env import env, content_item_template, index_template 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}") try: logger.debug(f"Title: {self.title}") @@ -26,7 +27,7 @@ class ContentItem: 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: - 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: logger.error(e) @@ -103,6 +104,8 @@ class Site: # Create static/about.md def get_content_items(self): + logger.debug("Getting content items") + 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}") @@ -113,9 +116,9 @@ class Site: def map_categories(self): for content_item in self.content_items: for category in content_item.data.get("categories"): + print(f"!!!!!!! {category}") if not category == "default": self.categories[category].append(content_item.slug) - print(self.categories) def build(self): # Recreate the output dir if needed @@ -133,32 +136,33 @@ class Site: if self.static_dir.exists(): shutil.copytree(self.static_dir, self.output_dir / self.static_dir, dirs_exist_ok=True) - # Parse the content files - logger.debug("Getting content items") + # 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 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 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)) # Render the categories indices for category in self.categories: + print(F"CREATING CATEGORY {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")] 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 about_content = ContentItem(Path('static/about.md')) 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.") \ No newline at end of file diff --git a/jinja_env.py b/jinja_env.py index 127b4a5..92d9a26 100644 --- a/jinja_env.py +++ b/jinja_env.py @@ -5,5 +5,4 @@ from config import Config env = Environment(loader=FileSystemLoader(Config.TEMPLATES_DIR)) env.globals['header_image'] = Config.HEADER_IMAGE index_template = env.get_template("index.html") -content_item_template = env.get_template("content_item.html") -categories_index_template = env.get_template("categories_index.html") \ No newline at end of file +content_item_template = env.get_template("content_item.html") \ No newline at end of file diff --git a/templates/categories_index.html b/templates/categories_index.html deleted file mode 100644 index 7aacac9..0000000 --- a/templates/categories_index.html +++ /dev/null @@ -1,16 +0,0 @@ -{% extends "default.html" %} - -{% block menu_links %} - Home - About -{% endblock %} - -{% block content %} -
-
- {% for category in categories_list %} - {{ category }} - {% endfor %} -
- -{% endblock %} \ No newline at end of file diff --git a/templates/default.html b/templates/default.html index c062bc0..c4d6c67 100644 --- a/templates/default.html +++ b/templates/default.html @@ -74,10 +74,17 @@
- {% block menu_links %} - {% endblock %} - + Home + Categories + About
+
+ +
{% block content %}{% endblock %}
@@ -92,4 +99,16 @@

Page created with microgen

- + + diff --git a/templates/index.html b/templates/index.html index f1b585d..6a710d3 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,20 +5,10 @@ {% endblock %} -{% block menu_links %} - Home - Categories - About -{% endblock %} + {% block content %} -
- -
+
{% for content_item in content_items %} @@ -42,19 +32,4 @@
-{% endblock %} - -{% block footer_includes %} - {% endblock %} \ No newline at end of file