updates
This commit is contained in:
41
classes.py
41
classes.py
@@ -28,8 +28,10 @@ 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")
|
||||||
|
|
||||||
class ContentItem:
|
class ContentItem:
|
||||||
def render_content(self, categories):
|
def render_content(self, categories, target_file = False):
|
||||||
logger.debug(f"Rendering {self.source_filename} to {self.target_filename}")
|
if target_file:
|
||||||
|
self.target_file = Path(target_file)
|
||||||
|
logger.debug(f"Rendering {self.source_file} to {self.target_file}")
|
||||||
try:
|
try:
|
||||||
if self.image_file and self.image_file.exists():
|
if self.image_file and self.image_file.exists():
|
||||||
image_targetfile = Path(f"{Config.OUTPUT_DIR}/{Config.STATIC_DIR}/images/{self.image_file.name}")
|
image_targetfile = Path(f"{Config.OUTPUT_DIR}/{Config.STATIC_DIR}/images/{self.image_file.name}")
|
||||||
@@ -44,19 +46,19 @@ class ContentItem:
|
|||||||
js_targetfile = Path(f"{Config.OUTPUT_DIR}/{Config.STATIC_DIR}/js/{self.js_file.name}")
|
js_targetfile = Path(f"{Config.OUTPUT_DIR}/{Config.STATIC_DIR}/js/{self.js_file.name}")
|
||||||
logger.debug(f"Copying {self.js_file} to {js_targetfile}")
|
logger.debug(f"Copying {self.js_file} to {js_targetfile}")
|
||||||
shutil.copyfile(self.js_file, js_targetfile)
|
shutil.copyfile(self.js_file, js_targetfile)
|
||||||
with self.target_filename.open("w", encoding="utf-8") as f:
|
with self.target_file.open("w", encoding="utf-8") as f:
|
||||||
f.write(content_item_template.render(content_item = self, page_title = self.title, parent_path = '../', categories = categories))
|
f.write(content_item_template.render(content_item = self, page_title = self.title, parent_path = '../', categories = categories))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Renderer: {e}")
|
logger.error(f"Renderer: {e}")
|
||||||
|
|
||||||
def parse_content(self):
|
def parse_content(self):
|
||||||
logger.debug(f"Parsing file {self.source_filename}")
|
logger.debug(f"Parsing file {self.source_file}")
|
||||||
try:
|
try:
|
||||||
self.source_filename = Path(self.source_filename)
|
self.source_file = Path(self.source_file)
|
||||||
self.subdir = self.source_filename.parent
|
self.subdir = self.source_file.parent
|
||||||
self.slug = self.source_filename.stem
|
self.slug = self.source_file.stem
|
||||||
self.target_filename = Path(f"{Config.OUTPUT_DIR}/{self.source_filename.parent}/{self.source_filename.stem}.html")
|
self.target_file = Path(f"{Config.OUTPUT_DIR}/{self.source_file.parent}/{self.source_file.stem}.html")
|
||||||
self.data = frontmatter.load(self.source_filename)
|
self.data = frontmatter.load(self.source_file)
|
||||||
self.preview = self.data.content.replace('\n', '<br>')[:300]
|
self.preview = self.data.content.replace('\n', '<br>')[:300]
|
||||||
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)
|
||||||
@@ -65,20 +67,20 @@ class ContentItem:
|
|||||||
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.data.content = self.data.content.replace('\n', ' \n')
|
||||||
self.html = markdown.markdown(self.data.content)
|
self.html = markdown.markdown(self.data.content)
|
||||||
cover_image_path = Path(f"{self.source_filename.parent}/{self.source_filename.stem}.jpg")
|
cover_image_path = Path(f"{self.source_file.parent}/{self.source_file.stem}.jpg")
|
||||||
self.image_file = cover_image_path if cover_image_path.exists() else ""
|
self.image_file = cover_image_path if cover_image_path.exists() else ""
|
||||||
css_filepath = Path(f"{self.source_filename.parent}/{self.source_filename.stem}.css")
|
css_filepath = Path(f"{self.source_file.parent}/{self.source_file.stem}.css")
|
||||||
self.css_file = css_filepath if css_filepath.exists() else ""
|
self.css_file = css_filepath if css_filepath.exists() else ""
|
||||||
js_filepath = Path(f"{self.source_filename.parent}/{self.source_filename.stem}.js")
|
js_filepath = Path(f"{self.source_file.parent}/{self.source_file.stem}.js")
|
||||||
self.js_file = js_filepath if js_filepath.exists() else ""
|
self.js_file = js_filepath if js_filepath.exists() else ""
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Parser error, {e}")
|
logger.error(f"Parser error, {e}")
|
||||||
|
|
||||||
def create_content(self):
|
def create_content(self):
|
||||||
with open(self.source_filename, mode="w", encoding="utf-8") as f:
|
with open(self.source_file, mode="w", encoding="utf-8") as f:
|
||||||
f.writelines([
|
f.writelines([
|
||||||
"---\n",
|
"---\n",
|
||||||
f"title: {self.source_filename.stem}\n",
|
f"title: {self.source_file.stem}\n",
|
||||||
f"date: '{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}'\n",
|
f"date: '{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}'\n",
|
||||||
"description: ''\n",
|
"description: ''\n",
|
||||||
"author: ''\n",
|
"author: ''\n",
|
||||||
@@ -89,8 +91,8 @@ class ContentItem:
|
|||||||
"\n\n\n"
|
"\n\n\n"
|
||||||
])
|
])
|
||||||
|
|
||||||
def __init__(self, filename):
|
def __init__(self, file):
|
||||||
self.source_filename = filename
|
self.source_file = file
|
||||||
|
|
||||||
class Site:
|
class Site:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -113,9 +115,6 @@ class Site:
|
|||||||
|
|
||||||
# copy default theme
|
# copy default theme
|
||||||
shutil.copytree(f"{base_dir}/themes/default", "themes/default", dirs_exist_ok=True)
|
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()
|
|
||||||
|
|
||||||
def get_content_items(self):
|
def get_content_items(self):
|
||||||
logger.debug("Getting content items")
|
logger.debug("Getting content items")
|
||||||
@@ -141,7 +140,7 @@ class Site:
|
|||||||
|
|
||||||
# Create public subdirs
|
# Create public subdirs
|
||||||
#subdirs = [self.images_dir, self.css_dir, self.js_dir, self.content_dir, "categories"]
|
#subdirs = [self.images_dir, self.css_dir, self.js_dir, self.content_dir, "categories"]
|
||||||
subdirs = ["static", "categories"]
|
subdirs = ["categories", "content", "static"]
|
||||||
for subdir in subdirs:
|
for subdir in subdirs:
|
||||||
subdir = self.output_dir / subdir
|
subdir = self.output_dir / subdir
|
||||||
subdir.mkdir(parents=True, exist_ok=True)
|
subdir.mkdir(parents=True, exist_ok=True)
|
||||||
@@ -162,7 +161,7 @@ class Site:
|
|||||||
# Render the about file
|
# Render the about file
|
||||||
about_content = ContentItem(Path(f'themes/{Config.THEME}/static/about.md'))
|
about_content = ContentItem(Path(f'themes/{Config.THEME}/static/about.md'))
|
||||||
about_content.parse_content()
|
about_content.parse_content()
|
||||||
about_content.render_content(categories = self.categories)
|
about_content.render_content(categories = self.categories, target_file='public/static/about.html')
|
||||||
|
|
||||||
# Render the index file
|
# Render the index file
|
||||||
visible_content_items = [c for c in self.content_items if c.data.get("hidden") != True]
|
visible_content_items = [c for c in self.content_items if c.data.get("hidden") != True]
|
||||||
|
|||||||
@@ -3,4 +3,3 @@ title: "About"
|
|||||||
omit_second_title: True
|
omit_second_title: True
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
height: 200px;
|
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/images/header.jpg");
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
background-position: center;
|
background-position: center;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
Reference in New Issue
Block a user