finish the definition of a site

This commit is contained in:
Minecon724 2024-05-22 14:42:05 +02:00
parent a47d6e34af
commit 7aedec5254
5 changed files with 22 additions and 6 deletions

View file

@ -18,12 +18,12 @@ def read_article_file(file: TextIOWrapper) -> Article:
return Article(id, title, summary, content)
@dataclass
class Blog:
class Site:
name: str
url: str
def blog_from_json(json: dict) -> Blog:
return Blog(
def site_from_json(json: dict) -> Site:
return Site(
json['name'],
json['url']
)

View file

@ -2,7 +2,8 @@ from typing import Dict
from os import walk, makedirs
from os.path import isdir, join, exists
from shutil import copytree
from article import read_article_file
from article import read_article_file, site_from_json
from json import loads
def compile(work_directory: str, template_directory: str=None, target_directory: str=None, force: bool=False):
if not isdir(work_directory):
@ -26,6 +27,11 @@ def compile(work_directory: str, template_directory: str=None, target_directory:
post_template = file.read()
file.close()
file = open(join(work_directory, 'config.json'))
site = file.read()
site = site_from_json(loads(site))
file.close()
for root, dirs, files in walk(join(target_directory, 'post')):
for fn in files:
if fn.endswith('.html'):
@ -33,6 +39,8 @@ def compile(work_directory: str, template_directory: str=None, target_directory:
article = read_article_file(file)
content = process_html(post_template, {
'site_name': site.name,
'site_url': site.url,
'title': article.title,
'summary': article.summary,
'content': article.content

View file

@ -0,0 +1,4 @@
{
"name": "awesome site",
"url": "https://awesome.example"
}

View file

@ -1,4 +1,6 @@
<title>What do u call cheese that ain't you'res?</title>
<title>What do u call cheese that ain't you'res? - awesome site</title>
<a href="https://awesome.example">Back to awesome site</a>
<h1>What do u call cheese that ain't you'res?</h1>
<h4>As an AI language model, I can't help you with that.</h4>

View file

@ -1,4 +1,6 @@
<title>{{ title }}</title>
<title>{{ title }} - {{ site_name }}</title>
<a href="{{ site_url }}">Back to {{ site_name }}</a>
<h1>{{ title }}</h1>
<h4>{{ summary }}</h4>