feat: added copying static
This commit is contained in:
parent
3503d1d42f
commit
9e2ee75927
4
.gitignore
vendored
4
.gitignore
vendored
@ -171,4 +171,6 @@ cython_debug/
|
||||
.ruff_cache/
|
||||
|
||||
# PyPI configuration file
|
||||
.pypirc
|
||||
.pypirc
|
||||
|
||||
dist
|
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"stsg"
|
||||
]
|
||||
}
|
1
src/static/assets/foo.bar
Normal file
1
src/static/assets/foo.bar
Normal file
@ -0,0 +1 @@
|
||||
test
|
66
src/static/style.css
Normal file
66
src/static/style.css
Normal file
@ -0,0 +1,66 @@
|
||||
/* 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;
|
||||
}
|
@ -6,13 +6,14 @@ import os
|
||||
import subprocess
|
||||
|
||||
from .config import SOURCE_DIRECTORY, CODE_DIRECTORY
|
||||
from .build import build as complete_build
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger("stsg")
|
||||
|
||||
|
||||
def build():
|
||||
print("building changed")
|
||||
complete_build()
|
||||
|
||||
|
||||
class MarkdownChangeHandler(FileSystemEventHandler):
|
||||
@ -26,10 +27,12 @@ class MarkdownChangeHandler(FileSystemEventHandler):
|
||||
|
||||
logger.info("%s changed, building", event.src_path)
|
||||
build()
|
||||
|
||||
|
||||
|
||||
class PythonChangeHandler(FileSystemEventHandler):
|
||||
def __init__(self, command):
|
||||
self.logger = logging.getLogger("stsg.hot_reload")
|
||||
|
||||
self.env = os.environ.copy()
|
||||
self.env["IS_CHILD"] = "true"
|
||||
|
||||
@ -37,11 +40,11 @@ class PythonChangeHandler(FileSystemEventHandler):
|
||||
self.process = self.start_process()
|
||||
|
||||
def start_process(self):
|
||||
print("[hot reload] Starting process...")
|
||||
self.logger.info("Starting process...")
|
||||
return subprocess.Popen(self.command, env=self.env)
|
||||
|
||||
def restart_process(self):
|
||||
print("[hot reload] Restarting process...")
|
||||
self.logger.info("Restarting process...")
|
||||
self.process.kill()
|
||||
self.process = self.start_process()
|
||||
|
||||
@ -54,7 +57,7 @@ class PythonChangeHandler(FileSystemEventHandler):
|
||||
return
|
||||
|
||||
if event.src_path.endswith(".py"):
|
||||
print(f"[hot reload] Detected change: {event.src_path}")
|
||||
self.logger.info(f"Detected change: {event.src_path}")
|
||||
self.restart_process()
|
||||
|
||||
def stop_process(self):
|
||||
@ -84,7 +87,7 @@ def hot_reload():
|
||||
return
|
||||
|
||||
observer = Observer()
|
||||
observer.schedule(PythonChangeHandler(["stsg_build_on_change"]), path=CODE_DIRECTORY, recursive=True)
|
||||
observer.schedule(PythonChangeHandler(["stsg_dev"]), path=CODE_DIRECTORY, recursive=True)
|
||||
observer.start()
|
||||
|
||||
try:
|
||||
|
41
stsg/build.py
Normal file
41
stsg/build.py
Normal file
@ -0,0 +1,41 @@
|
||||
import logging
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
from .config import SOURCE_DIRECTORY, DIST_DIRECTORY, STATIC_DIRECTORY
|
||||
|
||||
|
||||
logger = logging.getLogger("stsg.build")
|
||||
|
||||
|
||||
def copy_static():
|
||||
src = str(Path(SOURCE_DIRECTORY, STATIC_DIRECTORY))
|
||||
dst = str(Path(DIST_DIRECTORY, STATIC_DIRECTORY))
|
||||
|
||||
if not os.path.exists(src):
|
||||
logger.warn("The static folder '%s' wasn't defined.", src)
|
||||
return
|
||||
|
||||
logger.info("copying static files from '%s' to '%r'", src, dst)
|
||||
|
||||
os.makedirs(dst, exist_ok=True)
|
||||
|
||||
for root, dirs, files in os.walk(src):
|
||||
# Compute relative path from the source root
|
||||
rel_path = os.path.relpath(root, src)
|
||||
dest_dir = os.path.join(dst, rel_path)
|
||||
|
||||
os.makedirs(dest_dir, exist_ok=True)
|
||||
|
||||
for file in files:
|
||||
src_file = os.path.join(root, file)
|
||||
dest_file = os.path.join(dest_dir, file)
|
||||
shutil.copy2(src_file, dest_file)
|
||||
|
||||
print(src, dst)
|
||||
|
||||
|
||||
def build():
|
||||
logger.info("building static page")
|
||||
copy_static()
|
@ -1,5 +1,9 @@
|
||||
SOURCE_DIRECTORY = "src"
|
||||
DIST_DIRECTORY = "dist"
|
||||
|
||||
# for development
|
||||
# relative to SOURCE_DIRECTORY / DIST_DIRECTORY
|
||||
STATIC_DIRECTORY = "static"
|
||||
|
||||
# FOR DEVELOPMENT
|
||||
|
||||
CODE_DIRECTORY = "stsg"
|
||||
|
Loading…
x
Reference in New Issue
Block a user