This commit is contained in:
Ruidy 2023-07-05 21:00:22 +02:00
parent 5e39e5920a
commit 24632b08f0
5 changed files with 43 additions and 13 deletions

View file

@ -2,6 +2,7 @@ build:
@pipenv run python -m lib.main @pipenv run python -m lib.main
run: build run: build
@echo ""
@cd dist && pipenv run python -m http.server @cd dist && pipenv run python -m http.server
lint: lint:

View file

@ -5,7 +5,7 @@ name = "pypi"
[packages] [packages]
jinja2 = "*" jinja2 = "*"
loguru = "*" rich = "*"
[dev-packages] [dev-packages]
black = "*" black = "*"

36
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "4c4b43f1ede1c6a64f569dbd3bbfdc2c6aabfe004db06d43fe42496847026061" "sha256": "bef80c03c82a5024d5fd39621dcbdf6fb13cdcf4f3765b97214d0d0cfa7c99b1"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -24,13 +24,13 @@
"index": "pypi", "index": "pypi",
"version": "==3.1.2" "version": "==3.1.2"
}, },
"loguru": { "markdown-it-py": {
"hashes": [ "hashes": [
"sha256:1612053ced6ae84d7959dd7d5e431a0532642237ec21f7fd83ac73fe539e03e1", "sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1",
"sha256:b93aa30099fa6860d4727f1b81f8718e965bb96253fa190fab2077aaad6d15d3" "sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb"
], ],
"index": "pypi", "markers": "python_version >= '3.8'",
"version": "==0.7.0" "version": "==3.0.0"
}, },
"markupsafe": { "markupsafe": {
"hashes": [ "hashes": [
@ -87,6 +87,30 @@
], ],
"markers": "python_version >= '3.7'", "markers": "python_version >= '3.7'",
"version": "==2.1.3" "version": "==2.1.3"
},
"mdurl": {
"hashes": [
"sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8",
"sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"
],
"markers": "python_version >= '3.7'",
"version": "==0.1.2"
},
"pygments": {
"hashes": [
"sha256:8ace4d3c1dd481894b2005f560ead0f9f19ee64fe983366be1a21e171d12775c",
"sha256:db2db3deb4b4179f399a09054b023b6a586b76499d36965813c71aa8ed7b5fd1"
],
"markers": "python_version >= '3.7'",
"version": "==2.15.1"
},
"rich": {
"hashes": [
"sha256:8f87bc7ee54675732fa66a05ebfe489e27264caeeff3728c945d25971b6485ec",
"sha256:d653d6bccede5844304c605d5aac802c7cf9621efd700b46c7ec2b51ea914898"
],
"index": "pypi",
"version": "==13.4.2"
} }
}, },
"develop": { "develop": {

View file

@ -74,6 +74,8 @@ You can then deploy the site on any platform supporting static sites (Netlify,
- [ ] Create a template for the rooms - [ ] Create a template for the rooms
- [ ] Build script before commit - [ ] Build script before commit
- [ ] Lit parapluie, barbecue et machine à laver - [ ] Lit parapluie, barbecue et machine à laver
- [x] Use rich instead of logger
- [ ] Add file watching mode
## Excluded ## Excluded

View file

@ -5,7 +5,7 @@ import tomllib
from distutils.dir_util import copy_tree from distutils.dir_util import copy_tree
from time import perf_counter from time import perf_counter
from loguru import logger from rich import print
from lib.config import Config, load from lib.config import Config, load
from lib.engine import FileSystemRenderer from lib.engine import FileSystemRenderer
@ -17,28 +17,31 @@ def main():
fs = FileSystemRenderer(config) fs = FileSystemRenderer(config)
logger.info(f"🏁 Start building {config.name}") print(f"🏁 Start building [italic red]{config.name}[/italic red]")
clean_dist(config.out_dir) clean_dist(config.out_dir)
for page in os.scandir(config.templates_dir): for page in os.scandir(config.templates_dir):
if page.is_file(): if page.is_file():
with open(os.path.join(config.out_dir, page.name), "w") as fd: with open(os.path.join(config.out_dir, page.name), "w") as fd:
data = parse_data(page, config.data_dir) data = parse_data(page, config.data_dir)
logger.info(f"📃 Render '{page.name}'") print(f"📃 Render [italic cyan]{page.name}[/italic cyan]")
fd.write(fs.render(page.name, data)) fd.write(fs.render(page.name, data))
logger.info("⏩ Copy static assets to build") print("⏩ Copy static assets to build")
copy_tree(config.static_dir, os.path.join(config.out_dir)) copy_tree(config.static_dir, os.path.join(config.out_dir))
end = perf_counter() end = perf_counter()
logger.info(f"🎉 Done… in {(end - start) * 1000:.2f} ms") print(f"🎉 Done… in [italic red]{(end - start) * 1000:.2f} ms[/italic red]")
def parse_config() -> Config: def parse_config() -> Config:
try: try:
config = load() config = load()
except FileNotFoundError: except FileNotFoundError:
logger.error("the configuration file 'config.toml' was not found. Please verify it exists at the root level") print(
"🛑 configuration file [italic red]'config.toml'[/italic red] was not found. "
"Please verify it exists at the root level"
)
sys.exit(1) sys.exit(1)
else: else:
return config return config