1 Commits

Author SHA1 Message Date
SG
ed9d1dade2 added script path detection
prepare for PyInstaller
2025-06-14 17:37:33 +03:00
6 changed files with 20 additions and 23 deletions

View File

@@ -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")

View File

@@ -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}"

View File

@@ -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()

View File

@@ -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)

View File

@@ -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")
content_item_template = env.get_template("content_item.html")

3
test.py Normal file
View File

@@ -0,0 +1,3 @@
from pathlib import Path
app_dir = Path(__file__).resolve().parent
print(app_dir, type(app_dir))