From: Zachary Vance Date: Wed, 3 Jul 2024 05:19:45 +0000 (-0400) Subject: Restart the blog conversion if 'blog' changes in --follow mode X-Git-Url: https://git.za3k.com/?a=commitdiff_plain;h=7ac243ee6760a2bfd8c55f9531eca816941b246d;p=blog.git Restart the blog conversion if 'blog' changes in --follow mode --- diff --git a/blog b/blog index c1c8c34..d505ed7 100755 --- a/blog +++ b/blog @@ -4,7 +4,7 @@ import yaml import chevron as mustache from pathlib import Path import collections -import os.path +import os, os.path import sys import frontmatter @@ -26,7 +26,24 @@ def url_slug(title): title = "".join(x for x in title if x in allowable) return title -RELOAD_HTML = b"""""" +RELOAD_HTML = b""" + +""" class Templatable(PseudoMap): def __init__(self, blog): @@ -111,6 +128,7 @@ class Blog(PseudoMap): self.posts = [] self.reload = reload + self.config = os.path.abspath(config) self.load_config(config) self.load_posts() @@ -178,8 +196,16 @@ class Blog(PseudoMap): for path in paths: self._update_happened(path) + @staticmethod + def reboot(): + os.execl(sys.argv[0], *sys.argv) + def _update_happened(self, path): path = Path(path) + reload_update = [ + os.path.abspath(__file__), + self.config, + ] global_update = [ self.tag_template, self.category_template, self.post_template, Path(self.static_dir) / "wp-includes", @@ -191,17 +217,18 @@ class Blog(PseudoMap): self.static_dir, # aside from those two subdirs self.image_dir, ] + if str(path) in reload_update: + print(path, "updated, restarting 'blog'...") + self.reboot() if any(path.is_relative_to(top) for top in global_update): - print(path, "updated, generating all...", file=sys.stderr) + print(path, "updated, generating all", file=sys.stderr) self.generate_all() elif any(path.is_relative_to(top) for top in local_update): - print(path, "updated, generating all (needlessly)...", file=sys.stderr) + print(path, "updated, generating all (needlessly)", file=sys.stderr) self.generate_all() # TODO: Don't generate everything else: #print(path, "updated, ignoring...", file=sys.stderr) pass - - # TODO: Reload when 'blog' executable or config file is changed? if __name__ == "__main__": parser = argparse.ArgumentParser( @@ -220,7 +247,7 @@ if __name__ == "__main__": if args.all: blog.generate_all() else: - blog.updates_happened(changed_files) + blog.updates_happened(args.changed_files) if args.follow: print("monitoring for changes...", file=sys.stderr)