Draft of constructor to merge ./media files into a single HTML string object. 'theme.css' is also scanned to apply future styling. The next focus is a request handler which serves this content.
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
Lorum ipsum, whatever else...
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Lorum ipsum, whatever else...
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Lorum ipsum, whatever else...
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Lorum ipsum, whatever else...
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Lorum ipsum, whatever else...
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Lorum ipsum, whatever else...
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Lorum ipsum, whatever else...
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Lorum ipsum, whatever else...
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Lorum ipsum, whatever else...
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Hello my name Sam etc.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Bye bye and some other stuff.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
|
||||||
|
<!-- THEME -->
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="core">
|
||||||
|
|
||||||
|
<!-- ABSTRACT -->
|
||||||
|
|
||||||
|
<!-- CONTENT -->
|
||||||
|
|
||||||
|
<!-- FOOTER -->
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
[project]
|
||||||
|
name = "personal-site"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = ""
|
||||||
|
authors = [
|
||||||
|
{name = "Samuel Jones",email = "samuel@williamjones.me"}
|
||||||
|
]
|
||||||
|
requires-python = ">=3.14"
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
||||||
|
build-backend = "poetry.core.masonry.api"
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
from personal_site.constructor import main
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
"""
|
||||||
|
This module is charged with parsing the project's content files.
|
||||||
|
From this, we can construct our dynamic HTML.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Imports
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
# Init.
|
||||||
|
CONTENTS_DIR = Path(__file__).parents[2] / "media/site_content/"
|
||||||
|
THEME_PATH = Path(__file__).parents[2] / "media/theme.css"
|
||||||
|
|
||||||
|
|
||||||
|
# Functions
|
||||||
|
def read_file(path: Path) -> str:
|
||||||
|
with open(path, "r") as rf:
|
||||||
|
return "".join(rf.readlines())
|
||||||
|
|
||||||
|
|
||||||
|
def construct_site(
|
||||||
|
contents_dir: Path = CONTENTS_DIR,
|
||||||
|
theme_path: Path = THEME_PATH,
|
||||||
|
) -> str:
|
||||||
|
paths = [path for path in contents_dir.iterdir() if path.suffix == ".txt"]
|
||||||
|
potential_template_path = [path for path in paths if path.stem == "Template"]
|
||||||
|
assert (_l := len(potential_template_path)) == 1, (
|
||||||
|
f"`Template.txt`s found: {_l} (!= 1)."
|
||||||
|
)
|
||||||
|
output = read_file(potential_template_path[0])
|
||||||
|
output = output.replace("<!-- THEME -->", read_file(theme_path))
|
||||||
|
for path in sorted(paths):
|
||||||
|
match path.stem:
|
||||||
|
case "Template":
|
||||||
|
continue
|
||||||
|
case "Abstract":
|
||||||
|
output = output.replace(
|
||||||
|
"<!-- ABSTRACT -->",
|
||||||
|
'\n<div class="abstract">\n' + read_file(path) + "</div>",
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
case "Footer":
|
||||||
|
output = output.replace(
|
||||||
|
"<!-- FOOTER -->",
|
||||||
|
'<div class="footer">\n' + read_file(path) + "</div>\n",
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
case _:
|
||||||
|
...
|
||||||
|
new_text = '\n<div class="entry">\n' + read_file(path) + "</div>\n"
|
||||||
|
output = output.replace((_s := "<!-- CONTENT -->"), new_text + _s)
|
||||||
|
return output.replace("<!-- CONTENT -->", "")
|
||||||
|
|
||||||
|
|
||||||
|
# Script
|
||||||
|
def main():
|
||||||
|
print(construct_site())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user