Skip to content

Commit 66bd2ad

Browse files
bryanbrittendaattali
authored andcommitted
Allow dynamic images on each blog post (daattali#143)
* Allow dynamic images on each blog post * Adding responsive CSS for blog post images * Adding image parameter to YAML front matter
1 parent 33c5ffa commit 66bd2ad

File tree

7 files changed

+67
-6
lines changed

7 files changed

+67
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ subtitle | Short description of page or blog post that goes under the title
137137
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).
138138
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.
139139
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`.
140+
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.
140141
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.
141142
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).
142143
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)

_config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ prose:
182182
help: "Enter date of post."
183183
placeholder: "yyyy-mm-dd"
184184
alterable: true
185+
- name: "image"
186+
field:
187+
element: "text"
188+
label: "Image"
189+
help: "Add a thumbnail image to your post."
190+
placeholder: "Thumbnail"
191+
alterable: true
185192
- name: "published"
186193
field:
187194
element: "checkbox"

_includes/nav.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@
3737
</ul>
3838
</div>
3939

40-
{% if site.avatar and (layout.show-avatar or page.show-avatar) %}
40+
{% if page.image and (layout.show-avatar or page.show-avatar) %}
41+
<div class="avatar-container">
42+
<div class="avatar-img-border">
43+
<a href="{{ site.url }} ">
44+
<img class="avatar-img" src="{{ page.image | prepend: site.baseurl | replace: '//', '/' }}" />
45+
</a>
46+
</div>
47+
</div>
48+
{% elsif site.avatar and (layout.show-avatar or page.show-avatar) %}
4149
<div class="avatar-container">
4250
<div class="avatar-img-border">
4351
<a href="{{ site.url }} ">

_posts/2015-01-04-first-post.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
layout: post
33
title: First post!
4+
image: /img/hello_world.jpeg
45
tags: [random, exciting-stuff]
56
---
67

css/main.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,28 @@ footer .theme-by {
340340
.post-preview .post-entry {
341341
font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
342342
}
343+
.post-entry-container {
344+
display: inline-block;
345+
width: 100%;
346+
}
347+
.post-entry {
348+
width: 100%;
349+
}
350+
.post-image {
351+
float: right;
352+
height: 192px;
353+
width: 192px;
354+
margin-top: -35px;
355+
filter: grayscale(90%);
356+
}
357+
.post-image:hover {
358+
filter: grayscale(0%);
359+
}
360+
.post-image img {
361+
border-radius: 100px;
362+
height: 192px;
363+
width: 192px;
364+
}
343365
.post-preview .post-read-more {
344366
font-weight: 800;
345367
}
@@ -382,6 +404,19 @@ footer .theme-by {
382404
}
383405
}
384406

407+
@media only screen and (max-width: 500px) {
408+
.post-image, .post-image img {
409+
height: 100px;
410+
width: 100px;
411+
}
412+
413+
.post-image {
414+
width: 100%;
415+
text-align: center;
416+
margin-top: 0;
417+
float: left;
418+
}
419+
}
385420
/* --- Post and page headers --- */
386421

387422
.intro-header {

img/hello_world.jpeg

17.7 KB
Loading

index.html

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,21 @@ <h3 class="post-subtitle">
2121
Posted on {{ post.date | date: "%B %-d, %Y" }}
2222
</p>
2323

24-
<div class="post-entry">
25-
{{ post.excerpt | strip_html | xml_escape | truncatewords: site.excerpt_length }}
26-
{% assign excerpt_word_count = post.excerpt | number_of_words %}
27-
{% if post.content != post.excerpt or excerpt_word_count > site.excerpt_length %}
28-
<a href="{{ post.url | prepend: site.baseurl }}" class="post-read-more">[Read&nbsp;More]</a>
24+
<div class="post-entry-container">
25+
{% if post.image %}
26+
<div class="post-image">
27+
<a href="{{ post.url | prepend: site.baseurl }}">
28+
<img src="{{ post.image }}">
29+
</a>
30+
</div>
2931
{% endif %}
32+
<div class="post-entry">
33+
{{ post.excerpt | strip_html | xml_escape | truncatewords: site.excerpt_length }}
34+
{% assign excerpt_word_count = post.excerpt | number_of_words %}
35+
{% if post.content != post.excerpt or excerpt_word_count > site.excerpt_length %}
36+
<a href="{{ post.url | prepend: site.baseurl }}" class="post-read-more">[Read&nbsp;More]</a>
37+
{% endif %}
38+
</div>
3039
</div>
3140

3241
{% if post.tags.size > 0 %}

0 commit comments

Comments
 (0)