From 5a7ca67b511f53597f7b300be89463f60fe49d37 Mon Sep 17 00:00:00 2001 From: madrilene Date: Fri, 7 Mar 2025 17:29:11 +0100 Subject: [PATCH] validate carbon.txt --- src/_data/meta.js | 23 +++++++++++------------ src/common/carbon.njk | 16 ++++++++++++---- src/pages/sustainability.md | 11 +++++++++++ 3 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 src/pages/sustainability.md diff --git a/src/_data/meta.js b/src/_data/meta.js index 36a828e..6d7cda0 100644 --- a/src/_data/meta.js +++ b/src/_data/meta.js @@ -1,4 +1,6 @@ export const url = process.env.URL || 'http://localhost:8080'; +// Extract domain from `url` +export const domain = new URL(url).hostname; export const siteName = 'Eleventy Excellent'; export const siteDescription = 'Eleventy starter for building modern, resilient websites'; export const siteType = 'Person'; // schema @@ -74,18 +76,15 @@ export const themeSwitch = { dark: 'dark' }; export const greenweb = { - // this goes into src/common/greenweb.njk - providers: { - // if you want to add more than one, edit the array directly. - domain: 'netlify.com', - service: 'cdn' - }, - credentials: { - // optional, eg: { domain='my-org.com', doctype = 'webpage', url = 'https://my-org.com/our-climate-record'} - domain: '', - doctype: '', - url: '' - } + // https://carbontxt.org/ + disclosures: [ + { + docType: 'sustainability-page', + url: `${url}/sustainability/`, + domain: domain + } + ], + services: [{domain: 'netlify.com', serviceType: 'cdn'}] }; export const viewRepo = { // this is for the view/edit on github link. The value in the package.json will be pulled in. diff --git a/src/common/carbon.njk b/src/common/carbon.njk index 09e647a..f720c2d 100644 --- a/src/common/carbon.njk +++ b/src/common/carbon.njk @@ -3,7 +3,15 @@ permalink: /carbon.txt eleventyExcludeFromCollections: true excludeFromSitemap: true --- -[upstream] providers = [{ domain = '{{ meta.greenweb.providers.domain }}', service = -'{{ meta.greenweb.providers.service }}' }] [org] credentials = -[{% if meta.greenweb.credentials.domain %}{ domain = '{{ meta.greenweb.credentials.domain }}', doctype = -'{{ meta.greenweb.credentials.doctype }}', url = '{{ meta.greenweb.credentials.url }}' }{% endif %}] +[org] +disclosures = [ +{%- if meta.greenweb.disclosures | length >= 1 and meta.greenweb.disclosures[0].domain != '' -%} +{% for disclosure in meta.greenweb.disclosures %} + { doc_type='{{ disclosure.docType }}', url='{{ disclosure.url }}', domain='{{ disclosure.domain }}' }{%- if not loop.last -%},{% endif %}{% endfor %}{% endif %} +] +{% if meta.greenweb.services | length >= 1 and meta.greenweb.services[0].domain != '' %} +[upstream] +services = [ + {% for service in meta.greenweb.services %}{ domain='{{ service.domain }}', service_type='{{ service.serviceType }}' }{%- if not loop.last -%},{% endif %}{% endfor %} +] +{% endif %} diff --git a/src/pages/sustainability.md b/src/pages/sustainability.md new file mode 100644 index 0000000..2ac52e8 --- /dev/null +++ b/src/pages/sustainability.md @@ -0,0 +1,11 @@ +--- +title: Sustainability +layout: page +eleventyExcludeFromCollections: true +excludeFromSitemap: true +permalink: /sustainability/index.html +--- + +**Carbon Footprint**: This Website has a A+ Carbon Rating. [View full analysis on websitecarbon.com](https://www.websitecarbon.com/website/eleventy-excellent-netlify-app/) + +Only 0.02 g of CO2 is produced every time someone visits this web page.