Accomodate renaming of filenames to static_content in generator context

This commit is contained in:
Oliver Urs Lenz 2018-11-24 20:56:58 +01:00
parent 6b31a491f3
commit b5cde0aff5

View File

@ -12,6 +12,9 @@ import posixpath
from copy import copy from copy import copy
from itertools import chain from itertools import chain
from operator import attrgetter from operator import attrgetter
try:
from collections.abc import OrderedDict
except ImportError:
from collections import OrderedDict from collections import OrderedDict
from contextlib import contextmanager from contextlib import contextmanager
from six.moves.urllib.parse import urlparse from six.moves.urllib.parse import urlparse
@ -356,12 +359,18 @@ def interlink_static_files(generator):
'''Add links to static files in the main site if necessary''' '''Add links to static files in the main site if necessary'''
if generator.settings['STATIC_PATHS'] != []: if generator.settings['STATIC_PATHS'] != []:
return # customized STATIC_PATHS return # customized STATIC_PATHS
filenames = generator.context['filenames'] # minimize attr lookup try: # minimize attr lookup
static_content = generator.context['static_content']
except KeyError:
static_content = generator.context['filenames']
relpath = relpath_to_site(generator.settings['DEFAULT_LANG'], _MAIN_LANG) relpath = relpath_to_site(generator.settings['DEFAULT_LANG'], _MAIN_LANG)
for staticfile in _MAIN_STATIC_FILES: for staticfile in _MAIN_STATIC_FILES:
if staticfile.get_relative_source_path() not in filenames: if staticfile.get_relative_source_path() not in static_content:
staticfile = copy(staticfile) # prevent override in main site staticfile = copy(staticfile) # prevent override in main site
staticfile.override_url = posixpath.join(relpath, staticfile.url) staticfile.override_url = posixpath.join(relpath, staticfile.url)
try:
generator.add_source_path(staticfile, static=True)
except TypeError:
generator.add_source_path(staticfile) generator.add_source_path(staticfile)