Skip to content
Permalink
Browse files

Merge branch 'master' into new-compile-function

  • Loading branch information
felixfontein committed Oct 14, 2016
2 parents ce2f510 + 3fae233 commit bd7390b658497c11957877d8c0cbfec31a97ef9b
Showing with 52 additions and 10 deletions.
  1. +2 −0 CHANGES.txt
  2. +14 −0 docs/manual.txt
  3. +7 −0 nikola/conf.py.in
  4. +5 −4 nikola/plugins/misc/scan_posts.py
  5. +24 −6 nikola/post.py
@@ -7,6 +7,8 @@ Bugfixes
Features
--------

* The destination folder in ``POSTS`` and ``PAGES`` can now be
translated (Issue #2116)
* Pass ``post`` object and ``lang`` to post compilers (Issue #2531)

New in v7.8.1
@@ -461,6 +461,14 @@ default set to:
Nikola will only look for translation of input files for languages
specified in the TRANSLATIONS variable.

In case you translate your posts, you might also want to adjust various
other settings so that the generated URLs match the translation. You can
find most places in `conf.py` by searching for `(translatable)`. For example,
you might want to localize `/categories/` (search for `TAG_PATH`), `/pages/`
and `/posts/` (search for `POSTS` and `PAGES`, or see the next section), or
how to adjust the URLs for subsequent pages for indexes (search for
`INDEXES_PRETTY_PAGE_URL`).

Nikola supports multiple languages for a post (we have almost 50 translations!). If you wish to
add support for more languages, check out `the Transifex page for Nikola <https://www.transifex.com/projects/p/nikola/>`_

@@ -501,6 +509,12 @@ options. The exact mechanism is explained above the config options in the
# to feeds, indexes, tag lists and archives and are considered part
# of a blog, while PAGES are just independent HTML pages.
#
# Finally, note that destination can be translated, i.e. you can
# specify a different translation folder per language. Example:
# PAGES = (
# ("pages/*.rst", {"en": "pages", "de": "seiten"}, "story.tmpl"),
# ("pages/*.md", {"en": "pages", "de": "seiten"}, "story.tmpl"),
# )

POSTS = (
("posts/*.rst", "posts", "post.tmpl"),
@@ -94,6 +94,7 @@ THEME = ${THEME}
THEME_COLOR = '#5670d4'

# POSTS and PAGES contains (wildcard, destination, template) tuples.
# (translatable)
#
# The wildcard is used to generate a list of source files
# (whatever/thing.rst, for example).
@@ -119,6 +120,12 @@ THEME_COLOR = '#5670d4'
# to feeds, indexes, tag lists and archives and are considered part
# of a blog, while PAGES are just independent HTML pages.
#
# Finally, note that destination can be translated, i.e. you can
# specify a different translation folder per language. Example:
# PAGES = (
# ("pages/*.rst", {"en": "pages", "de": "seiten"}, "story.tmpl"),
# ("pages/*.md", {"en": "pages", "de": "seiten"}, "story.tmpl"),
# )

POSTS = ${POSTS}
PAGES = ${PAGES}
@@ -55,10 +55,10 @@ def scan(self):
self.site.config['post_pages']:
if not self.site.quiet:
print(".", end='', file=sys.stderr)
destination_translatable = utils.TranslatableSetting('destination', destination, self.site.config['TRANSLATIONS'])
dirname = os.path.dirname(wildcard)
for dirpath, _, _ in os.walk(dirname, followlinks=True):
dest_dir = os.path.normpath(os.path.join(destination,
os.path.relpath(dirpath, dirname))) # output/destination/foo/
rel_dest_dir = os.path.relpath(dirpath, dirname)
# Get all the untranslated paths
dir_glob = os.path.join(dirpath, os.path.basename(wildcard)) # posts/foo/*.rst
untranslated = glob.glob(dir_glob)
@@ -93,11 +93,12 @@ def scan(self):
post = Post(
base_path,
self.site.config,
dest_dir,
rel_dest_dir,
use_in_feeds,
self.site.MESSAGES,
template_name,
self.site.get_compiler(base_path)
self.site.get_compiler(base_path),
destination_base=destination_translatable
)
timeline.append(post)
except Exception as err:
@@ -87,13 +87,17 @@ def __init__(
use_in_feeds,
messages,
template_name,
compiler
compiler,
destination_base=None
):
"""Initialize post.
The source path is the user created post file. From it we calculate
the meta file, as well as any translations available, and
the .html fragment file path.
destination_base must be None or a TranslatableSetting instance. If
specified, it will be prepended to the destination path.
"""
self.config = config
self.compiler = compiler
@@ -120,9 +124,10 @@ def __init__(
# cache/posts/blah.html
self._base_path = self.base_path.replace('\\', '/')
self.metadata_path = self.post_name + ".meta" # posts/blah.meta
self.folder = destination
self.translations = self.config['TRANSLATIONS']
self.folder_relative = destination
self.folder_base = destination_base
self.default_lang = self.config['DEFAULT_LANG']
self.translations = self.config['TRANSLATIONS']
self.messages = messages
self.skip_untranslated = not self.config['SHOW_UNTRANSLATED_POSTS']
self._template_name = template_name
@@ -161,6 +166,18 @@ def __init__(
for lang in sorted(self.translated_to):
default_metadata.update(self.meta[lang])

# Compose paths
if self.folder_base is not None:
# Use translatable destination folders
self.folders = {}
for lang in self.config['TRANSLATIONS'].keys():
self.folders[lang] = os.path.normpath(os.path.join(
self.folder_base(lang), self.folder_relative))
else:
# Old behavior (non-translatable destination path, normalized by scanner)
self.folders = {lang: self.folder_relative for lang in self.config['TRANSLATIONS'].keys()}
self.folder = self.folders[self.default_lang]

# Load data field from metadata
self.data = Functionary(lambda: None, self.default_lang)
for lang in self.translations:
@@ -770,12 +787,13 @@ def destination_path(self, lang=None, extension='.html', sep=os.sep):
"""
if lang is None:
lang = nikola.utils.LocaleBorg().current_lang
folder = self.folders[lang]
if self._has_pretty_url(lang):
path = os.path.join(self.translations[lang],
self.folder, self.meta[lang]['slug'], 'index' + extension)
folder, self.meta[lang]['slug'], 'index' + extension)
else:
path = os.path.join(self.translations[lang],
self.folder, self.meta[lang]['slug'] + extension)
folder, self.meta[lang]['slug'] + extension)
if sep != os.sep:
path = path.replace(os.sep, sep)
if path.startswith('./'):
@@ -847,7 +865,7 @@ def permalink(self, lang=None, absolute=False, extension='.html', query=None):
extension = self.compiler.extension()

pieces = self.translations[lang].split(os.sep)
pieces += self.folder.split(os.sep)
pieces += self.folders[lang].split(os.sep)
if self._has_pretty_url(lang):
pieces += [self.meta[lang]['slug'], 'index' + extension]
else:

0 comments on commit bd7390b

Please sign in to comment.
You can’t perform that action at this time.