Skip to content

Commit 6d8f248

Browse files
author
Phil Hawksworth
authored
Merge pull request #528 from jamstack/ph/og-improvements
Ph/og improvements
2 parents 47eb0fd + 2abcfbb commit 6d8f248

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

.eleventy.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,25 @@ module.exports = function(eleventyConfig) {
161161
});
162162

163163

164-
eleventyConfig.addFilter("replace", (str, from, to) => {
165-
if (str) {
166-
return str.replace(new RegExp(from, "g"), to);
164+
// Format a path to avoid any Cloudinary URL API miss-steps.
165+
eleventyConfig.addFilter("cloudinaryifyPath", (str) => {
166+
167+
if(str) {
168+
169+
// add generic url encoding
170+
str = encodeURI(str);
171+
172+
// we also need to double escape some characters which might appear in text
173+
// but are meaningful in cloudinary URLs
174+
str = str.replace(/,/g, '%252C');
175+
str = str.replace(/\//g, '%252F');
176+
167177
}
178+
return str;
168179
});
169180

170181

182+
171183
// favicons files
172184
eleventyConfig.addPassthroughCopy("src/site/browserconfig.xml");
173185
eleventyConfig.addPassthroughCopy("src/site/site.webmanifest");

src/site/_data/glossary.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
- term: 'CDN (Content Delivery Network)'
2525
id: 'cdn'
26-
summary: 'A network of optimized for serving assets to users. A CDN can provide redundancy and also improve delivery performance as a result of being geographically distributed.'
26+
summary: 'A network optimized for serving assets to users. A CDN can provide redundancy and also improve delivery performance as a result of being geographically distributed.'
2727
definition: 'A distributed network optimized for serving assets to users. By being geographically distributed, a CDN can provide redundancy and also improve delivery performance as a result of servicing requests from the infrastructure closest to the user making the request.'
2828

2929
- term: 'Edge Network'

src/site/_includes/layouts/base.njk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ ogimage: "/img/og/default-og-image.png"
1717
<link rel="icon" type="image/png" sizes="16x16" href="/img/favicons/favicon-16x16.png">
1818
<meta property="og:title" content="{{ title }} | Jamstack">
1919
<meta property="og:site_name" content="Jamstack.org">
20-
<meta property="og:url" content="https://jamstack.org/">
20+
<meta property="og:url" content="https://jamstack.org{{ page.url }}">
2121
<meta property="og:description" content="{{ description }}">
2222
<meta property="og:type" content="website">
2323
<meta property="og:image" content="{{ netlify.deployUrl }}{{ ogimage }}">
2424
<meta property="twitter:card" content="summary_large_image">
25-
<meta property="twitter:url" content="https://jamstack.org/">
25+
<meta property="twitter:url" content="https://jamstack.org{{ page.url }}">
2626
<meta property="twitter:title" content="{{ title }} | Jamstack">
2727
<meta property="twitter:description" content="{{ description }}">
2828
<meta property="twitter:image" content="{{ netlify.deployUrl }}{{ ogimage }}">

src/site/glossary-pages.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ layout: layouts/base.njk
1010
eleventyComputed:
1111
title: "{{ item.term }}"
1212
description: "What is {{ item.term }}? {{ item.summary}}"
13-
ogimage: "/img/og/glossary/{{ item.term | replace(',','%252C') | replace('/', '%252F') }}/{{ item.summary | replace(',','%252C') | replace('/', '%252F') }}"
13+
ogimage: "/img/og/glossary/{{ item.term | cloudinaryifyPath }}/{{ item.summary | cloudinaryifyPath }}"
1414

1515
---
1616

0 commit comments

Comments
 (0)