lua - now we have a plugin manager which works relativley cool!
This commit is contained in:
26
PyPost.py
26
PyPost.py
@@ -7,14 +7,19 @@ from pathlib import Path
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
import base64
|
||||
import random
|
||||
import time
|
||||
|
||||
import marko
|
||||
from marko.ext.gfm import GFM
|
||||
from watchdog.observers import Observer
|
||||
|
||||
from log.Logger import *
|
||||
from log.Logger import *
|
||||
from hashes.hashes import hash_list
|
||||
from htmlhandler import htmlhandler as Handler
|
||||
from lua import plugin_manager
|
||||
|
||||
plugin_manager = plugin_manager.PluginManager()
|
||||
plugin_manager.load_all() # load plugins
|
||||
|
||||
# Use absolute paths
|
||||
ROOT = Path(os.path.abspath("."))
|
||||
@@ -108,6 +113,15 @@ def render_markdown(md_path: Path):
|
||||
if line.startswith("# "):
|
||||
title = line[2:].strip()
|
||||
break
|
||||
|
||||
# Call pre_template hook properly
|
||||
Logger.log_debug(f"Calling pre_template hook for {md_path}")
|
||||
modified = plugin_manager.run_hook("pre_template", str(md_path), html_body)
|
||||
if modified is not None:
|
||||
html_body = modified
|
||||
Logger.log_debug("pre_template hook modified the content")
|
||||
else:
|
||||
Logger.log_debug("pre_template hook returned None")
|
||||
|
||||
# Create clean HTML structure
|
||||
# Pick two different hashes from hash_list
|
||||
@@ -120,11 +134,15 @@ def render_markdown(md_path: Path):
|
||||
title=title,
|
||||
html_body=html_body,
|
||||
now=time.asctime(time.localtime()),
|
||||
hash1 = base64.b64encode(hash1.encode("utf-8")).decode("utf-8"),
|
||||
hash2 = base64.b64encode(hash2.encode("windows-1252")).decode("utf-8"),
|
||||
hash1=base64.b64encode(hash1.encode("utf-8")).decode("utf-8"),
|
||||
hash2=base64.b64encode(hash2.encode("windows-1252")).decode("utf-8"),
|
||||
timestamp=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
|
||||
)
|
||||
|
||||
post_mod = plugin_manager.run_hook("post_render", str(md_path), clean_jinja_html)
|
||||
if post_mod is not None:
|
||||
clean_jinja_html = post_mod
|
||||
|
||||
# Ensure html directory exists
|
||||
HTML_DIR.mkdir(exist_ok=True)
|
||||
|
||||
@@ -145,13 +163,11 @@ def remove_html(md_path: Path):
|
||||
out_path.unlink()
|
||||
Logger.log_debug(f"Removed: {out_path}")
|
||||
|
||||
|
||||
def initial_scan(markdown_dir: Path):
|
||||
Logger.log_info(f"Starting initial scan of markdown files in {markdown_dir}...")
|
||||
for md in markdown_dir.rglob("*.md"):
|
||||
render_markdown(md)
|
||||
|
||||
|
||||
def build_rust_parser() -> bool:
|
||||
fastmd_dir = ROOT / "fastmd"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user