Skip to content

Commit

Permalink
Allow dynamic images on each blog post (daattali#143)
Browse files Browse the repository at this point in the history
* Allow dynamic images on each blog post

* Adding responsive CSS for blog post images

* Adding image parameter to YAML front matter
  • Loading branch information
bryanbritten authored and daattali committed Dec 24, 2016
1 parent 33c5ffa commit 66bd2ad
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ subtitle | Short description of page or blog post that goes under the title
bigimg | Include a large full-width image at the top of the page. You can either give the path to a single image, or provide a list of images to cycle through (see [my personal website](http://deanattali.com/) as an example).
comments | If you want do add Disqus comments to a specific page, use `comments: true`. Comments are automatically enabled on blog posts; to turn comments off for a specific post, use `comments: false`. Comments only work if you set your Disqus id in the `_config.yml` file.
show-avatar | If you have an avatar configured in the `_config.yml` but you want to turn it off on a specific page, use `show-avatar: false`. If you want to turn it off by default, locate the line `show-avatar: true` in the file `_config.yml` and change the `true` to `false`; then you can selectively turn it on in specific pages using `show-avatar: true`.
image | If you want to add a personalized image to your blog post that will show up next to the post's excerpt and on the post itself, use `image: /img/some_image.jpeg` where `some_image.jpeg` is replaced by the name of the image you would like to use.
share-img | If you want to specify an image to use when sharing the page on Facebook or Twitter, then provide the image's full URL here.
social-share | If you don't want to show buttons to share a blog post on social media, use `social-share: false` (this feature is turned on by default).
layout | What type of page this is (default is `blog` for blog posts and `page` for other pages. You can use `minimal` if you don't want a header and footer)
Expand Down
7 changes: 7 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ prose:
help: "Enter date of post."
placeholder: "yyyy-mm-dd"
alterable: true
- name: "image"
field:
element: "text"
label: "Image"
help: "Add a thumbnail image to your post."
placeholder: "Thumbnail"
alterable: true
- name: "published"
field:
element: "checkbox"
Expand Down
10 changes: 9 additions & 1 deletion _includes/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@
</ul>
</div>

{% if site.avatar and (layout.show-avatar or page.show-avatar) %}
{% if page.image and (layout.show-avatar or page.show-avatar) %}
<div class="avatar-container">
<div class="avatar-img-border">
<a href="{{ site.url }} ">
<img class="avatar-img" src="{{ page.image | prepend: site.baseurl | replace: '//', '/' }}" />
</a>
</div>
</div>
{% elsif site.avatar and (layout.show-avatar or page.show-avatar) %}
<div class="avatar-container">
<div class="avatar-img-border">
<a href="{{ site.url }} ">
Expand Down
1 change: 1 addition & 0 deletions _posts/2015-01-04-first-post.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
layout: post
title: First post!
image: /img/hello_world.jpeg
tags: [random, exciting-stuff]
---

Expand Down
35 changes: 35 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,28 @@ footer .theme-by {
.post-preview .post-entry {
font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.post-entry-container {
display: inline-block;
width: 100%;
}
.post-entry {
width: 100%;
}
.post-image {
float: right;
height: 192px;
width: 192px;
margin-top: -35px;
filter: grayscale(90%);
}
.post-image:hover {
filter: grayscale(0%);
}
.post-image img {
border-radius: 100px;
height: 192px;
width: 192px;
}
.post-preview .post-read-more {
font-weight: 800;
}
Expand Down Expand Up @@ -382,6 +404,19 @@ footer .theme-by {
}
}

@media only screen and (max-width: 500px) {
.post-image, .post-image img {
height: 100px;
width: 100px;
}

.post-image {
width: 100%;
text-align: center;
margin-top: 0;
float: left;
}
}
/* --- Post and page headers --- */

.intro-header {
Expand Down
Binary file added img/hello_world.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 14 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ <h3 class="post-subtitle">
Posted on {{ post.date | date: "%B %-d, %Y" }}
</p>

<div class="post-entry">
{{ post.excerpt | strip_html | xml_escape | truncatewords: site.excerpt_length }}
{% assign excerpt_word_count = post.excerpt | number_of_words %}
{% if post.content != post.excerpt or excerpt_word_count > site.excerpt_length %}
<a href="{{ post.url | prepend: site.baseurl }}" class="post-read-more">[Read&nbsp;More]</a>
<div class="post-entry-container">
{% if post.image %}
<div class="post-image">
<a href="{{ post.url | prepend: site.baseurl }}">
<img src="{{ post.image }}">
</a>
</div>
{% endif %}
<div class="post-entry">
{{ post.excerpt | strip_html | xml_escape | truncatewords: site.excerpt_length }}
{% assign excerpt_word_count = post.excerpt | number_of_words %}
{% if post.content != post.excerpt or excerpt_word_count > site.excerpt_length %}
<a href="{{ post.url | prepend: site.baseurl }}" class="post-read-more">[Read&nbsp;More]</a>
{% endif %}
</div>
</div>

{% if post.tags.size > 0 %}
Expand Down

0 comments on commit 66bd2ad

Please sign in to comment.