pep8
This commit is contained in:
parent
8ce1426785
commit
edcc28d056
@ -4,8 +4,6 @@ css-js-minify wrapper for Pelican
|
||||
"""
|
||||
|
||||
import glob
|
||||
import os
|
||||
import sys
|
||||
|
||||
from .minify import (
|
||||
process_single_css_file,
|
||||
@ -17,6 +15,7 @@ from pelican import signals
|
||||
CSS_DIR = '/theme/css'
|
||||
JS_DIR = '/theme/js'
|
||||
|
||||
|
||||
def main(pelican):
|
||||
""" Compiler """
|
||||
for file in glob.iglob(pelican.output_path + CSS_DIR + '/**/*.css', recursive=True):
|
||||
@ -24,10 +23,12 @@ def main(pelican):
|
||||
for file in glob.iglob(pelican.output_path + JS_DIR + '/**/*.js', recursive=True):
|
||||
process_single_js_file(file, overwrite=True)
|
||||
|
||||
|
||||
def register():
|
||||
""" Register """
|
||||
signals.finalized.connect(main)
|
||||
|
||||
|
||||
SUPPORT_JS = """
|
||||
-----------------------------------------------------------------
|
||||
COMPRESSOR:
|
||||
|
@ -32,6 +32,7 @@ color = {
|
||||
'green': '\033[1;32m'
|
||||
}
|
||||
|
||||
|
||||
def process_multiple_files(file_path, watch=False, wrap=False, timestamp=False,
|
||||
comments=False, sort=False, overwrite=False,
|
||||
zipy=False, prefix='', add_hash=False):
|
||||
@ -95,7 +96,9 @@ def process_single_css_file(css_file_path, wrap=False, timestamp=False,
|
||||
zipy=False, prefix='', add_hash=False,
|
||||
output_path=None):
|
||||
"""Process a single CSS file."""
|
||||
print("Processing %sCSS%s file: %s" % (color['cyan'], color['end'], css_file_path))
|
||||
print("Processing %sCSS%s file: %s" % (color['cyan'],
|
||||
color['end'],
|
||||
css_file_path))
|
||||
with open(css_file_path, encoding="utf-8") as css_file:
|
||||
original_css = css_file.read()
|
||||
|
||||
@ -134,7 +137,9 @@ def process_single_css_file(css_file_path, wrap=False, timestamp=False,
|
||||
def process_single_js_file(js_file_path, timestamp=False, overwrite=False,
|
||||
zipy=False, output_path=None):
|
||||
"""Process a single JS file."""
|
||||
print("Processing %sJS%s file: %s" % (color['green'], color['end'], js_file_path))
|
||||
print("Processing %sJS%s file: %s" % (color['green'],
|
||||
color['end'],
|
||||
js_file_path))
|
||||
with open(js_file_path, encoding="utf-8") as js_file:
|
||||
original_js = js_file.read()
|
||||
print("INPUT: Reading JS file %s" % js_file_path)
|
||||
@ -173,7 +178,8 @@ def make_arguments_parser():
|
||||
SHA1 HEX-Digest 11 Chars Hash on Filenames is used for Server Cache.
|
||||
CSS Properties are Alpha-Sorted, to help spot cloned ones, Selectors not.
|
||||
Watch works for whole folders, with minimum of ~60 Secs between runs.""")
|
||||
# parser.add_argument('--version', action='version', version=css_js_minify.__version__)
|
||||
# parser.add_argument('--version', action='version',
|
||||
# version=css_js_minify.__version__)
|
||||
parser.add_argument('fullpath', metavar='fullpath', type=str,
|
||||
help='Full path to local file or folder.')
|
||||
parser.add_argument('--wrap', action='store_true',
|
||||
|
@ -35,7 +35,7 @@ except ImportError:
|
||||
_MAIN_SETTINGS = None # settings dict of the main Pelican instance
|
||||
_MAIN_LANG = None # lang of the main Pelican instance
|
||||
_MAIN_SITEURL = None # siteurl of the main Pelican instance
|
||||
_MAIN_STATIC_FILES = None # list of Static instances the main Pelican instance
|
||||
_MAIN_STATIC_FILES = None # list of Static instances the main Pelican
|
||||
_SUBSITE_QUEUE = {} # map: lang -> settings overrides
|
||||
_SITE_DB = OrderedDict() # OrderedDict: lang -> siteurl
|
||||
_SITES_RELPATH_DB = {} # map: (lang, base_lang) -> relpath
|
||||
@ -81,30 +81,37 @@ def prepare_site_db_and_overrides():
|
||||
|
||||
_SITE_DB.keys() need to be ready for filter_translations
|
||||
'''
|
||||
|
||||
_SITE_DB.clear()
|
||||
_SITE_DB[_MAIN_LANG] = _MAIN_SITEURL
|
||||
|
||||
# make sure it works for both root-relative and absolute
|
||||
main_siteurl = '/' if _MAIN_SITEURL == '' else _MAIN_SITEURL
|
||||
for lang, overrides in _SUBSITE_QUEUE.items():
|
||||
|
||||
main_siteurl = ('/' if _MAIN_SITEURL == '' else _MAIN_SITEURL)
|
||||
for (lang, overrides) in _SUBSITE_QUEUE.items():
|
||||
if 'SITEURL' not in overrides:
|
||||
overrides['SITEURL'] = posixpath.join(main_siteurl, lang)
|
||||
_SITE_DB[lang] = overrides['SITEURL']
|
||||
|
||||
# default subsite hierarchy
|
||||
|
||||
if 'OUTPUT_PATH' not in overrides:
|
||||
overrides['OUTPUT_PATH'] = os.path.join(
|
||||
_MAIN_SETTINGS['OUTPUT_PATH'], lang)
|
||||
overrides['OUTPUT_PATH'] = \
|
||||
os.path.join(_MAIN_SETTINGS['OUTPUT_PATH'], lang)
|
||||
if 'CACHE_PATH' not in overrides:
|
||||
overrides['CACHE_PATH'] = os.path.join(
|
||||
_MAIN_SETTINGS['CACHE_PATH'], lang)
|
||||
overrides['CACHE_PATH'] = \
|
||||
os.path.join(_MAIN_SETTINGS['CACHE_PATH'], lang)
|
||||
if 'STATIC_PATHS' not in overrides:
|
||||
overrides['STATIC_PATHS'] = []
|
||||
if ('THEME' not in overrides and 'THEME_STATIC_DIR' not in overrides and
|
||||
'THEME_STATIC_PATHS' not in overrides):
|
||||
if 'THEME' not in overrides and 'THEME_STATIC_DIR' \
|
||||
not in overrides and 'THEME_STATIC_PATHS' not in overrides:
|
||||
relpath = relpath_to_site(lang, _MAIN_LANG)
|
||||
overrides['THEME_STATIC_DIR'] = posixpath.join(
|
||||
relpath, _MAIN_SETTINGS['THEME_STATIC_DIR'])
|
||||
overrides['THEME_STATIC_PATHS'] = []
|
||||
|
||||
# to change what is perceived as translations
|
||||
|
||||
overrides['DEFAULT_LANG'] = lang
|
||||
|
||||
|
||||
|
@ -8,6 +8,7 @@ variables to the article's context
|
||||
"""
|
||||
from pelican import signals
|
||||
|
||||
|
||||
def iter3(seq):
|
||||
it = iter(seq)
|
||||
nxt = None
|
||||
@ -17,6 +18,7 @@ def iter3(seq):
|
||||
nxt, cur = cur, prv
|
||||
yield nxt, cur, None
|
||||
|
||||
|
||||
def get_translation(article, prefered_language):
|
||||
if not article:
|
||||
return None
|
||||
@ -25,18 +27,16 @@ def get_translation(article, prefered_language):
|
||||
return translation
|
||||
return article
|
||||
|
||||
|
||||
def set_neighbors(articles, next_name, prev_name):
|
||||
for nxt, cur, prv in iter3(articles):
|
||||
exec("cur.{} = nxt".format(next_name))
|
||||
exec("cur.{} = prv".format(prev_name))
|
||||
|
||||
for translation in cur.translations:
|
||||
exec(
|
||||
"translation.{} = get_translation(nxt, translation.lang)".format(
|
||||
next_name))
|
||||
exec(
|
||||
"translation.{} = get_translation(prv, translation.lang)".format(
|
||||
prev_name))
|
||||
exec("translation.{} = get_translation(nxt, translation.lang)".format(next_name))
|
||||
exec("translation.{} = get_translation(prv, translation.lang)".format(prev_name))
|
||||
|
||||
|
||||
def neighbors(generator):
|
||||
set_neighbors(generator.articles, 'next_article', 'prev_article')
|
||||
@ -54,5 +54,6 @@ def neighbors(generator):
|
||||
prev_name = 'prev_article_in_subcategory{}'.format(index)
|
||||
set_neighbors(articles, next_name, prev_name)
|
||||
|
||||
|
||||
def register():
|
||||
signals.article_generator_finalized.connect(neighbors)
|
||||
|
@ -10,6 +10,7 @@ import shutil
|
||||
|
||||
from pelican import signals
|
||||
|
||||
|
||||
def copy_resources(src, dest, file_list):
|
||||
"""
|
||||
Copy files from content folder to output folder
|
||||
@ -33,6 +34,7 @@ def copy_resources(src, dest, file_list):
|
||||
file_src = os.path.join(src, file_)
|
||||
shutil.copy2(file_src, dest)
|
||||
|
||||
|
||||
def add_files(gen, metadata):
|
||||
"""
|
||||
The registered handler for the dynamic resources plugin. It will
|
||||
@ -59,6 +61,7 @@ def add_files(gen, metadata):
|
||||
htmls.append(html)
|
||||
metadata[key] = htmls
|
||||
|
||||
|
||||
def move_resources(gen):
|
||||
"""
|
||||
Move files from js/css folders to output folder
|
||||
|
@ -54,6 +54,7 @@ def format_date(date):
|
||||
tz = "-00:00"
|
||||
return date.strftime("%Y-%m-%dT%H:%M:%S") + tz
|
||||
|
||||
|
||||
class SitemapGenerator(object):
|
||||
|
||||
def __init__(self, context, settings, path, theme, output_path, *null):
|
||||
@ -63,7 +64,6 @@ class SitemapGenerator(object):
|
||||
self.now = datetime.now()
|
||||
self.siteurl = settings.get('SITEURL')
|
||||
|
||||
|
||||
self.default_timezone = settings.get('TIMEZONE', 'UTC')
|
||||
self.timezone = getattr(self, 'timezone', self.default_timezone)
|
||||
self.timezone = timezone(self.timezone)
|
||||
|
Loading…
x
Reference in New Issue
Block a user