Skip to content

Commit

Permalink
Fixed social image generation, and now it looks great!
Browse files Browse the repository at this point in the history
  • Loading branch information
omgmog committed Feb 15, 2021
1 parent b1d4655 commit 876b8ba
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 21 deletions.
12 changes: 12 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ module.exports = function (eleventyConfig) {
return dateToCheck < today;
});

// Filter to format the date in the same way we're doing it clientside, to be used in places
eleventyConfig.addFilter("formatTheDate", (date) => {
return new Intl.DateTimeFormat('default', {
month: 'long',
day: 'numeric',
hour: 'numeric',
hour12: true,
timeZoneName: 'short'
})
.format(new Date(date))
})

eleventyConfig.addFilter("slug", (str) => {
if (!str) {
return;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"build": "cross-env ELEVENTY_ENV=prod npm-run-all build:sass build:eleventy social-images",
"lint": "stylelint 'src/sass/**/*.scss' 'src/sass/**/**/*.scss' 'src/sass/**/**/**/*.scss'",
"lint:fix": "stylelint --fix 'src/sass/**/*.scss' 'src/sass/**/**/*.scss' 'src/sass/**/**/**/*.scss'",
"social-images": "eleventy-social-images --outputDir public --dataFile social/pages.json --templatePath social/template.html --theme green",
"social-images": "eleventy-social-images --outputDir public --dataFile social/pages.json --templatePath social/template.html",
"bump": "npm --no-git-tag-version version"
},
"repository": {
Expand Down
21 changes: 17 additions & 4 deletions src/_generate/pagesjson.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ permalink: ./social/pages.json
permalinkBypassOutputDir: true
eleventyExcludeFromCollections: true
---
[{% for pages in collections.all %}
{# Generate image for the home page #}
[
{# Generate image for other pages #}
{% for pages in collections.all %}
{% if pages.data.previewslug or pages.data.title %}
{
"title":"{{ pages.data.title | addNbsp | safe }}",
"imgName":"{% if pages.data.previewslug %}{{ pages.data.previewslug }}{% else %}{{ pages.data.title | slug }}{% endif %}"
},
{% endif %}
{% endfor %}
{# Generate image for the events #}
{% for event in collections.events %}
{
"title":"{% if pages.data.title %}{{ pages.data.title | addNbsp | safe }}{% else %}{{ meta.siteName }}{% endif %}",
"imgName":"{% if pages.data.title %}{{ pages.data.title | slug}}{% else %}home{% endif %}"
"title":"{{ event.date | formatTheDate }}",
"imgName":"{{ event.fileSlug | slug }}"
}{% if loop.last == false %},{% endif %}
{% endfor %}]
{% endfor %}
]
56 changes: 43 additions & 13 deletions src/_generate/socialtemplate.njk
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,52 @@ eleventyExcludeFromCollections: true
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
href="https://fonts.googleapis.com/css2?family=Baloo+2:wght@400;500&display=swap"
rel="stylesheet"
/>
<style>
{% raw %}{{ style }}{% endraw %}
@import url('https://fonts.googleapis.com/css2?family=Fira+Sans:ital,wght@1,400;1,700&amp;display=swap');
body {
/* This is actually the bg.svg from the main site, base64 encoded so it can be used for the site-preview image generation */
background-image: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4NCjxzdmcgd2lkdGg9IjY1M3B4IiBoZWlnaHQ9IjUxOHB4IiB2aWV3Qm94PSIwIDAgNjUzIDUxOCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIj4NCiAgICA8dGl0bGU+QXJ0Ym9hcmQ8L3RpdGxlPg0KICAgIDxkZWZzPg0KICAgICAgICA8bGluZWFyR3JhZGllbnQgeDE9IjUzLjI3ODkxNjYlIiB5MT0iODAuMTM2NzU1OCUiIHgyPSIzNS44NDM5MDc1JSIgeTI9IjIxLjU3Mjc3ODMlIiBpZD0ibGluZWFyR3JhZGllbnQtMSI+DQogICAgICAgICAgICA8c3RvcCBzdG9wL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HcmFkaWVudC0xKSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoNDEwLjAwMDAwMCwgMjk4LjUwMDAwMCkgcm90YXRlKC02NS4wMDAwMDApIHRyYW5zbGF0ZSgtNDEwLjAwMDAwMCwgLTI5OC41MDAwMDApICIgcG9pbnRzPSIxNDkgLTEzMiA2NzEgNzI5IDQyMC41NDU3MDEgNzI5Ij48L3BvbHlnb24+DQogICAgICAgIDxwb2x5Z29uIGlkPSJQYXRoLTIiIGZpbGw9InVybCgjbGluZWFyR3JhZGllbnQtMikiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDI4NS4wMDAwMDAsIDQ0My4wMDAwMDApIHNjYWxlKC0xLCAxKSByb3RhdGUoLTY4LjAwMDAwMCkgdHJhbnNsYXRlKC0yODUuMDAwMDAwLCAtNDQzLjAwMDAwMCkgIiBwb2ludHM9Ii0xMjIgNDUgNjkyIDg0MSAzMDEuNDQ0ODI5IDg0MSI+PC9wb2x5Z29uPg0KICAgICAgICA8cG9seWdvbiBpZD0iUGF0aC0yIiBmaWxsPSJ1cmwoI2xpbmVhckdyYWRpZW50LTMpIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSg1MTQuMDAwMDAwLCAxNjkuMDAwMDAwKSBzY2FsZSgtMSwgLTEpIHJvdGF0ZSg0NS4wMDAwMDApIHRyYW5zbGF0ZSgtNTE0LjAwMDAwMCwgLTE2OS4wMDAwMDApICIgcG9pbnRzPSIxMzYgLTQ5IDg5MiAzODcgODcyLjc5MDUyMiAxMDguMDY3ODIiPjwvcG9seWdvbj4NCiAgICA8L2c+DQo8L3N2Zz4=");
background-color: #20fea1;
background-size: 120% 120%;
background-repeat: no-repeat;
background-position: 50% 50%;
background-attachment: fixed;
margin: 0;
padding: 0;
padding-left: 6vw;
display: flex;
min-height: 100vh;
width: 100%;
justify-content: flex-start;
align-items: center;
box-sizing: border-box;
}
.text {
font-family: Fira Sans;
font-size: 12vw;
font-weight: 400;
font-style: italic;
}
#line1 {
font-weight: 700;
}
#line2 {
}
#line3 {
font-size: 6vw;
font-style: normal;
margin: 0;
padding: 0;
font-weight: inherit;
}
</style>
</head>
<body>
<header>
<div>
<h1></h1>
<p>
<em>Published on</em>&nbsp;&nbsp;<strong>{{ meta.siteName }}</strong>
</p>
</div>
</header>
<div class="text">
<div id="line1">Not</div>
<div id="line2">JSOxford</div>
<h1 id="line3">{{ dateline }}</h1>
</div>
</body>
</html>
4 changes: 3 additions & 1 deletion src/_includes/layouts/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html lang="en">
{%- set pageTitle %}{% if title %}{{ title }} | {% endif %}{{ meta.siteName }}{% endset -%}
{%- set pageDescription %}{% if description %}{{ description }}{% else %}{{ meta.siteDescription }}{% endif %}{% endset -%}
{%- set pageSocialImg %}{{ meta.url }}/previews/{% if title %}{{ title | slug }}{% else %}home{% endif %}.png{% endset -%}
<head>
<!-- Generated from the 11ty Netlify Jumpstart: https://github.com/5t3ph/11ty-netlify-jumpstart -->
<meta charset="UTF-8" />
Expand Down Expand Up @@ -37,6 +36,9 @@
/>
<meta property="og:image" content="{{pageSocialImg}}" />
<meta name="twitter:image" content="{{pageSocialImg}}" />
{%- set pageSocialImg %}/previews/{% if previewslug %}{{ previewslug }}{% else %}{{ page.fileSlug }}{% endif %}.png{% endset -%}
<meta property="og:image" content="{{ pageSocialImg | url }}" />
<meta name="twitter:image" content="{{ pageSocialImg | url }}" />

<link
rel="alternate"
Expand Down
1 change: 1 addition & 0 deletions src/coc.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
layout: page
title: Code of Conduct
description: For all JSNotOxford events
previewslug: code-of-conduct
---

All attendees, speakers, sponsors, volunteers and organisers at our meetup group and online interactions are required to agree with the following code of conduct. Organizers will enforce this code throughout the event. We are expecting cooperation from all participants to help ensure a safe environment for everybody.
Expand Down
1 change: 1 addition & 0 deletions src/index.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
layout: page
previewslug: home
---
{% set all_events = collections.events | reverse %}
{% set next_event = all_events[0] %}
Expand Down
2 changes: 0 additions & 2 deletions src/sass/_maybenot.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
body {
background-color: #20fea1;
background-image: url(../img/bg.svg);

background-size: 100% 100%;
background-size: cover;
background-attachment: fixed;
color: #000;
Expand Down

0 comments on commit 876b8ba

Please sign in to comment.