Switching to self-contained binary -
initial commit.
This commit is contained in:
19
config.py
19
config.py
@@ -1,24 +1,7 @@
|
||||
import logging, os, sys
|
||||
|
||||
import os
|
||||
# Main config section
|
||||
class Config:
|
||||
APP_NAME = "hydrogen"
|
||||
MAIN_PAGE_TITLE = "Selected poems"
|
||||
OUTPUT_DIR = os.environ.get('OUTPUT_DIR') or 'public'
|
||||
HEADER_IMAGE = 'static/header.jpg'
|
||||
LOG_TO = sys.stdout
|
||||
LOG_LEVEL = logging.DEBUG
|
||||
|
||||
# Logging config section
|
||||
logger = logging.getLogger(Config.APP_NAME)
|
||||
logger.setLevel(Config.LOG_LEVEL)
|
||||
stdout_handler = logging.StreamHandler(Config.LOG_TO)
|
||||
stdout_handler.setLevel(Config.LOG_LEVEL)
|
||||
formatter = logging.Formatter(
|
||||
'[%(asctime)s] %(name)s: %(levelname)s: %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S'
|
||||
)
|
||||
stdout_handler.setFormatter(formatter)
|
||||
if not logger.hasHandlers():
|
||||
logger.addHandler(stdout_handler)
|
||||
logger.propagate = False
|
||||
26
hydrogen.py
26
hydrogen.py
@@ -5,15 +5,15 @@ import frontmatter
|
||||
import markdown
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
import shutil
|
||||
from config import Config, logger
|
||||
from config import Config
|
||||
from logger import logger
|
||||
|
||||
content_dir = Path('content')
|
||||
template_dir = Path('templates')
|
||||
output_dir = Path(Config.OUTPUT_DIR)
|
||||
img_dir = Path('public/images')
|
||||
assets_dir = Path('public/assets')
|
||||
assets_css_dir = Path('public/assets/css')
|
||||
assets_js_dir = Path('public/assets/js')
|
||||
assets_css_dir = Path(output_dir / 'static/css')
|
||||
assets_js_dir = Path(output_dir / 'static/js')
|
||||
static_dir = Path('static')
|
||||
header_image = Config.HEADER_IMAGE or '/static/header.jpg'
|
||||
|
||||
@@ -22,7 +22,7 @@ class ContentItemPrototype:
|
||||
if self.image_src_file.exists():
|
||||
shutil.copyfile(self.image_src_file, output_dir / self.image)
|
||||
if self.custom_css_src_file.exists():
|
||||
shutil.copyfile(self.custom_css_src_file, output_dir / self.custom_css)
|
||||
shutil.copyfile(self.custom_css_src_file,output_dir / self.custom_css)
|
||||
if self.custom_js_src_file.exists():
|
||||
shutil.copyfile(self.custom_js_src_file, output_dir / self.custom_js)
|
||||
with self.content_output_path.open("w", encoding="utf-8") as f:
|
||||
@@ -40,28 +40,30 @@ class ContentItemPrototype:
|
||||
self.image_src_file = Path(f"{content_dir}/{md_file.stem}.jpg")
|
||||
self.image = f"images/{md_file.stem}.jpg" if self.image_src_file.exists() else None
|
||||
self.custom_css_src_file = Path(f"{content_dir}/{md_file.stem}.css")
|
||||
self.custom_css = f"assets/css/{md_file.stem}.css" if self.custom_css_src_file.exists() else None
|
||||
self.custom_css = f"static/css/{md_file.stem}.css" if self.custom_css_src_file.exists() else None
|
||||
logger.debug(f"Custom CSS: {self.slug}: {self.custom_css}")
|
||||
self.custom_js_src_file = Path(f"{content_dir}/{md_file.stem}.js")
|
||||
self.custom_js = f"assets/js/{md_file.stem}.js" if self.custom_js_src_file.exists() else None
|
||||
self.custom_js = f"static/js/{md_file.stem}.js" if self.custom_js_src_file.exists() else None
|
||||
logger.debug(f"Custom JS: {self.slug}: {self.custom_js}")
|
||||
# Special handling for the 'about' item
|
||||
if self.slug == 'about':
|
||||
self.image = 'static/about.jpg'
|
||||
|
||||
logger.info(f"Building the '{Config.MAIN_PAGE_TITLE}' site.")
|
||||
|
||||
# Recreate the output dir if needed
|
||||
if output_dir.exists():
|
||||
shutil.rmtree(output_dir)
|
||||
output_dir.mkdir()
|
||||
|
||||
# Create public subdirs
|
||||
img_dir.mkdir()
|
||||
assets_dir.mkdir()
|
||||
assets_css_dir.mkdir()
|
||||
assets_js_dir.mkdir()
|
||||
subdirs = [img_dir, assets_css_dir, assets_js_dir]
|
||||
for subdir in subdirs:
|
||||
subdir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Copy static files if exist
|
||||
if static_dir.exists():
|
||||
shutil.copytree(static_dir, output_dir / "static")
|
||||
shutil.copytree(static_dir, output_dir / "static", dirs_exist_ok=True)
|
||||
|
||||
# Prepare template rendering engine
|
||||
env = Environment(loader=FileSystemLoader(str(template_dir)))
|
||||
|
||||
20
logger.py
Normal file
20
logger.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import logging, sys
|
||||
from config import Config
|
||||
|
||||
# Logging config section
|
||||
|
||||
LOG_TO = sys.stdout
|
||||
LOG_LEVEL = logging.INFO
|
||||
|
||||
logger = logging.getLogger(Config.APP_NAME)
|
||||
logger.setLevel(LOG_LEVEL)
|
||||
stdout_handler = logging.StreamHandler(LOG_TO)
|
||||
stdout_handler.setLevel(LOG_LEVEL)
|
||||
formatter = logging.Formatter(
|
||||
'[%(asctime)s] %(name)s: %(levelname)s: %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S'
|
||||
)
|
||||
stdout_handler.setFormatter(formatter)
|
||||
if not logger.hasHandlers():
|
||||
logger.addHandler(stdout_handler)
|
||||
logger.propagate = False
|
||||
Reference in New Issue
Block a user