mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge branch 'master' of github.com:ametaireau/pelican
This commit is contained in:
commit
f081c3b41b
4 changed files with 49 additions and 13 deletions
|
|
@ -127,3 +127,10 @@ And the french one::
|
||||||
Despite the text quality, you can see that only the slug is the same here.
|
Despite the text quality, you can see that only the slug is the same here.
|
||||||
You're not forced to define the slug that way, and it's completely possible to
|
You're not forced to define the slug that way, and it's completely possible to
|
||||||
have two translations with the same title (which defines the slug)
|
have two translations with the same title (which defines the slug)
|
||||||
|
|
||||||
|
Autoreload
|
||||||
|
==========
|
||||||
|
|
||||||
|
It's possible to tell pelican to watch for your modifications, instead of
|
||||||
|
manually launching it each time you need. Use the `-r` option, or
|
||||||
|
`--autoreload`.
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
from pelican.settings import read_settings
|
|
||||||
from pelican.utils import clean_output_dir
|
|
||||||
from pelican.writers import Writer
|
|
||||||
from pelican.generators import (ArticlesGenerator, PagesGenerator,
|
from pelican.generators import (ArticlesGenerator, PagesGenerator,
|
||||||
StaticGenerator, PdfGenerator)
|
StaticGenerator, PdfGenerator)
|
||||||
|
from pelican.settings import read_settings
|
||||||
|
from pelican.utils import clean_output_dir, files_changed
|
||||||
|
from pelican.writers import Writer
|
||||||
|
|
||||||
VERSION = "2.5.3"
|
VERSION = "2.5.3"
|
||||||
|
|
||||||
|
|
@ -107,7 +108,10 @@ def main():
|
||||||
help='Keep the output directory and just update all the generated files.'
|
help='Keep the output directory and just update all the generated files.'
|
||||||
'Default is to delete the output directory.')
|
'Default is to delete the output directory.')
|
||||||
parser.add_argument('--version', action='version', version=VERSION,
|
parser.add_argument('--version', action='version', version=VERSION,
|
||||||
help="Print the pelican version and exit")
|
help='Print the pelican version and exit')
|
||||||
|
parser.add_argument('-r', '--autoreload', dest='autoreload', action='store_true',
|
||||||
|
help="Relaunch pelican each time a modification occurs on the content"
|
||||||
|
"files")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Split the markup languages only if some have been given. Otherwise, populate
|
# Split the markup languages only if some have been given. Otherwise, populate
|
||||||
|
|
@ -125,7 +129,16 @@ def main():
|
||||||
cls = getattr(module, cls_name)
|
cls = getattr(module, cls_name)
|
||||||
|
|
||||||
pelican = cls(settings, args.path, args.theme, args.output, markup, args.keep)
|
pelican = cls(settings, args.path, args.theme, args.output, markup, args.keep)
|
||||||
pelican.run()
|
|
||||||
|
if args.autoreload:
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
if files_changed(pelican.path, pelican.markup):
|
||||||
|
pelican.run()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
pelican.run()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
|
|
@ -276,14 +276,6 @@ img.left, figure.left {float: right; margin: 0 0 2em 2em;}
|
||||||
padding: .3em .25em;
|
padding: .3em .25em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#extras li:last-child,
|
|
||||||
#extras li:last-child a {border: 0}
|
|
||||||
|
|
||||||
#extras .blogroll li:nth-last-child(2),
|
|
||||||
#extras .blogroll li:nth-last-child(3),
|
|
||||||
#extras .blogroll li:nth-last-child(2) a,
|
|
||||||
#extras .blogroll li:nth-last-child(3) a {border: 0;}
|
|
||||||
|
|
||||||
#extras a:hover, #extras a:active {color: #fff;}
|
#extras a:hover, #extras a:active {color: #fff;}
|
||||||
|
|
||||||
/* Blogroll */
|
/* Blogroll */
|
||||||
|
|
|
||||||
|
|
@ -174,3 +174,27 @@ def process_translations(content_list):
|
||||||
for a in items:
|
for a in items:
|
||||||
a.translations = filter(lambda x: x != a, items)
|
a.translations = filter(lambda x: x != a, items)
|
||||||
return index, translations
|
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