moved static files into themes
This commit is contained in:
36
classes.py
36
classes.py
@@ -1,5 +1,6 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import markdown
|
import markdown
|
||||||
@@ -8,7 +9,23 @@ from bs4 import BeautifulSoup
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from logger import logger
|
from logger import logger
|
||||||
from config import Config
|
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:
|
class ContentItem:
|
||||||
def render_content(self, categories):
|
def render_content(self, categories):
|
||||||
@@ -91,19 +108,14 @@ class Site:
|
|||||||
def init_site(self):
|
def init_site(self):
|
||||||
logger.info("Initializing new site")
|
logger.info("Initializing new site")
|
||||||
# Create directories
|
# Create directories
|
||||||
for subdir in [self.content_dir, self.static_dir, self.templates_dir,
|
for subdir in [self.content_dir]:
|
||||||
self.images_dir, self.css_dir, self.js_dir]:
|
|
||||||
os.makedirs(subdir, exist_ok=True)
|
os.makedirs(subdir, exist_ok=True)
|
||||||
# Create templates from literals
|
|
||||||
import templates
|
# copy default theme
|
||||||
template_names = [t for t in dir(templates) if not t.startswith('_')]
|
shutil.copytree(f"{base_dir}/themes/default", "themes/default", dirs_exist_ok=True)
|
||||||
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)
|
|
||||||
# Create static/about.md
|
# Create static/about.md
|
||||||
about_item = ContentItem(filename = Path('static/about.md'))
|
#about_item = ContentItem(filename = Path('static/about.md'))
|
||||||
about_item.create_content()
|
#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,5 +1,4 @@
|
|||||||
import os, sys, subprocess
|
import os, subprocess
|
||||||
import shutil
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from classes import *
|
from classes import *
|
||||||
from config import Config
|
from config import Config
|
||||||
|
|||||||
10
jinja_env.py
10
jinja_env.py
@@ -3,15 +3,17 @@ 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
|
# get the scrip directory
|
||||||
if getattr(sys, 'frozen', False):
|
if getattr(sys, 'frozen', False):
|
||||||
# Running fron Pyinstaller-packed binary
|
# Running fron Pyinstaller-packed binary
|
||||||
base_dir = Path(sys._MEIPASS)
|
base_dir = Path(sys._MEIPASS)
|
||||||
else:
|
else:
|
||||||
# Running as a plain Python app
|
# Running as a plain Python app
|
||||||
base_dir = Path(__file__).resolve().parent
|
base_dir = Path(__file__).resolve().parent
|
||||||
|
|
||||||
env = Environment(loader=FileSystemLoader(f"{base_dir}/{Config.TEMPLATES_DIR}"))
|
# Prepare template rendering engine
|
||||||
env.globals['header_image'] = Config.HEADER_IMAGE
|
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}/static/header.jpg"
|
||||||
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")
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
User-agent: *
|
|
||||||
Disallow: /
|
|
||||||
182
templates.py
182
templates.py
@@ -1,182 +0,0 @@
|
|||||||
default = """
|
|
||||||
<!doctype html>
|
|
||||||
<html data-bs-theme="light">
|
|
||||||
<head>
|
|
||||||
{% set base = "" %}
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-4Q6Gf2aSP4eDXB8Miphtr37CMZZQ5oXLH2yaXMJ2w8e2ZtHTl7GptT4jmndRuHDT" crossorigin="anonymous">
|
|
||||||
<title>{{ page_title }}</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
|
||||||
"Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif,
|
|
||||||
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
|
||||||
}
|
|
||||||
.top_header {
|
|
||||||
position: relative;
|
|
||||||
height: 250px;
|
|
||||||
background: rgb(70, 70, 124);
|
|
||||||
background-image: url("{{ parent_path }}static/header.jpg");
|
|
||||||
background-size: cover;
|
|
||||||
background-position: center;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.top_header_text {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 10px;
|
|
||||||
left: 10px;
|
|
||||||
color: white;
|
|
||||||
font-weight: bold;
|
|
||||||
font-size: 2.5rem;
|
|
||||||
background: rgba(0, 0, 0, 0.05);
|
|
||||||
border-radius: 5px;
|
|
||||||
padding: 10px 20px;
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
@media (min-width: 768px) {
|
|
||||||
.top_header_text {
|
|
||||||
font-size: 4rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
article {
|
|
||||||
font-size: 1.1rem;
|
|
||||||
line-height: 1.6;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
{% block head_includes %}
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="top_header">
|
|
||||||
<div class="col-auto">
|
|
||||||
<h1 class="top_header_text"><a style="border-radius: 5px; padding: 10px; opacity: 0.7; background: black">{{ page_title }}</a></h1>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row justify-content-end pe-2 py-2" >
|
|
||||||
<div class="col-auto fw-bold">
|
|
||||||
<a class="link-body-emphasis mx-2 text-decoration-none" href="{{ parent_path }}index.html">Home</a>
|
|
||||||
<a class="link-body-emphasis mx-2 text-decoration-none" id="categories_toggle" href="#none">Categories</a>
|
|
||||||
<a class="link-body-emphasis mx-2 text-decoration-none" href="{{ parent_path }}static/about.html">About</a>
|
|
||||||
<a class="link-body-emphasis mx-2 text-decoration-none" id="dark_theme_toggle" href="#none">🌓︎</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="categories_container" class="container">
|
|
||||||
<div id="categories_menu" class="row justify-content-center mx-auto mb-2" style="display: none">
|
|
||||||
{% for category in categories %}
|
|
||||||
<a href="{{ parent_path }}categories/{{ category }}.html" class="mx-1 text-decoration-none">{{ category }}</a>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="content" class="container-fluid mb-2">
|
|
||||||
{% block content %}
|
|
||||||
{% endblock %}
|
|
||||||
</div>
|
|
||||||
<div id="footer" class="container-fluid">
|
|
||||||
<div id="footer-data" class="row my-1">
|
|
||||||
{% block footer_includes %}
|
|
||||||
{% endblock %}
|
|
||||||
</div>
|
|
||||||
<div class="row small d-flex text-muted justify-content-end">
|
|
||||||
<div class="col-auto" style="font-size: 0.75rem;">
|
|
||||||
<p>Page created with <a class="text-decoration-none" href="#microgen">microgen</a></p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/js/bootstrap.min.js" integrity="sha384-RuyvpeZCxMJCqVUGFI0Do1mQrods/hhxYlcVfGPOfQtPJh0JCw12tUAZ/Mv10S7D" crossorigin="anonymous"></script>
|
|
||||||
<script defer>
|
|
||||||
const saved_color_theme = localStorage.getItem('saved_color_theme');
|
|
||||||
if (saved_color_theme) {
|
|
||||||
document.documentElement.setAttribute('data-bs-theme', saved_color_theme);
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById("categories_toggle").onclick = function() {
|
|
||||||
categories_menu_item = document.getElementById("categories_menu");
|
|
||||||
categories_menu_item.style.display = categories_menu_item.style.display === "none" ? "block" : "none"
|
|
||||||
};
|
|
||||||
document.getElementById("dark_theme_toggle").onclick = function() {
|
|
||||||
html = document.documentElement;
|
|
||||||
current_color_theme = html.getAttribute('data-bs-theme');
|
|
||||||
new_color_theme = current_color_theme === 'dark' ? 'light' : 'dark';
|
|
||||||
html.setAttribute('data-bs-theme', new_color_theme);
|
|
||||||
localStorage.setItem('saved_color_theme', new_color_theme);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
"""
|
|
||||||
|
|
||||||
index = """
|
|
||||||
{% extends "default.html" %}
|
|
||||||
|
|
||||||
{% block head_includes %}
|
|
||||||
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="row justify-content-between g-4 mb-4 py-4">
|
|
||||||
{% for content_item in content_items %}
|
|
||||||
<div class="col-auto align-items-stretch d-flex mx-2" style="width: 100%; width: 24em;">
|
|
||||||
<div class="card h-100 px-0 rounded mx-1 my-3" style="width: 100%; width: 22em;">
|
|
||||||
<div class="card-header">
|
|
||||||
{% if content_item.image_file %}
|
|
||||||
<img src="{{ parent_path }}static/images/{{ content_item.image_file }}" alt="{{ content_item.title }}" class="card-img-top img-fluid mx-auto d-block object-fit-fill rounded" style="height: 200px; width: auto;">
|
|
||||||
{% else %}
|
|
||||||
<img src="{{ parent_path }}static/images/1x1.png" alt="{{ content_item.title }}" class="card-img-top img-fluid mx-auto d-block object-fit-scale rounded" style="height: 200px; width: auto;">
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
<div class="card-body">
|
|
||||||
<h5 class="fw-bold"><a class="text-decoration-none text-body" href="{{ parent_path }}content/{{ content_item.slug}}.html">{{ content_item.title }}</a></h5>
|
|
||||||
<p class="card-text mb-2">{{ content_item.preview | safe}}<a class="text-decoration-none" href="{{ parent_path }}content/{{ content_item.slug}}.html">... read more</a> </p>
|
|
||||||
</div>
|
|
||||||
<div class="card-footer" style="height: 4em;">
|
|
||||||
{% for item_category in content_item.categories %}
|
|
||||||
<small><a href="{{ parent_path }}categories/{{ item_category }}.html" class="text-muted text-decoration-none mx-1">{{ item_category }}</a></small>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
"""
|
|
||||||
|
|
||||||
content_item="""
|
|
||||||
{% extends "default.html" %}
|
|
||||||
|
|
||||||
{% block head_includes %}
|
|
||||||
{% if content_item.css_file %}
|
|
||||||
<link rel="stylesheet" href="{{ parent_path }}static/css/{{ content_item.slug }}.css">
|
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="container mt-4 mb-5">
|
|
||||||
{% if content_item.image_file %}<img src="{{ parent_path }}static/images/{{ content_item.image_file }}" class="img-fluid mb-5 rounded w-100 h-auto">{% endif %}
|
|
||||||
{% if not content_item.omit_second_title %}
|
|
||||||
<h1>{{ content_item.title }}</h1>
|
|
||||||
{% endif %}
|
|
||||||
<article>{{ content_item.html | safe }}</article>
|
|
||||||
<div id="categories">
|
|
||||||
{% for category in content_item.categories %}
|
|
||||||
<a href="{{ parent_path }}categories/{{ category }}.html" class="mx-1 text-decoration-none small text-muted">{{ category }} </a>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
<a href="../index.html" class="btn btn-secondary mt-4">← Back</a>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block footer_includes %}
|
|
||||||
{% if content_item.js_file %}
|
|
||||||
<script src="{{ parent_path}}static/js/{{ content_item.slug }}.js"></script>
|
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
|
||||||
"""
|
|
||||||
3
test.py
3
test.py
@@ -1,3 +0,0 @@
|
|||||||
from pathlib import Path
|
|
||||||
app_dir = Path(__file__).resolve().parent
|
|
||||||
print(app_dir, type(app_dir))
|
|
||||||
|
Before Width: | Height: | Size: 95 B After Width: | Height: | Size: 95 B |
|
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 60 KiB |
|
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 71 KiB |
@@ -15,7 +15,7 @@
|
|||||||
}
|
}
|
||||||
.top_header {
|
.top_header {
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 250px;
|
height: 200px;
|
||||||
background: rgb(70, 70, 124);
|
background: rgb(70, 70, 124);
|
||||||
background-image: url("{{ parent_path }}static/header.jpg");
|
background-image: url("{{ parent_path }}static/header.jpg");
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
Reference in New Issue
Block a user