moved static files into themes
This commit is contained in:
36
classes.py
36
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")
|
||||
|
||||
Reference in New Issue
Block a user