mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Add the autoreload feature. This fixes #45. I've choosen to not serve the content
via HTTP, because it's really simple to do "firefox output/index.html".
This commit is contained in:
parent
55da03ad2f
commit
b8fb45de9e
3 changed files with 49 additions and 5 deletions
|
|
@ -174,3 +174,27 @@ def process_translations(content_list):
|
|||
for a in items:
|
||||
a.translations = filter(lambda x: x != a, items)
|
||||
return index, translations
|
||||
|
||||
|
||||
LAST_MTIME = 0
|
||||
|
||||
|
||||
def files_changed(path, extensions):
|
||||
"""Return True if the files have changed since the last check"""
|
||||
|
||||
def with_extension(f):
|
||||
return True if True in [f.endswith(ext) for ext in extensions] else False
|
||||
|
||||
def file_times(path):
|
||||
"""Return the last time files have been modified"""
|
||||
for top_level in os.listdir(path):
|
||||
for root, dirs, files in os.walk(top_level):
|
||||
for file in filter(with_extension, files):
|
||||
yield os.stat(os.path.join(root, file)).st_mtime
|
||||
|
||||
global LAST_MTIME
|
||||
mtime = max(file_times(path))
|
||||
if mtime > LAST_MTIME:
|
||||
LAST_MTIME = mtime
|
||||
return True
|
||||
return False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue