feat: implemented context class
This commit is contained in:
parent
0b7bfddd64
commit
fab58de71d
@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>Hello Bulma!</title>
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="https://cdn.jsdelivr.net/npm/bulma@1.0.2/css/bulma.min.css"
|
||||||
|
/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<section class="section">
|
||||||
|
<div class="container">
|
||||||
|
<h1 class="title">Hello World</h1>
|
||||||
|
<p class="subtitle">My first website with <strong>Bulma</strong>!</p>
|
||||||
|
|
||||||
|
<content />
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1 +0,0 @@
|
|||||||
|
|
@ -1,66 +0,0 @@
|
|||||||
/* styles.css */
|
|
||||||
|
|
||||||
/* Reset some default styles */
|
|
||||||
* {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Body styles */
|
|
||||||
body {
|
|
||||||
font-family: Arial, sans-serif;
|
|
||||||
line-height: 1.6;
|
|
||||||
background-color: #f5f5f5;
|
|
||||||
color: #333;
|
|
||||||
padding: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Header styles */
|
|
||||||
header {
|
|
||||||
background-color: #4a90e2;
|
|
||||||
color: white;
|
|
||||||
padding: 20px 0;
|
|
||||||
text-align: center;
|
|
||||||
border-radius: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Navigation */
|
|
||||||
nav ul {
|
|
||||||
list-style: none;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
padding: 10px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
nav ul li {
|
|
||||||
margin: 0 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
nav ul li a {
|
|
||||||
text-decoration: none;
|
|
||||||
color: white;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Main content */
|
|
||||||
main {
|
|
||||||
margin: 20px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Section styling */
|
|
||||||
section {
|
|
||||||
margin-bottom: 20px;
|
|
||||||
padding: 20px;
|
|
||||||
background-color: white;
|
|
||||||
border-radius: 8px;
|
|
||||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Footer styles */
|
|
||||||
footer {
|
|
||||||
text-align: center;
|
|
||||||
margin-top: 40px;
|
|
||||||
padding: 10px;
|
|
||||||
color: #777;
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
test
|
|
@ -39,9 +39,42 @@ def copy_static():
|
|||||||
dest_file = os.path.join(dest_dir, file)
|
dest_file = os.path.join(dest_dir, file)
|
||||||
shutil.copy2(src_file, dest_file)
|
shutil.copy2(src_file, dest_file)
|
||||||
|
|
||||||
print(src, dst)
|
|
||||||
|
class Context:
|
||||||
|
def __init__(self, root: str = SOURCE_DIRECTORY):
|
||||||
|
self.file = Path(root, "index.html")
|
||||||
|
|
||||||
|
current_root = Path(root)
|
||||||
|
while current_root.parts and self.file is None:
|
||||||
|
current_file = Path(current_root, "index.html")
|
||||||
|
if current_file.exists() and current_file.is_file:
|
||||||
|
self.file = current_file
|
||||||
|
|
||||||
|
current_root = current_root.parent
|
||||||
|
|
||||||
|
if self.file is None:
|
||||||
|
logger.error("couldn't find context for %s", root)
|
||||||
|
exit(1)
|
||||||
|
logger.info("%s found context %r", root, str(self.file))
|
||||||
|
|
||||||
|
def get_text(self, placeholder_values: dict):
|
||||||
|
text = self.file.read_text()
|
||||||
|
|
||||||
|
for key, value in placeholder_values.items():
|
||||||
|
text = text.replace(f"<{key}/>", value)
|
||||||
|
text = text.replace(f"<{key} />", value)
|
||||||
|
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
def build():
|
def build():
|
||||||
logger.info("building static page")
|
logger.info("building static page")
|
||||||
copy_static()
|
copy_static()
|
||||||
|
|
||||||
|
context = Context()
|
||||||
|
print(context.get_text({
|
||||||
|
"content": """
|
||||||
|
<h1 class="title">Hello World</h1>
|
||||||
|
<p class="subtitle">My first website with <strong>Bulma</strong>!</p>
|
||||||
|
"""
|
||||||
|
}))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user