This commit is contained in:
SG
2025-06-10 23:11:10 +03:00
parent 7c7dedcfa5
commit 2e93be7184
7 changed files with 26 additions and 14 deletions

View File

@@ -16,31 +16,36 @@ class ContentItem:
shutil.copyfile(self.image_file, Path(Config.OUTPUT_DIR) / self.image_file) shutil.copyfile(self.image_file, Path(Config.OUTPUT_DIR) / self.image_file)
self.image_file = f"{self.image_file.stem}.jpg" self.image_file = f"{self.image_file.stem}.jpg"
if self.css_file and self.css_file.exists(): if self.css_file and self.css_file.exists():
shutil.copyfile(self.css_file,Path(Config.OUTPUT_DIR) / self.css_file) css_targetfile = Path(f"{Config.OUTPUT_DIR}/{Config.STATIC_DIR}/css/{self.css_file.name}")
logger.debug(f"Copying {self.css_file} to {css_targetfile}")
shutil.copyfile(self.css_file, css_targetfile)
self.css_file = css_targetfile
if self.js_file and self.js_file.exists(): if self.js_file and self.js_file.exists():
shutil.copyfile(self.js_file, Path(Config.OUTPUT_DIR) / self.js_file) shutil.copyfile(self.js_file, Path(Config.OUTPUT_DIR) / self.js_file)
with self.target_filename.open("w", encoding="utf-8") as f: with self.target_filename.open("w", encoding="utf-8") as f:
f.write(content_item_template.render(content_item = self, page_title = self.title)) f.write(content_item_template.render(content_item = self, page_title = self.title))
def parse_content(self): def parse_content(self):
logger.debug(f"Parsing file {self.source_filename}")
try: try:
self.source_filename = Path(self.source_filename) self.source_filename = Path(self.source_filename)
logger.debug(f"Parsing item {self.source_filename}")
self.subdir = self.source_filename.parent self.subdir = self.source_filename.parent
self.slug = self.source_filename.stem self.slug = self.source_filename.stem
self.target_filename = Path(f"{Config.OUTPUT_DIR}/{self.source_filename.parent}/{self.source_filename.stem}.html") self.target_filename = Path(f"{Config.OUTPUT_DIR}/{self.source_filename.parent}/{self.source_filename.stem}.html")
self.data = frontmatter.load(self.source_filename) self.data = frontmatter.load(self.source_filename)
self.html = markdown.markdown(self.data.content.replace('\n', ' \n'))
self.url = "<a href=" + f"{self.subdir}/{self.slug}.html" + "> ...read more</a>" self.url = "<a href=" + f"{self.subdir}/{self.slug}.html" + "> ...read more</a>"
self.preview = self.html[:300] + self.url self.preview = self.data.content.replace('\n', '<br>')[:300] + self.url
self.title = self.data.get("title", self.slug) self.title = self.data.get("title", self.slug)
self.omit_second_title = self.data.get("omit_second_title", False) self.omit_second_title = self.data.get("omit_second_title", False)
self.date = self.data.get("date", "2000-01-01T00:00:00+03:00") self.date = self.data.get("date", "2000-01-01T00:00:00+03:00")
self.categories = self.data.get("categories", str([])) self.categories = self.data.get("categories", str([]))
self.hidden = self.data.get("hidden", str(False)) self.hidden = self.data.get("hidden", str(False))
self.data.content = self.data.content.replace('\n', ' \n')
self.html = markdown.markdown(self.data.content)
cover_image_path = Path(self.source_filename.parent) / Path(self.source_filename.stem + ".jpg") cover_image_path = Path(self.source_filename.parent) / Path(self.source_filename.stem + ".jpg")
self.image_file = cover_image_path if cover_image_path.exists() else None self.image_file = cover_image_path if cover_image_path.exists() else None
self.css_file = Path(self.source_filename.stem + ".css") if Path(self.source_filename.stem + ".css").exists() else None css_filepath = Path(f"{self.source_filename.parent}/{self.source_filename.stem}.css")
self.css_file = css_filepath if css_filepath.exists() else None
self.js_file = Path(self.source_filename.stem + ".js") if Path(self.source_filename.stem + ".js").exists else None self.js_file = Path(self.source_filename.stem + ".js") if Path(self.source_filename.stem + ".js").exists else None
except Exception as e: except Exception as e:
logger.error(e) logger.error(e)

View File

@@ -10,4 +10,5 @@ class Config:
TEMPLATES_DIR = 'templates' TEMPLATES_DIR = 'templates'
CONTENT_DIR = 'content' CONTENT_DIR = 'content'
STATIC_DIR = 'static' STATIC_DIR = 'static'
HEADER_IMAGE = 'static/header.jpg' HEADER_IMAGE = 'static/header.jpg'
THEME = "default"

BIN
static/images/1x1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

BIN
static/images/1x1.png.1 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

View File

@@ -2,8 +2,8 @@
{% extends "default.html" %} {% extends "default.html" %}
{% block head_includes %} {% block head_includes %}
{% if content_item.custom_css %} {% if content_item.css_file %}
<link href="{{ content_item.custom_css }}"> <link rel="stylesheet" href="/{{ content_item.css_file }}">
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@@ -12,7 +12,7 @@
position: relative; position: relative;
height: 250px; height: 250px;
background: rgb(70, 70, 124); background: rgb(70, 70, 124);
background-image: url("{{ header_image }}"); background-image: url("/public/static/header.jpg");
background-size: cover; background-size: cover;
background-position: center; background-position: center;
display: flex; display: flex;
@@ -63,10 +63,10 @@
font-size: 1.1rem; font-size: 1.1rem;
line-height: 1.6; line-height: 1.6;
} }
</style>
{% block head_includes %} {% block head_includes %}
{% endblock %} {% endblock %}
</style> </head>
</head>
<body> <body>
<div class="top_header"> <div class="top_header">
<div > <div >

View File

@@ -9,17 +9,23 @@
{% block content %} {% block content %}
<!-- <div class="row row-cols-1 row-cols-md-3 row-cols-xxl-5 g-4 px-1 py-2"> --> <!-- <div class="row row-cols-1 row-cols-md-3 row-cols-xxl-5 g-4 px-1 py-2"> -->
<div class="container-fluid"> <div class="container-fluid content-row">
<div class="row justify-content-center"> <div class="row">
{% for content_item in content_items %} {% for content_item in content_items %}
<div class="d-flex justify-content-center mb-4">
<div class="card h-100 rounded mx-1 my-3" style="width: 100%; max-width: 400px;"> <div class="card h-100 rounded mx-1 my-3" style="width: 100%; max-width: 400px;">
<div class="card-header bg-dark"> <div class="card-header">
{% if content_item.image_file %}
<img src="content/{{ content_item.image_file }}" alt="{{ content_item.title }}" class="card-img-top img-fluid mx-auto d-block object-fit-scale rounded" style="max-height: 200px; width: auto;"> <img src="content/{{ content_item.image_file }}" alt="{{ content_item.title }}" class="card-img-top img-fluid mx-auto d-block object-fit-scale rounded" style="max-height: 200px; width: auto;">
{% else %}
<img src="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>
<div class="card-body d-flex flex-column"> <div class="card-body d-flex flex-column">
<h5 class="card-title"><a class="text-decoration-none text-body" href="content/{{ content_item.slug}}.html ">{{ content_item.title }}</a></h5> <h5 class="card-title"><a class="text-decoration-none text-body" href="content/{{ content_item.slug}}.html ">{{ content_item.title }}</a></h5>
<p class="card-text mb-3">{{ content_item.preview | safe}}</p> <p class="card-text mb-3">{{ content_item.preview | safe}}</p>
</div> </div>
</div>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>