Skip to content

Commit

Permalink
Merge pull request #3475 from getnikola/fix-3471-previewimage-absolute
Browse files Browse the repository at this point in the history
Fix #3471 — fix previewimages for non-server-root sites
  • Loading branch information
Kwpolska authored Nov 13, 2020
2 parents ebad7f2 + 83618d8 commit 60e38f8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Features
Bugfixes
--------

* Fix previewimages (post- and root-relative) in bootblog4/galleries
featured posts for non-server-root sites (Issue #3471)
* Windows: Also fix symlinks when installing from source with pip; if possible,
enable Developer Mode and run ``git config --global core.symlinks true``
before cloning the Nikola repo
Expand Down
2 changes: 1 addition & 1 deletion nikola/data/themes/base/templates/gallery.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div class="thumnbnail-container">
<a href="${folder}" class="thumbnail image-reference" title="${ftitle|h}">
% if fpost and fpost.previewimage:
<img src="${url_replacer(fpost.permalink(), fpost.previewimage, lang, 'full_path')}" alt="${ftitle|h}" loading="lazy" style="max-width:${thumbnail_size}px; max-height:${thumbnail_size}px;" />
<img src="${fpost.previewimage}" alt="${ftitle|h}" loading="lazy" style="max-width:${thumbnail_size}px; max-height:${thumbnail_size}px;" />
% else:
<div style="height: ${thumbnail_size}px; width: ${thumbnail_size}px; background-color: #eee;"></div>
% endif
Expand Down
6 changes: 3 additions & 3 deletions nikola/data/themes/bootblog4/templates/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
% else:
<div class="col-md-6 p-0 h-md-250 text-right d-none d-md-block">
% endif
<img class="bootblog4-featured-large-image" src="${url_replacer(featured[0].permalink(), featured[0].previewimage, lang, 'full_path')}" alt="${featured.pop(0).title()}">
<img class="bootblog4-featured-large-image" src="${featured[0].previewimage}" alt="${featured.pop(0).title()}">
</div>
% else:
<div class="lead my-3 mb-0">${featured.pop(0).text(teaser_only=True, strip_html=theme_config.get('featured_strip_html', True))}</div>
Expand All @@ -117,7 +117,7 @@
% if featured[0].previewimage:
<div class="card-text mb-auto bootblog4-featured-text">${featured[0].text(teaser_only=True, strip_html=theme_config.get('featured_strip_html', True))}</div>
</div>
<img class="card-img-right flex-auto d-none d-lg-block" src="${url_replacer(featured[0].permalink(), featured[0].previewimage, lang, 'full_path')}" alt="${featured.pop(0).title()}">
<img class="card-img-right flex-auto d-none d-lg-block" src="${featured[0].previewimage}" alt="${featured.pop(0).title()}">
% else:
<div class="card-text mb-auto bootblog4-featured-text">${featured.pop(0).text(teaser_only=True, strip_html=theme_config.get('featured_strip_html', True))}</div>
</div>
Expand All @@ -135,7 +135,7 @@
% if featured[0].previewimage:
<div class="card-text mb-auto bootblog4-featured-text">${featured[0].text(teaser_only=True, strip_html=theme_config.get('featured_strip_html', True))}</div>
</div>
<img class="card-img-right flex-auto d-none d-lg-block" src="${url_replacer(featured[0].permalink(), featured[0].previewimage, lang, 'full_path')}" alt="${featured.pop(0).title()}">
<img class="card-img-right flex-auto d-none d-lg-block" src="${featured[0].previewimage}" alt="${featured.pop(0).title()}">
% else:
<div class="card-text mb-auto bootblog4-featured-text">${featured.pop(0).text(teaser_only=True, strip_html=theme_config.get('featured_strip_html', True))}</div>
</div>
Expand Down
10 changes: 6 additions & 4 deletions nikola/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,11 +1085,13 @@ def previewimage(self, lang=None):

image_path = self.meta[lang]['previewimage']
if not image_path:
return self._default_preview_image
image_path = self._default_preview_image

# This is further parsed by the template, because we don’t have access
# to the URL replacer here. (Issue #1473)
return image_path
if not image_path or image_path.startswith("/"):
# Paths starting with slashes are expected to be root-relative, pass them directly.
return image_path
# Other paths are relative to the permalink. The path will be made prettier by the URL replacer later.
return urljoin(self.permalink(lang), image_path)

def source_ext(self, prefix=False):
"""Return the source file extension.
Expand Down

0 comments on commit 60e38f8

Please sign in to comment.