diff --git a/.eleventy.js b/.eleventy.js index 83ae0ee..b362386 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -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; diff --git a/package.json b/package.json index 69eb239..92f274d 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/_generate/pagesjson.njk b/src/_generate/pagesjson.njk index f671351..7b47e10 100644 --- a/src/_generate/pagesjson.njk +++ b/src/_generate/pagesjson.njk @@ -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 %}] \ No newline at end of file +{% endfor %} +] \ No newline at end of file diff --git a/src/_generate/socialtemplate.njk b/src/_generate/socialtemplate.njk index 3da724e..b07cd30 100644 --- a/src/_generate/socialtemplate.njk +++ b/src/_generate/socialtemplate.njk @@ -8,22 +8,52 @@ eleventyExcludeFromCollections: true
- -- Published on {{ meta.siteName }} -
-