added script path detection
prepare for PyInstaller
This commit is contained in:
@@ -102,6 +102,8 @@ class Site:
|
|||||||
with open(self.templates_dir / f"{template_name}.html", "w", encoding="utf8") as f:
|
with open(self.templates_dir / f"{template_name}.html", "w", encoding="utf8") as f:
|
||||||
f.write(template_content)
|
f.write(template_content)
|
||||||
# Create static/about.md
|
# Create static/about.md
|
||||||
|
about_item = ContentItem(filename = Path('static/about.md'))
|
||||||
|
about_item.create_content()
|
||||||
|
|
||||||
def get_content_items(self):
|
def get_content_items(self):
|
||||||
logger.debug("Getting content items")
|
logger.debug("Getting content items")
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
# Main config section
|
# Main config section
|
||||||
class Config:
|
class Config:
|
||||||
MAIN_PAGE_TITLE = "microgen library"
|
MAIN_PAGE_TITLE = "microgen library"
|
||||||
|
|
||||||
APP_NAME = "hydrogen"
|
APP_NAME = "hydrogen"
|
||||||
APP_DESCRIPTION = "Simplistic static site generator"
|
APP_DESCRIPTION = "Simplistic static site generator"
|
||||||
APP_SRC_URL = f"https://git.exocortex.ru/Exocortex/{APP_NAME}"
|
APP_SRC_URL = f"https://git.exocortex.ru/Exocortex/{APP_NAME}"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import os, subprocess
|
import os, sys, subprocess
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from classes import *
|
from classes import *
|
||||||
@@ -21,23 +21,6 @@ def edit_content(filename):
|
|||||||
filename = Path(f"{Config.CONTENT_DIR}/{filename}.md")
|
filename = Path(f"{Config.CONTENT_DIR}/{filename}.md")
|
||||||
subprocess.call([editor, filename])
|
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():
|
def init_site():
|
||||||
site = Site()
|
site = Site()
|
||||||
site.init_site()
|
site.init_site()
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from argparser import argparser
|
from argparser import argparser
|
||||||
from classes import *
|
from helpers import *
|
||||||
from functions import *
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
@@ -11,6 +10,7 @@ def main():
|
|||||||
build_site()
|
build_site()
|
||||||
case "init":
|
case "init":
|
||||||
init_site()
|
init_site()
|
||||||
|
return
|
||||||
case "new" | "create" | "edit":
|
case "new" | "create" | "edit":
|
||||||
edit_content(args.filename)
|
edit_content(args.filename)
|
||||||
|
|
||||||
|
|||||||
13
jinja_env.py
13
jinja_env.py
@@ -1,8 +1,17 @@
|
|||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
from config import Config
|
from config import Config
|
||||||
|
|
||||||
# Prepare template rendering engine
|
# 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
|
env.globals['header_image'] = Config.HEADER_IMAGE
|
||||||
index_template = env.get_template("index.html")
|
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")
|
||||||
Reference in New Issue
Block a user