Skip to content
Permalink
Browse files

Computing paths once.

  • Loading branch information...
felixfontein committed Sep 26, 2016
1 parent e05e806 commit 14ba726759022ca4dfc36e6189772d80b543929b
Showing with 10 additions and 16 deletions.
  1. +10 −16 nikola/post.py
@@ -124,12 +124,6 @@ def __init__(
self.folder_relative = destination
self.folder_base = destination_base
self.default_lang = self.config['DEFAULT_LANG']
if self.folder_base is None:
self.folder = destination
elif isinstance(self.folder_base, (utils.bytes_str, utils.unicode_str)):
self.folder = os.path.normpath(os.path.join(self.folder_base, self.folder_relative))
else:
self.folder = os.path.normpath(os.path.join(self.folder_base(self.default_lang), self.folder_relative))
self.translations = self.config['TRANSLATIONS']
self.messages = messages
self.skip_untranslated = not self.config['SHOW_UNTRANSLATED_POSTS']
@@ -169,6 +163,14 @@ def __init__(
for lang in sorted(self.translated_to):
default_metadata.update(self.meta[lang])

# Find paths from metadata
self.folders = {lang: self.meta[lang].get('path', self.folder_relative) for lang in self.config['TRANSLATIONS'].keys()}
if isinstance(self.folder_base, (utils.bytes_str, utils.unicode_str)):
self.folders = {lang: os.path.normpath(os.path.join(self.folder_base, folder)) for lang, folder in self.folders.items()}
elif self.folder_base is not None:
self.folders = {lang: os.path.normpath(os.path.join(self.folder_base(lang), folder)) for lang, folder in self.folders.items()}
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:
@@ -774,11 +776,7 @@ def destination_path(self, lang=None, extension='.html', sep=os.sep):
"""
if lang is None:
lang = nikola.utils.LocaleBorg().current_lang
folder = self.meta[lang].get('path', self.folder_relative)
if isinstance(self.folder_base, (utils.bytes_str, utils.unicode_str)):
folder = os.path.normpath(os.path.join(self.folder_base, folder))
elif self.folder_base is not None:
folder = os.path.normpath(os.path.join(self.folder_base(lang), folder))
folder = self.folders[lang]
if self._has_pretty_url(lang):
path = os.path.join(self.translations[lang],
folder, self.meta[lang]['slug'], 'index' + extension)
@@ -856,11 +854,7 @@ def permalink(self, lang=None, absolute=False, extension='.html', query=None):
extension = self.compiler.extension()

pieces = self.translations[lang].split(os.sep)
folder = self.meta[lang].get('path', self.folder_relative)
if isinstance(self.folder_base, (utils.bytes_str, utils.unicode_str)):
folder = os.path.normpath(os.path.join(self.folder_base, folder))
elif self.folder_base is not None:
folder = os.path.normpath(os.path.join(self.folder_base(lang), folder))
folder = self.folders[lang]
pieces += folder.split(os.sep)
if self._has_pretty_url(lang):
pieces += [self.meta[lang]['slug'], 'index' + extension]

0 comments on commit 14ba726

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