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 = "" %} - - - - {{ page_title }} - - {% block head_includes %} - {% endblock %} - - - -
-
-

{{ page_title }}

-
-
-
-
- Home - Categories - About - 🌓︎ -
-
-
- -
- -
- {% block content %} - {% endblock %} -
- - - - - -""" - -index = """ -{% extends "default.html" %} - -{% block head_includes %} - -{% endblock %} - -{% block content %} -
- {% for content_item in content_items %} -
-
-
- {% if content_item.image_file %} - {{ content_item.title }} - {% else %} - {{ content_item.title }} - {% endif %} -
-
-
{{ content_item.title }}
-

{{ content_item.preview | safe}}... read more

-
- -
-
- {% endfor %} -
-{% endblock %} -""" - -content_item=""" -{% extends "default.html" %} - -{% block head_includes %} - {% if content_item.css_file %} - - {% endif %} -{% endblock %} - -{% block content %} -
- {% if content_item.image_file %}{% endif %} - {% if not content_item.omit_second_title %} -

{{ content_item.title }}

- {% endif %} -
{{ content_item.html | safe }}
-
- {% for category in content_item.categories %} - {{ category }} - {% endfor %} -
- ← Back -
-{% endblock %} - -{% block footer_includes %} - {% if content_item.js_file %} - - {% endif %} -{% endblock %} -""" \ No newline at end of file diff --git a/test.py b/test.py deleted file mode 100644 index db6b483..0000000 --- a/test.py +++ /dev/null @@ -1,3 +0,0 @@ -from pathlib import Path -app_dir = Path(__file__).resolve().parent -print(app_dir, type(app_dir)) \ No newline at end of file diff --git a/static/about.md b/themes/default/static/about.md similarity index 100% rename from static/about.md rename to themes/default/static/about.md diff --git a/static/images/1x1.png b/themes/default/static/images/1x1.png similarity index 100% rename from static/images/1x1.png rename to themes/default/static/images/1x1.png diff --git a/static/about.jpg b/themes/default/static/images/about.jpg similarity index 100% rename from static/about.jpg rename to themes/default/static/images/about.jpg diff --git a/static/header.jpg b/themes/default/static/images/header.jpg similarity index 100% rename from static/header.jpg rename to themes/default/static/images/header.jpg diff --git a/templates/content_item.html b/themes/default/templates/content_item.html similarity index 100% rename from templates/content_item.html rename to themes/default/templates/content_item.html diff --git a/templates/default.html b/themes/default/templates/default.html similarity index 99% rename from templates/default.html rename to themes/default/templates/default.html index 8760aa4..ed31c11 100644 --- a/templates/default.html +++ b/themes/default/templates/default.html @@ -15,7 +15,7 @@ } .top_header { position: relative; - height: 250px; + height: 200px; background: rgb(70, 70, 124); background-image: url("{{ parent_path }}static/header.jpg"); background-size: cover; diff --git a/templates/index.html b/themes/default/templates/index.html similarity index 100% rename from templates/index.html rename to themes/default/templates/index.html