Skip to content

Commit

Permalink
Merge pull request #66 from j3soon/fix/live-reload-infinite-loop
Browse files Browse the repository at this point in the history
Fix live reload infinite loop when serving locally
  • Loading branch information
ojacques authored Oct 3, 2024
2 parents 178b66b + a512b1a commit 325cf6f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mkdocs_git_committers_plugin_2/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self):
self.githuburl = "https://api.github.com"
self.gitlaburl = "https://gitlab.com/api/v4"
self.gitlabauthors_cache = dict()
self.should_save_cache = False

def on_config(self, config):
self.enabled = self.config['enabled']
Expand Down Expand Up @@ -241,8 +242,9 @@ def list_contributors(self, path):

authors=[]
authors = self.get_contributors_to_file(path)

self.cache_page_authors[path] = {'last_commit_date': last_commit_date, 'authors': authors}
if path not in self.cache_page_authors or self.cache_page_authors[path] != {'last_commit_date': last_commit_date, 'authors': authors}:
self.should_save_cache = True
self.cache_page_authors[path] = {'last_commit_date': last_commit_date, 'authors': authors}

return authors, last_commit_date

Expand Down Expand Up @@ -270,6 +272,8 @@ def on_page_context(self, context, page, config, nav):
return context

def on_post_build(self, config):
if not self.should_save_cache:
return
LOG.info("git-committers: saving page authors cache file")
json_data = json.dumps({'cache_date': datetime.now().strftime("%Y-%m-%d"), 'page_authors': self.cache_page_authors})
os.makedirs(self.config['cache_dir'], exist_ok=True)
Expand Down

0 comments on commit 325cf6f

Please sign in to comment.