fix i18n_subsites with pelican 4.0.0
This commit is contained in:
parent
b49d21c984
commit
08d9b22103
@ -12,10 +12,7 @@ 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 import OrderedDict
|
||||||
from collections.abc import OrderedDict
|
|
||||||
except ImportError:
|
|
||||||
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
|
||||||
|
|
||||||
@ -25,10 +22,7 @@ import locale
|
|||||||
from pelican import signals
|
from pelican import signals
|
||||||
from pelican.generators import ArticlesGenerator, PagesGenerator
|
from pelican.generators import ArticlesGenerator, PagesGenerator
|
||||||
from pelican.settings import configure_settings
|
from pelican.settings import configure_settings
|
||||||
try:
|
from pelican.contents import Article
|
||||||
from pelican.contents import Draft
|
|
||||||
except ImportError:
|
|
||||||
from pelican.contents import Article as Draft
|
|
||||||
|
|
||||||
|
|
||||||
# Global vars
|
# Global vars
|
||||||
@ -98,8 +92,9 @@ def prepare_site_db_and_overrides():
|
|||||||
_MAIN_SETTINGS['CACHE_PATH'], lang)
|
_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'])
|
||||||
@ -157,8 +152,8 @@ def save_generator(generator):
|
|||||||
|
|
||||||
|
|
||||||
def article2draft(article):
|
def article2draft(article):
|
||||||
'''Transform an Article to Draft'''
|
'''Set to draft the status of an article'''
|
||||||
draft = Draft(article._content, article.metadata, article.settings,
|
draft = Article(article._content, article.metadata, article.settings,
|
||||||
article.source_path, article._context)
|
article.source_path, article._context)
|
||||||
draft.status = 'draft'
|
draft.status = 'draft'
|
||||||
return draft
|
return draft
|
||||||
@ -254,10 +249,8 @@ def filter_contents_translations(generator):
|
|||||||
hiding_func = inspector.hiding_function()
|
hiding_func = inspector.hiding_function()
|
||||||
untrans_policy = inspector.untranslated_policy(default='hide')
|
untrans_policy = inspector.untranslated_policy(default='hide')
|
||||||
for (contents, other_contents) in inspector.contents_list_pairs():
|
for (contents, other_contents) in inspector.contents_list_pairs():
|
||||||
# save any hidden native content first
|
for content in other_contents: # save any hidden native content first
|
||||||
for content in other_contents:
|
if content.lang == current_lang: # in native lang
|
||||||
# in native lang
|
|
||||||
if content.lang == current_lang:
|
|
||||||
# save the native URL attr formatted in the current locale
|
# save the native URL attr formatted in the current locale
|
||||||
_NATIVE_CONTENT_URL_DB[content.source_path] = content.url
|
_NATIVE_CONTENT_URL_DB[content.source_path] = content.url
|
||||||
# copy for removing in loop
|
# copy for removing in loop
|
||||||
@ -367,18 +360,16 @@ def interlink_static_files(generator):
|
|||||||
return
|
return
|
||||||
# minimize attr lookup
|
# minimize attr lookup
|
||||||
try:
|
try:
|
||||||
static_content = generator.context['static_content']
|
filenames = generator.context['static_content']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
static_content = generator.context['filenames']
|
filenames = generator.context['filenames']
|
||||||
|
return # customized STATIC_PATHS
|
||||||
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 static_content:
|
if staticfile.get_relative_source_path() not in filenames:
|
||||||
# prevent override in main site
|
# prevent override in main site
|
||||||
staticfile = copy(staticfile)
|
staticfile = copy(staticfile)
|
||||||
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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ with local development when ``SITEURL == ''``.
|
|||||||
Language buttons showing all available languages, current is active
|
Language buttons showing all available languages, current is active
|
||||||
...................................................................
|
...................................................................
|
||||||
|
|
||||||
The ``extra_siteurls`` dictionary is a mapping of all languages to the
|
The ``lang_subsites`` dictionary is a mapping of all languages to the
|
||||||
``SITEURL`` of the respective (sub-)sites. This template sets the
|
``SITEURL`` of the respective (sub-)sites. This template sets the
|
||||||
language of the current (sub-)site as active.
|
language of the current (sub-)site as active.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user