diff --git a/classes.py b/classes.py index c9dc8c5..576420a 100644 --- a/classes.py +++ b/classes.py @@ -1,5 +1,6 @@ from datetime import datetime import os +import sys import shutil from collections import defaultdict import markdown @@ -8,7 +9,23 @@ from bs4 import BeautifulSoup from pathlib import Path from logger import logger from config import Config -from jinja_env import env, content_item_template, index_template +#from jinja_env import env, content_item_template, index_template +from jinja2 import Environment, FileSystemLoader + +# get the scrip directory +if getattr(sys, 'frozen', False): + # Running fron Pyinstaller-packed binary + base_dir = Path(sys._MEIPASS) +else: + # Running as a plain Python app + base_dir = Path(__file__).resolve().parent + +# Prepare template rendering engine +jinja_env_dir = f"{base_dir}/themes/{Config.THEME}/templates" +env = Environment(loader=FileSystemLoader(f"{jinja_env_dir}")) +env.globals['header_image'] = f"{base_dir}/themes/{Config.THEME}/static/images/header.jpg" +index_template = env.get_template("index.html") +content_item_template = env.get_template("content_item.html") class ContentItem: def render_content(self, categories): @@ -91,19 +108,14 @@ class Site: 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]: + for subdir in [self.content_dir]: os.makedirs(subdir, exist_ok=True) - # Create templates from literals - import templates - template_names = [t for t in dir(templates) if not t.startswith('_')] - for template_name in template_names: - template_content = getattr(templates, template_name) - with open(self.templates_dir / f"{template_name}.html", "w", encoding="utf8") as f: - f.write(template_content) + + # copy default theme + shutil.copytree(f"{base_dir}/themes/default", "themes/default", dirs_exist_ok=True) # Create static/about.md - about_item = ContentItem(filename = Path('static/about.md')) - about_item.create_content() + #about_item = ContentItem(filename = Path('static/about.md')) + #about_item.create_content() def get_content_items(self): logger.debug("Getting content items") diff --git a/helpers.py b/helpers.py index b3c58c1..afd55b5 100644 --- a/helpers.py +++ b/helpers.py @@ -1,5 +1,4 @@ -import os, sys, subprocess -import shutil +import os, subprocess from pathlib import Path from classes import * from config import Config diff --git a/jinja_env.py b/jinja_env.py index 892991c..d1f7760 100644 --- a/jinja_env.py +++ b/jinja_env.py @@ -3,15 +3,17 @@ from pathlib import Path from jinja2 import Environment, FileSystemLoader from config import Config -# Prepare template rendering engine +# get the scrip directory if getattr(sys, 'frozen', False): # Running fron Pyinstaller-packed binary base_dir = Path(sys._MEIPASS) else: # Running as a plain Python app base_dir = Path(__file__).resolve().parent - -env = Environment(loader=FileSystemLoader(f"{base_dir}/{Config.TEMPLATES_DIR}")) -env.globals['header_image'] = Config.HEADER_IMAGE + +# Prepare template rendering engine +jinja_env_dir = f"{base_dir}/themes/{Config.THEME}/templates" +env = Environment(loader=FileSystemLoader(f"{jinja_env_dir}")) +env.globals['header_image'] = f"{base_dir}/static/header.jpg" index_template = env.get_template("index.html") content_item_template = env.get_template("content_item.html") \ No newline at end of file diff --git a/static/robots.txt b/static/robots.txt deleted file mode 100644 index 77470cb..0000000 --- a/static/robots.txt +++ /dev/null @@ -1,2 +0,0 @@ -User-agent: * -Disallow: / \ No newline at end of file diff --git a/templates.py b/templates.py deleted file mode 100644 index 8c42498..0000000 --- a/templates.py +++ /dev/null @@ -1,182 +0,0 @@ -default = """ - - -
- {% set base = "" %} - - - -
- {% endif %}
- {{ content_item.preview | safe}}... read more
-