Skip to content
Permalink
Browse files

Allowing to override the relative path to the post via language-depen…

…dent post metadata.
  • Loading branch information
felixfontein committed Sep 19, 2016
1 parent fad241e commit b4ed2e6d14bd2bb159700080fc4ebb9f7962068b
Showing with 25 additions and 11 deletions.
  1. +4 −4 nikola/plugins/misc/scan_posts.py
  2. +21 −7 nikola/post.py
@@ -55,8 +55,7 @@ def scan(self):
print(".", end='', file=sys.stderr)
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)
@@ -90,11 +89,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
)
timeline.append(post)

@@ -87,7 +87,8 @@ def __init__(
use_in_feeds,
messages,
template_name,
compiler
compiler,
destination_base=None
):
"""Initialize post.
@@ -120,7 +121,12 @@ 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.folder_relative = destination
self.folder_base = destination_base
if self.folder_base is not None:
self.folder = os.path.normpath(os.path.join(self.folder_base, self.folder_relative))
else:
self.folder = destination
self.translations = self.config['TRANSLATIONS']
self.default_lang = self.config['DEFAULT_LANG']
self.messages = messages
@@ -754,24 +760,29 @@ def remaining_paragraph_count(self):
def source_link(self, lang=None):
"""Return absolute link to the post's source."""
ext = self.source_ext(True)
link = "/" + self.destination_path(lang=lang, extension=ext, sep='/')
link = "/" + self.destination_path(lang=lang, extension=ext, sep='/', _force_source=True)
link = utils.encodelink(link)
return link

def destination_path(self, lang=None, extension='.html', sep=os.sep):
def destination_path(self, lang=None, extension='.html', sep=os.sep, _force_source=False):
"""Destination path for this post, relative to output/.
If lang is not specified, it's the current language.
Extension is used in the path if specified.
"""
if lang is None:
lang = nikola.utils.LocaleBorg().current_lang
folder = self.folder
if not _force_source:
folder = self.meta[lang].get('path', folder)
if self.folder_base is not None:
folder = os.path.normpath(os.path.join(self.folder_base, folder))
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('./'):
@@ -843,7 +854,10 @@ 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)
folder = self.meta[lang].get('path', self.folder)
if self.folder_base is not None:
folder = os.path.normpath(os.path.join(self.folder_base, folder))
pieces += folder.split(os.sep)
if self._has_pretty_url(lang):
pieces += [self.meta[lang]['slug'], 'index' + extension]
else:

0 comments on commit b4ed2e6

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