Adding import command

This commit is contained in:
evilchili 2022-09-17 16:48:16 -07:00
parent f03d1fd6bf
commit 64bed4bbb1
2 changed files with 45 additions and 0 deletions

View File

@ -17,6 +17,7 @@ rich = "latest"
pyyaml = "latest" pyyaml = "latest"
livereload = "latest" livereload = "latest"
jinja2-simple-tags = "latest" jinja2-simple-tags = "latest"
pyinotify = "latest"
# static website # static website
pelican = "^4.7.2" pelican = "^4.7.2"

View File

@ -11,7 +11,11 @@ import site_tools as st
from enum import Enum from enum import Enum
from livereload import Server from livereload import Server
from livereload.watcher import INotifyWatcher
from pathlib import Path
from pelican import main as pelican_main from pelican import main as pelican_main
from time import sleep
from site_tools.content_manager import create from site_tools.content_manager import create
@ -30,6 +34,10 @@ CONFIG = {
'port': 8000, 'port': 8000,
# content manager config # content manager config
'templates_path': 'markdown-templates', 'templates_path': 'markdown-templates',
# directory to watch for new assets
'import_path': 'imports',
# where new asseets will be made available
'production_host': 'deadsands.froghat.club',
} }
app = typer.Typer() app = typer.Typer()
@ -61,6 +69,42 @@ def build() -> None:
pelican_run() pelican_run()
@app.command()
def watch() -> None:
import_path = Path(CONFIG['import_path'])
content_path = Path(st.SETTINGS['PATH'])
def do_import():
assets = []
for src in import_path.rglob('*'):
relpath = src.relative_to(import_path)
target = content_path / relpath
if src.is_dir():
target.mkdir(parents=True, exist_ok=True)
continue
if target.exists():
print(f"{target}: exists; skipping.")
continue
print(f"{target}: importing...")
src.link_to(target)
uri = target.relative_to('content')
assets.append(f"https://{CONFIG['production_host']}/{uri}")
src.unlink()
if assets:
publish()
print('\n\t'.join(["\nImported Asset URLS:"] + assets))
print("\n")
watcher = INotifyWatcher()
watcher.watch(import_path, do_import)
watcher.start(do_import)
print(f"Watching {import_path}. CTRL+C to exit.")
while True:
watcher.examine()
sleep(1)
@app.command() @app.command()
def serve() -> None: def serve() -> None: