瀏覽代碼

feat: add `preview_only` option for featured image

Add `preview_only = true` under `[image]` in a page's front matter to
only show featured image in page previews and not on the page itself.

Example: https://raw.githubusercontent.com/gcushen/hugo-academic/master/exampleSite/content/post/getting-started/index.md

Close #789
See #728
George Cushen 6 年之前
父節點
當前提交
d930502a55
共有 2 個文件被更改,包括 6 次插入3 次删除
  1. 3 0
      exampleSite/content/post/getting-started/index.md
  2. 3 3
      layouts/partials/page_header.html

+ 3 - 0
exampleSite/content/post/getting-started/index.md

@@ -30,6 +30,9 @@ summary = "Create a beautifully simple website or blog in under 10 minutes."
   # Options: Smart, Center, TopLeft, Top, TopRight, Left, Right, BottomLeft, Bottom, BottomRight
   focal_point = ""
 
+  # Show image only in page previews?
+  preview_only = false
+
 # Set captions for image gallery.
 
 [[gallery_item]]

+ 3 - 3
layouts/partials/page_header.html

@@ -29,14 +29,14 @@
 {{end}}
 
 {{/* Featured image */}}
-{{ with $featured }}
-{{ $image := .Fill (printf "1600x400 q90 %s" $anchor) }}
+{{ if and $featured (not $.Params.image.preview_only) }}
+{{ $image := $featured.Fill (printf "1600x400 q90 %s" $anchor) }}
 <div class="article-header d-xl-none">
   <img src="{{ $image.RelPermalink }}" class="article-banner" itemprop="image" alt="">
   {{ with $.Params.image.caption }}<span class="article-header-caption">{{ . | markdownify | emojify }}</span>{{ end }}
 </div>
 
-{{ $image := .Fill (printf "680x500 q90 %s" $anchor) }}
+{{ $image := $featured.Fill (printf "680x500 q90 %s" $anchor) }}
 <div class="container-fluid split-header d-none d-xl-block">
   <div class="row">
     <div class="col-6">