File tree Expand file tree Collapse file tree 4 files changed +24
-5
lines changed
Expand file tree Collapse file tree 4 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 11import { DateTime } from "luxon" ;
22import striptags from "striptags" ;
3+ import Image from "@11ty/eleventy-img" ;
34
45export default function ( eleventyConfig ) {
56 eleventyConfig . addFilter ( "readableDate" , ( dateObj , format , zone ) => {
@@ -70,6 +71,8 @@ export default function(eleventyConfig) {
7071 extractExcerpt ( post )
7172 ) ;
7273
74+ eleventyConfig . addFilter ( "contentImgUrlShortcode" , contentImgUrlShortcode ) ;
75+
7376} ;
7477
7578// Taken from here => https://keepinguptodate.com/pages/2019/06/creating-blog-with-eleventy/
@@ -85,3 +88,19 @@ function extractExcerpt(article) {
8588
8689 return striptags ( content . slice ( 0 , content . indexOf ( "\n" ) ) ) ;
8790}
91+
92+ async function contentImgUrlShortcode ( src ) {
93+ // src might be small.png - taken from frontmatter
94+ const imageSrc = ( this . eleventy . directories . input + this . page . filePathStem + "/../" + src ) . replace ( "//" , "/" ) ;
95+ let metadata = await Image ( imageSrc , {
96+ widths : [ 600 ] ,
97+ formats : [ "png" ] ,
98+ urlPath : this . page . url ,
99+ outputDir : `./_site/${ this . page . url } ` ,
100+ } ) ;
101+
102+ const data = metadata . png [ 0 ] ;
103+ // data.url might be /blog/hello-world/xfO_genLg4-600.jpeg
104+ // note the filename is a content hash-width combination
105+ return data . url ;
106+ }
Original file line number Diff line number Diff line change 11export default function ( eleventyConfig ) {
2- } ;
3-
2+ } ;
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ h1.post-title {
3737}
3838
3939{%- endcss %}
40+
4041<article >
4142 {%- if image %}
4243 <img src =" {{ image }}" alt =" " class =" post-header" />
Original file line number Diff line number Diff line change 1818 },
1919 " headline" : " {{ title or metadata.title }}" ,
2020 " description" : " {{ description or metadata.description }}" ,
21- {% if image % }" image" : " {{ page.url | absoluteUrl(metadata.url) }}{{ image }}" ,{% endif % }
21+ {% if image % }" image" : " {{ image | contentImgUrlShortcode | absoluteUrl(metadata.url) }}" ,{% endif % }
2222 " author" : {
2323 " @type" : " Person" ,
2424 " name" : " {{ metadata.author.name }}"
4242<meta property =" og:type" content =" website" >
4343<meta property =" og:title" content =" {% if title %}{{ title }} | {% endif %}{{ metadata.title }}" >
4444<meta property =" og:description" content =" {% if description %}{{ description }}{% else %}{{ metadata.description }}{% endif %}" >
45- {% if image %} <meta property =" og:image" content =" {{ page.url | absoluteUrl(metadata.url) }}{{ image }}" />{% endif %}
45+ {% if image %} <meta property =" og:image" content =" {{ image | contentImgUrlShortcode | absoluteUrl(metadata.url) }}" />{% endif %}
4646
4747<meta property =" twitter:card" content =" summary_large_image" >
4848<meta name =" twitter:title" content =" {% if title %}{{ title }} | {% endif %}{{ metadata.title }}" />
4949<meta name =" twitter:description" content =" {{ description or metadata.description }}" />
50- {% if image %} <meta name =" twitter:image" content =" {{ page.url | absoluteUrl(metadata.url) }}{{ image }}" />{% endif %}
50+ {% if image %} <meta name =" twitter:image" content =" {{ image | contentImgUrlShortcode | absoluteUrl(metadata.url) }}" />{% endif %}
5151
5252<meta name =" robots" content =" index, follow" />
5353<link rel =" alternate" href =" {{ 'feed/feed.xml' | absoluteUrl(metadata.url) }}" type =" application/atom+xml" title =" {{ metadata.title }}" >
You can’t perform that action at this time.
0 commit comments