Skip to content

Commit

Permalink
Support live reload for custom template file
Browse files Browse the repository at this point in the history
  • Loading branch information
liang2kl committed Sep 25, 2021
1 parent 8d4d4a5 commit 56e664a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions mkdocs_blogging_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ class BloggingPlugin(BasePlugin):
template = None

util = Util()

def on_serve(self, server, config, builder):
self.get_template(config)

if self.template:
# Watch the template file for live reload
server.watch(self.template)

return server

def on_config(self, config):
self.size = self.config.get("size")
Expand Down Expand Up @@ -71,10 +80,8 @@ def on_config(self, config):
# Remove all posts to adapt live reload
self.blog_pages = []

if self.config.get("template"):
root_url = os.path.dirname(config.get("config_file_path"))
self.template = root_url + "/" + self.config.get("template")

if not self.template:
self.get_template(config)

def on_page_content(self, html, page, config, files):
"""
Expand Down Expand Up @@ -140,3 +147,8 @@ def on_post_page(self, output, page, config):

return output


def get_template(self, config):
if self.config.get("template"):
root_url = os.path.dirname(config.get("config_file_path"))
self.template = root_url + "/" + self.config.get("template")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="mkdocs-blogging-plugin",
version="0.2.1",
version="0.2.2",
description="Mkdocs plugin that generates a blog index page sorted by creation date.",
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 56e664a

Please sign in to comment.