Skip to content

Commit

Permalink
Merge pull request #69 from Kuadrant/add-image-links
Browse files Browse the repository at this point in the history
Add image links to original image
  • Loading branch information
openshift-merge-bot[bot] authored Nov 11, 2024
2 parents 8ec14a1 + deb39c4 commit 8af6589
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module.exports = function(eleventyConfig) {

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

eleventyConfig.addPassthroughCopy("src/blog/**/*.png");

let markdownItOptions = {
html: true,
breaks: true,
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ This will ensure the blog post title shows up in the post list, grouped by year
The title, author and date will also render in a styled manner at the top of the post page.

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.
Then you can insert an image like this:
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.

To insert an image, use the image helper function:

```njk
{% image "./myimage.png", "My image" %}
```

Images will sized automatically for the site, but also include a link to the original size.
This can be helpful if sufficient detail is not visible in a shrunk down image.

The post list template is at `src/_includes/postslist.njk`.
The post page template is at `src/_includes/layouts/post.njk`.
4 changes: 3 additions & 1 deletion eleventy.config.images.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ module.exports = function(eleventyConfig) {
decoding: "async",
};

return eleventyImage.generateHTML(metadata, imageAttributes);
let imageHtml = eleventyImage.generateHTML(metadata, imageAttributes);

return `<a href="${src}">${imageHtml}</a>`;
});
};

0 comments on commit 8af6589

Please sign in to comment.