Skip to content

Commit

Permalink
posts: Add featured image option and stream layout for widget
Browse files Browse the repository at this point in the history
To use:

1. Set `list_format = 2` in `content/home/posts.md`
2. Refactor a post named `X.md` to `content/post/X/index.md`
3. Add an image named `featured.*` to your post's new folder
  • Loading branch information
gcushen committed Sep 30, 2018
1 parent bfae051 commit 0cd9c1d
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 7 deletions.
4 changes: 2 additions & 2 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ enableGitInfo = false

gravatar = false # Get your avatar from Gravatar.com? (true/false)
avatar = "portrait.jpg" # Specify an avatar image (in `static/img/` folder) or delete value to disable avatar.

# Details for the Contact Widget
email = "test@example.org"
address = "Building 1 Room 1, Stanford University, California, 90210, USA"
Expand Down Expand Up @@ -107,7 +107,7 @@ enableGitInfo = false

# Description for social sharing and search engines. If undefined, author role is used in place.
description = ""

# Default image for social sharing and search engines. Place image in `static/img/` folder and specify image name here.
sharing_image = ""

Expand Down
3 changes: 2 additions & 1 deletion exampleSite/content/home/posts.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ count = 5
# List format.
# 0 = Simple
# 1 = Detailed
list_format = 1
# 2 = Stream
list_format = 2
+++

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ tags = ["Academic"]
summary = "Create a beautifully simple website or blog in under 10 minutes."

[header]
image = "headers/getting-started.png"
caption = "Image credit: [**Academic**](https://github.com/gcushen/hugo-academic/)"
caption = "Image credit: [**Unsplash**](https://unsplash.com/photos/CpkOjOcXdUY)"

[[gallery_item]]
album = "1"
Expand Down
Binary file removed exampleSite/static/img/headers/getting-started.png
Binary file not shown.
33 changes: 33 additions & 0 deletions layouts/partials/css/academic.css
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,39 @@ article .article-metadata {
padding-top: 1rem;
}

/*************************************************
* Stream
**************************************************/

.media.stream-item {
margin-bottom: 2rem;
}

.media.stream-item .article-title {
font-size: 1.2rem;
}

.media.stream-item .article-style {
margin-top: 2px;
font-size: 0.8rem;
}

.media.stream-item .stream-meta {
margin-top: 12px;
}

.media.stream-item img {
max-width: 150px;
height: auto;
object-fit: cover;
}

@media screen and (max-width: 768px) {
.media.stream-item img {
max-width: 80px;
}
}

/*************************************************
* Publications
**************************************************/
Expand Down
11 changes: 10 additions & 1 deletion layouts/partials/header_image.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{{ if .Params.header.image }}
{{ $featured := (.Resources.ByType "image").GetMatch "*featured*" }}
{{ with $featured }}
{{ $image := .Fill "1600x400" }}
<div class="article-header">
<img src="{{ $image.RelPermalink }}" class="article-banner" itemprop="image" style="width: 100%; min-height: 400px; height: auto;">
{{ with $.Params.header.caption }}<span class="article-header-caption">{{ . | markdownify | emojify }}</span>{{ end }}
</div>
{{end}}

{{ if and .Params.header.image (not $featured) }}
<div class="article-header">
{{ $img_src := urls.Parse .Params.header.image }}
{{ if $img_src.Scheme }}
Expand Down
36 changes: 36 additions & 0 deletions layouts/partials/post_li_stream.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{{ $post := .post }}

<div class="media stream-item" itemscope itemprop="blogPost" itemtype="http://schema.org/BlogPosting">
<div class="media-body">

<h3 class="article-title mb-0 mt-0" itemprop="headline">
<a href="{{ $post.RelPermalink }}" itemprop="url">{{ $post.Title }}</a>
</h3>

{{ $summary := "" }}
{{ if $post.Params.summary }}
{{ $summary = $post.Params.summary | markdownify }}
{{ else if $post.Truncated }}
{{ $summary = $post.Summary }}
{{ end }}
{{ with $summary }}
<div class="article-style" itemprop="articleBody">
{{ . | truncate 135 }}
</div>
{{ end }}

<div class="stream-meta">
{{ partial "article_metadata" (dict "content" $post "is_list" 1) }}
</div>

</div>
<div class="ml-3">
{{ $resource := ($post.Resources.ByType "image").GetMatch "*featured*" }}
{{ with $resource }}
{{ $image := .Resize "150x" }}
<a href="{{ $post.RelPermalink }}">
<img src="{{ $image.RelPermalink }}" itemprop="image">
</a>
{{end}}
</div>
</div>
4 changes: 3 additions & 1 deletion layouts/partials/widgets/posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ <h1>{{ with $page.Title }}{{ . | markdownify }}{{ end }}</h1>
{{ $params := dict "post" . }}
{{ if eq $page.Params.list_format 0 }}
{{ partial "post_li_simple" $params }}
{{ else }}
{{ else if eq $page.Params.list_format 1 }}
{{ partial "post_li_detailed" $params }}
{{ else }}
{{ partial "post_li_stream" $params }}
{{ end }}
{{end}}

Expand Down

0 comments on commit 0cd9c1d

Please sign in to comment.