diff --git a/classes.py b/classes.py index 14a627e..c9dc8c5 100644 --- a/classes.py +++ b/classes.py @@ -102,6 +102,8 @@ class Site: with open(self.templates_dir / f"{template_name}.html", "w", encoding="utf8") as f: f.write(template_content) # Create static/about.md + 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/config.py b/config.py index 151f129..206751d 100644 --- a/config.py +++ b/config.py @@ -1,8 +1,8 @@ import os + # Main config section class Config: MAIN_PAGE_TITLE = "microgen library" - APP_NAME = "hydrogen" APP_DESCRIPTION = "Simplistic static site generator" APP_SRC_URL = f"https://git.exocortex.ru/Exocortex/{APP_NAME}" diff --git a/functions.py b/helpers.py similarity index 59% rename from functions.py rename to helpers.py index b49a68c..b3c58c1 100644 --- a/functions.py +++ b/helpers.py @@ -1,4 +1,4 @@ -import os, subprocess +import os, sys, subprocess import shutil from pathlib import Path from classes import * @@ -21,23 +21,6 @@ def edit_content(filename): filename = Path(f"{Config.CONTENT_DIR}/{filename}.md") subprocess.call([editor, filename]) -def init_site_old(): - logger.debug(f"Initializing new site") - - # Recreate output directory if necessary - output_dir = Path(Config.OUTPUT_DIR) - if output_dir.exists(): - shutil.rmtree(output_dir) - output_dir.mkdir() - - # Create output directory subtree - for dir in [ Path(Config.CONTENT_DIR), Path(Config.STATIC_DIR), Path(Config.TEMPLATE_DIR), - Path(Config.OUTPUT_IMG_DIR), Path(Config.OUTPUT_CSS_DIR), Path(Config.OUTPUT_JS_DIR)]: - dir.mkdir(exist_ok=True) - - # Create "About.md" content item - create_content("about") - def init_site(): site = Site() site.init_site() diff --git a/hydrogen.py b/hydrogen.py index 134572e..e8c8b23 100644 --- a/hydrogen.py +++ b/hydrogen.py @@ -1,8 +1,7 @@ #!/usr/bin/env python3 from argparser import argparser -from classes import * -from functions import * +from helpers import * def main(): args = argparser.parse_args() @@ -11,6 +10,7 @@ def main(): build_site() case "init": init_site() + return case "new" | "create" | "edit": edit_content(args.filename) diff --git a/jinja_env.py b/jinja_env.py index 92d9a26..892991c 100644 --- a/jinja_env.py +++ b/jinja_env.py @@ -1,8 +1,17 @@ +import sys +from pathlib import Path from jinja2 import Environment, FileSystemLoader from config import Config # Prepare template rendering engine -env = Environment(loader=FileSystemLoader(Config.TEMPLATES_DIR)) +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 index_template = env.get_template("index.html") -content_item_template = env.get_template("content_item.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/test.py b/test.py new file mode 100644 index 0000000..db6b483 --- /dev/null +++ b/test.py @@ -0,0 +1,3 @@ +from pathlib import Path +app_dir = Path(__file__).resolve().parent +print(app_dir, type(app_dir)) \ No newline at end of file