Skip to content

Commit 8af6589

Browse files
Merge pull request #69 from Kuadrant/add-image-links
Add image links to original image
2 parents 8ec14a1 + deb39c4 commit 8af6589

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

.eleventy.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module.exports = function(eleventyConfig) {
1616

1717
eleventyConfig.addPassthroughCopy("src/.well-known");
1818

19+
eleventyConfig.addPassthroughCopy("src/blog/**/*.png");
20+
1921
let markdownItOptions = {
2022
html: true,
2123
breaks: true,

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@ This will ensure the blog post title shows up in the post list, grouped by year
3636
The title, author and date will also render in a styled manner at the top of the post page.
3737

3838
If you want to include images, you can create a folder in the `src/blog/` folder, and put the markdown file there, along with any images.
39-
Then you can insert an image like this:
39+
Make sure the folder name is the same as the markdown file name so that the url allows relative image links to work. For example, if the folder is `src/blog/mypost/` and the markdown file is `mypost.md`, then the url will be `/blog/mypost/`. If they are different, like `src/blog/mypost/MyPost.md`, the url will be `/blog/mypost/MyPost/` and relative image links will give a 404.
40+
41+
To insert an image, use the image helper function:
4042

4143
```njk
4244
{% image "./myimage.png", "My image" %}
4345
```
4446

47+
Images will sized automatically for the site, but also include a link to the original size.
48+
This can be helpful if sufficient detail is not visible in a shrunk down image.
49+
4550
The post list template is at `src/_includes/postslist.njk`.
4651
The post page template is at `src/_includes/layouts/post.njk`.

eleventy.config.images.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ module.exports = function(eleventyConfig) {
4646
decoding: "async",
4747
};
4848

49-
return eleventyImage.generateHTML(metadata, imageAttributes);
49+
let imageHtml = eleventyImage.generateHTML(metadata, imageAttributes);
50+
51+
return `<a href="${src}">${imageHtml}</a>`;
5052
});
5153
};

0 commit comments

Comments
 (0)