Allow dynamic images on each blog post (#143)

* Allow dynamic images on each blog post

* Adding responsive CSS for blog post images

* Adding image parameter to YAML front matter
This commit is contained in:
Bryan Britten 2016-12-24 17:48:55 -05:00 committed by Dean Attali
parent 33c5ffadff
commit 66bd2ada99
7 changed files with 67 additions and 6 deletions

View File

@ -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). 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. 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`. 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. 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). 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) 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)

View File

@ -182,6 +182,13 @@ prose:
help: "Enter date of post." help: "Enter date of post."
placeholder: "yyyy-mm-dd" placeholder: "yyyy-mm-dd"
alterable: true alterable: true
- name: "image"
field:
element: "text"
label: "Image"
help: "Add a thumbnail image to your post."
placeholder: "Thumbnail"
alterable: true
- name: "published" - name: "published"
field: field:
element: "checkbox" element: "checkbox"

View File

@ -37,7 +37,15 @@
</ul> </ul>
</div> </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-container">
<div class="avatar-img-border"> <div class="avatar-img-border">
<a href="{{ site.url }} "> <a href="{{ site.url }} ">

View File

@ -1,6 +1,7 @@
--- ---
layout: post layout: post
title: First post! title: First post!
image: /img/hello_world.jpeg
tags: [random, exciting-stuff] tags: [random, exciting-stuff]
--- ---

View File

@ -340,6 +340,28 @@ footer .theme-by {
.post-preview .post-entry { .post-preview .post-entry {
font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; 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 { .post-preview .post-read-more {
font-weight: 800; font-weight: 800;
} }
@ -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 --- */ /* --- Post and page headers --- */
.intro-header { .intro-header {

BIN
img/hello_world.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -21,12 +21,21 @@ subtitle: This is where I will tell my friends way too much about me
Posted on {{ post.date | date: "%B %-d, %Y" }} Posted on {{ post.date | date: "%B %-d, %Y" }}
</p> </p>
<div class="post-entry"> <div class="post-entry-container">
{{ post.excerpt | strip_html | xml_escape | truncatewords: site.excerpt_length }} {% if post.image %}
{% assign excerpt_word_count = post.excerpt | number_of_words %} <div class="post-image">
{% if post.content != post.excerpt or excerpt_word_count > site.excerpt_length %} <a href="{{ post.url | prepend: site.baseurl }}">
<a href="{{ post.url | prepend: site.baseurl }}" class="post-read-more">[Read&nbsp;More]</a> <img src="{{ post.image }}">
</a>
</div>
{% endif %} {% 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> </div>
{% if post.tags.size > 0 %} {% if post.tags.size > 0 %}