This commit is contained in:
Jesús 2020-02-04 21:03:27 -05:00
parent 8ce1426785
commit edcc28d056
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766
8 changed files with 68 additions and 50 deletions

View File

@ -4,8 +4,6 @@ css-js-minify wrapper for Pelican
""" """
import glob import glob
import os
import sys
from .minify import ( from .minify import (
process_single_css_file, process_single_css_file,
@ -17,6 +15,7 @@ from pelican import signals
CSS_DIR = '/theme/css' CSS_DIR = '/theme/css'
JS_DIR = '/theme/js' JS_DIR = '/theme/js'
def main(pelican): def main(pelican):
""" Compiler """ """ Compiler """
for file in glob.iglob(pelican.output_path + CSS_DIR + '/**/*.css', recursive=True): 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): for file in glob.iglob(pelican.output_path + JS_DIR + '/**/*.js', recursive=True):
process_single_js_file(file, overwrite=True) process_single_js_file(file, overwrite=True)
def register(): def register():
""" Register """ """ Register """
signals.finalized.connect(main) signals.finalized.connect(main)
SUPPORT_JS = """ SUPPORT_JS = """
----------------------------------------------------------------- -----------------------------------------------------------------
COMPRESSOR: COMPRESSOR:

View File

@ -32,6 +32,7 @@ color = {
'green': '\033[1;32m' 'green': '\033[1;32m'
} }
def process_multiple_files(file_path, watch=False, wrap=False, timestamp=False, def process_multiple_files(file_path, watch=False, wrap=False, timestamp=False,
comments=False, sort=False, overwrite=False, comments=False, sort=False, overwrite=False,
zipy=False, prefix='', add_hash=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, zipy=False, prefix='', add_hash=False,
output_path=None): output_path=None):
"""Process a single CSS file.""" """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: with open(css_file_path, encoding="utf-8") as css_file:
original_css = css_file.read() 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, def process_single_js_file(js_file_path, timestamp=False, overwrite=False,
zipy=False, output_path=None): zipy=False, output_path=None):
"""Process a single JS file.""" """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: with open(js_file_path, encoding="utf-8") as js_file:
original_js = js_file.read() original_js = js_file.read()
print("INPUT: Reading JS file %s" % js_file_path) 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. 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. CSS Properties are Alpha-Sorted, to help spot cloned ones, Selectors not.
Watch works for whole folders, with minimum of ~60 Secs between runs.""") 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, parser.add_argument('fullpath', metavar='fullpath', type=str,
help='Full path to local file or folder.') help='Full path to local file or folder.')
parser.add_argument('--wrap', action='store_true', parser.add_argument('--wrap', action='store_true',

View File

@ -35,7 +35,7 @@ except ImportError:
_MAIN_SETTINGS = None # settings dict of the main Pelican instance _MAIN_SETTINGS = None # settings dict of the main Pelican instance
_MAIN_LANG = None # lang of the main Pelican instance _MAIN_LANG = None # lang of the main Pelican instance
_MAIN_SITEURL = None # siteurl 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 _SUBSITE_QUEUE = {} # map: lang -> settings overrides
_SITE_DB = OrderedDict() # OrderedDict: lang -> siteurl _SITE_DB = OrderedDict() # OrderedDict: lang -> siteurl
_SITES_RELPATH_DB = {} # map: (lang, base_lang) -> relpath _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.keys() need to be ready for filter_translations
''' '''
_SITE_DB.clear() _SITE_DB.clear()
_SITE_DB[_MAIN_LANG] = _MAIN_SITEURL _SITE_DB[_MAIN_LANG] = _MAIN_SITEURL
# make sure it works for both root-relative and absolute # 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: if 'SITEURL' not in overrides:
overrides['SITEURL'] = posixpath.join(main_siteurl, lang) overrides['SITEURL'] = posixpath.join(main_siteurl, lang)
_SITE_DB[lang] = overrides['SITEURL'] _SITE_DB[lang] = overrides['SITEURL']
# default subsite hierarchy # default subsite hierarchy
if 'OUTPUT_PATH' not in overrides: if 'OUTPUT_PATH' not in overrides:
overrides['OUTPUT_PATH'] = os.path.join( overrides['OUTPUT_PATH'] = \
_MAIN_SETTINGS['OUTPUT_PATH'], lang) os.path.join(_MAIN_SETTINGS['OUTPUT_PATH'], lang)
if 'CACHE_PATH' not in overrides: if 'CACHE_PATH' not in overrides:
overrides['CACHE_PATH'] = os.path.join( overrides['CACHE_PATH'] = \
_MAIN_SETTINGS['CACHE_PATH'], lang) os.path.join(_MAIN_SETTINGS['CACHE_PATH'], lang)
if 'STATIC_PATHS' not in overrides: if 'STATIC_PATHS' not in overrides:
overrides['STATIC_PATHS'] = [] overrides['STATIC_PATHS'] = []
if ('THEME' not in overrides and 'THEME_STATIC_DIR' not in overrides and if 'THEME' not in overrides and 'THEME_STATIC_DIR' \
'THEME_STATIC_PATHS' not in overrides): not in overrides and 'THEME_STATIC_PATHS' not in overrides:
relpath = relpath_to_site(lang, _MAIN_LANG) relpath = relpath_to_site(lang, _MAIN_LANG)
overrides['THEME_STATIC_DIR'] = posixpath.join( overrides['THEME_STATIC_DIR'] = posixpath.join(
relpath, _MAIN_SETTINGS['THEME_STATIC_DIR']) relpath, _MAIN_SETTINGS['THEME_STATIC_DIR'])
overrides['THEME_STATIC_PATHS'] = [] overrides['THEME_STATIC_PATHS'] = []
# to change what is perceived as translations # to change what is perceived as translations
overrides['DEFAULT_LANG'] = lang overrides['DEFAULT_LANG'] = lang

View File

@ -8,6 +8,7 @@ variables to the article's context
""" """
from pelican import signals from pelican import signals
def iter3(seq): def iter3(seq):
it = iter(seq) it = iter(seq)
nxt = None nxt = None
@ -17,6 +18,7 @@ def iter3(seq):
nxt, cur = cur, prv nxt, cur = cur, prv
yield nxt, cur, None yield nxt, cur, None
def get_translation(article, prefered_language): def get_translation(article, prefered_language):
if not article: if not article:
return None return None
@ -25,18 +27,16 @@ def get_translation(article, prefered_language):
return translation return translation
return article return article
def set_neighbors(articles, next_name, prev_name): def set_neighbors(articles, next_name, prev_name):
for nxt, cur, prv in iter3(articles): for nxt, cur, prv in iter3(articles):
exec("cur.{} = nxt".format(next_name)) exec("cur.{} = nxt".format(next_name))
exec("cur.{} = prv".format(prev_name)) exec("cur.{} = prv".format(prev_name))
for translation in cur.translations: for translation in cur.translations:
exec( exec("translation.{} = get_translation(nxt, translation.lang)".format(next_name))
"translation.{} = get_translation(nxt, translation.lang)".format( exec("translation.{} = get_translation(prv, translation.lang)".format(prev_name))
next_name))
exec(
"translation.{} = get_translation(prv, translation.lang)".format(
prev_name))
def neighbors(generator): def neighbors(generator):
set_neighbors(generator.articles, 'next_article', 'prev_article') set_neighbors(generator.articles, 'next_article', 'prev_article')
@ -54,5 +54,6 @@ def neighbors(generator):
prev_name = 'prev_article_in_subcategory{}'.format(index) prev_name = 'prev_article_in_subcategory{}'.format(index)
set_neighbors(articles, next_name, prev_name) set_neighbors(articles, next_name, prev_name)
def register(): def register():
signals.article_generator_finalized.connect(neighbors) signals.article_generator_finalized.connect(neighbors)

View File

@ -10,6 +10,7 @@ import shutil
from pelican import signals from pelican import signals
def copy_resources(src, dest, file_list): def copy_resources(src, dest, file_list):
""" """
Copy files from content folder to output folder 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_) file_src = os.path.join(src, file_)
shutil.copy2(file_src, dest) shutil.copy2(file_src, dest)
def add_files(gen, metadata): def add_files(gen, metadata):
""" """
The registered handler for the dynamic resources plugin. It will The registered handler for the dynamic resources plugin. It will
@ -59,6 +61,7 @@ def add_files(gen, metadata):
htmls.append(html) htmls.append(html)
metadata[key] = htmls metadata[key] = htmls
def move_resources(gen): def move_resources(gen):
""" """
Move files from js/css folders to output folder Move files from js/css folders to output folder

View File

@ -54,6 +54,7 @@ def format_date(date):
tz = "-00:00" tz = "-00:00"
return date.strftime("%Y-%m-%dT%H:%M:%S") + tz return date.strftime("%Y-%m-%dT%H:%M:%S") + tz
class SitemapGenerator(object): class SitemapGenerator(object):
def __init__(self, context, settings, path, theme, output_path, *null): def __init__(self, context, settings, path, theme, output_path, *null):
@ -63,7 +64,6 @@ class SitemapGenerator(object):
self.now = datetime.now() self.now = datetime.now()
self.siteurl = settings.get('SITEURL') self.siteurl = settings.get('SITEURL')
self.default_timezone = settings.get('TIMEZONE', 'UTC') self.default_timezone = settings.get('TIMEZONE', 'UTC')
self.timezone = getattr(self, 'timezone', self.default_timezone) self.timezone = getattr(self, 'timezone', self.default_timezone)
self.timezone = timezone(self.timezone) self.timezone = timezone(self.timezone)