From 6219c17066bc4f768ecd20201dae12160d549660 Mon Sep 17 00:00:00 2001 From: aloxe Date: Sun, 29 Dec 2024 21:49:02 +0100 Subject: [PATCH] add thumbnail field --- .eleventy.js | 31 +++++++++++++++++++++++++ src/_assets/public/admin/config.yml | 15 ++++++++---- src/_layouts/includes/head.njk | 36 ++++++++++++++++++----------- src/pages/documentation/index.md | 1 + 4 files changed, 66 insertions(+), 17 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index b7a1f94..7893656 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -145,6 +145,37 @@ module.exports = async function(eleventyConfig) { return `${picture}`; }); + // image path for meta tags + eleventyConfig.addNunjucksAsyncShortcode("getOGImageUri", async (page, src) => { + if (!src) return "/img/tete-2006.png"; + + let inputFolder = page.inputPath.split("/") + inputFolder.pop() + inputFolder = inputFolder.join("/"); + const imageSrc = inputFolder+"/"+src; + + let urlPath = page.outputPath.split("/") + urlPath.pop() + urlPath.shift() + urlPath = "/" + urlPath.join("/"); + + // TODO: limit to a certain max height 200x200 min 1200×1200 max + let metadata = await Image(imageSrc, { + widths: [1200], + formats: ["webp"], + urlPath: urlPath, + outputDir: `./_site/${page.url}`, + filenameFormat: function (id, src, width, format, options) { + const extension = path.extname(src); + const name = path.basename(src, extension); + return `${name}-og.${format}`; + } + }) + + const data = metadata.webp[0] + // data.url might be /blog/hello-world/xfO_genLg4-600.jpeg + return data.url + }) // Collections eleventyConfig.addCollection("documentation", function (collection) { diff --git a/src/_assets/public/admin/config.yml b/src/_assets/public/admin/config.yml index 6d2fa7c..b1fce37 100644 --- a/src/_assets/public/admin/config.yml +++ b/src/_assets/public/admin/config.yml @@ -9,7 +9,7 @@ backend: name: github repo: aloxe/huwindty # Path to your GitHub repository - branch: ecrire + branch: seo-fields base_url: https://auth.xn--4lj4bfp6d.eu.org # Path to ext auth provider @@ -24,6 +24,8 @@ collections: - name: "documentation" # Used in routes, e.g., /admin/collections/blog label: "Documentation" # Used in the UI folder: "src/pages/documentation" # The path to the folder where the documents are stored + thumbnail: true + columns: [title, date] media_folder: '' # start with a slash public_folder: /documentation create: true # Allow users to create new documents in this collection @@ -49,21 +51,26 @@ collections: - label: "description" name: "description" widget: "string" - picker_utc: false + required: false - label: "tags" name: "tags" widget: "string" - picker_utc: false + required: false - label: "author" name: "author" widget: "string" - picker_utc: false + required: false - label: "date" name: "date" widget: "datetime" default: "{{now}}" format: "YYYY-MM-DD" picker_utc: false + - label: "Featured Image" + name: "thumbnail" + widget: "image" + allow_multiple: false + required: false - name: "examples" # Used in routes, e.g., /admin/collections/blog label: "Examples" # Used in the UI folder: "src/pages/examples" # The path to the folder where the documents are stored diff --git a/src/_layouts/includes/head.njk b/src/_layouts/includes/head.njk index 35d3502..5fbb13c 100644 --- a/src/_layouts/includes/head.njk +++ b/src/_layouts/includes/head.njk @@ -1,5 +1,5 @@ - +{% if meta.author.name %}{% endif %} @@ -9,26 +9,36 @@ {% endif %} - - {{ title or meta.title }} - - +{{ title or meta.title }} +{% if description %}{% endif %} + {% if page.fileSlug === "404" %}{% else %} - - {# #} + + {% if description %}{% endif %} + + + + {% if thumbnail %}{% endif %} + + {% if thumbnail %}{% endif %} + + + + + - + {% if description %}{% endif %} - - {# #} + + {% if thumbnail %}{% endif %} - + {% if meta.author.fediverse %}{% endif %} - - {# #} + {% if description %}{% endif %} + {% if thumbnail %}{% endif %} {% endif %} diff --git a/src/pages/documentation/index.md b/src/pages/documentation/index.md index 9a5aa53..44af2bd 100644 --- a/src/pages/documentation/index.md +++ b/src/pages/documentation/index.md @@ -4,6 +4,7 @@ title: Documentation headline: How Huwindty works and how to install it description: Documentation for Huwindty. ismarkdown: true +thumbnail: /static/img/vera.jpg --- ## Table of content