From e8a725381194a84fbb4d67ec4d3b5fd6fc595101 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Sun, 14 Jan 2024 12:35:07 +1300 Subject: [PATCH 1/9] Add support for full URLs in image plugin. --- eleventy.config.images.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/eleventy.config.images.js b/eleventy.config.images.js index 32a0269..0b4a823 100644 --- a/eleventy.config.images.js +++ b/eleventy.config.images.js @@ -1,22 +1,38 @@ const path = require("path"); const eleventyImage = require("@11ty/eleventy-img"); -module.exports = eleventyConfig => { - function relativeToInputPath(inputPath, relativeFilePath) { - let split = inputPath.split("/"); - split.pop(); +function relativeToInputPath(inputPath, relativeFilePath) { + let split = inputPath.split("/"); + split.pop(); - return path.resolve(split.join(path.sep), relativeFilePath); + return path.resolve(split.join(path.sep), relativeFilePath); + +} + +function isFullUrl(url) { + try { + new URL(url); + return true; + } catch(e) { + return false; } +} +module.exports = function(eleventyConfig) { // Eleventy Image shortcode // https://www.11ty.dev/docs/plugins/image/ eleventyConfig.addAsyncShortcode("image", async function imageShortcode(src, alt, widths, sizes) { // Full list of formats here: https://www.11ty.dev/docs/plugins/image/#output-formats // Warning: Avif can be resource-intensive so take care! let formats = ["avif", "webp", "auto"]; - let file = relativeToInputPath(this.page.inputPath, src); - let metadata = await eleventyImage(file, { + let input; + if(isFullUrl(src)) { + input = src; + } else { + input = relativeToInputPath(this.page.inputPath, src); + } + + let metadata = await eleventyImage(input, { widths: widths || ["auto"], formats, outputDir: path.join(eleventyConfig.dir.output, "img"), // Advanced usage note: `eleventyConfig.dir` works here because we’re using addPlugin. @@ -29,6 +45,7 @@ module.exports = eleventyConfig => { loading: "lazy", decoding: "async", }; + return eleventyImage.generateHTML(metadata, imageAttributes); }); }; From c1c6d21ed84604a59f621ddece843761277af9c3 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Mon, 12 Feb 2024 09:16:51 -0600 Subject: [PATCH 2/9] Add cache to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ab338d7..83253a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ _site/ node_modules/ package-lock.json +.cache From c2b160541288efb0224edc1f51067dd5d56a6200 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Thu, 7 Mar 2024 07:54:29 -0600 Subject: [PATCH 3/9] Deploy to GitHub Pages action --- .github/workflows/deploy-pages.yml | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/deploy-pages.yml diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml new file mode 100644 index 0000000..e064723 --- /dev/null +++ b/.github/workflows/deploy-pages.yml @@ -0,0 +1,39 @@ +name: Deploy to GitHub Pages + +on: + push: + branches: + - main + pull_request: + +jobs: + deploy: + runs-on: ubuntu-22.04 + permissions: + contents: write + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + steps: + - uses: actions/checkout@v3 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: '18' + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: | + ~/.npm + ./.cache + + - run: npm ci + - run: npm run build-ghpages + + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + if: github.ref == 'refs/heads/main' + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./_site From 25dc5d04528c8528275589e06bb842c30b70f95f Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Thu, 7 Mar 2024 07:55:26 -0600 Subject: [PATCH 4/9] Install --- .github/workflows/deploy-pages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml index e064723..ff16f7a 100644 --- a/.github/workflows/deploy-pages.yml +++ b/.github/workflows/deploy-pages.yml @@ -28,7 +28,7 @@ jobs: ~/.npm ./.cache - - run: npm ci + - run: npm install - run: npm run build-ghpages - name: Deploy From 4a50a70c0d16dc8dac9542635c8e84eb357c70fe Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Thu, 7 Mar 2024 07:57:06 -0600 Subject: [PATCH 5/9] GitHub workflow cache key --- .github/workflows/deploy-pages.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml index ff16f7a..898a472 100644 --- a/.github/workflows/deploy-pages.yml +++ b/.github/workflows/deploy-pages.yml @@ -24,9 +24,15 @@ jobs: - name: Cache dependencies uses: actions/cache@v3 with: - path: | - ~/.npm - ./.cache + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ./.cache + key: ${{ runner.os }}-eleventy-fetch-cache + - run: npm install - run: npm run build-ghpages From 3ce17a93834da4980ae018d4aa0de2048f653e9b Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Thu, 7 Mar 2024 08:00:00 -0600 Subject: [PATCH 6/9] Rename cache actions --- .github/workflows/deploy-pages.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml index 898a472..872d067 100644 --- a/.github/workflows/deploy-pages.yml +++ b/.github/workflows/deploy-pages.yml @@ -21,13 +21,13 @@ jobs: with: node-version: '18' - - name: Cache dependencies + - name: Cache npm uses: actions/cache@v3 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} - - name: Cache dependencies + - name: Cache Eleventy .cache uses: actions/cache@v3 with: path: ./.cache From c37673b2b9aa69935eac3fcad2c9ffdb57def29e Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Thu, 7 Mar 2024 08:03:38 -0600 Subject: [PATCH 7/9] Testing deploys --- content/blog/fourthpost/fourthpost.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/blog/fourthpost/fourthpost.md b/content/blog/fourthpost/fourthpost.md index 8149f7c..4c1a5b2 100644 --- a/content/blog/fourthpost/fourthpost.md +++ b/content/blog/fourthpost/fourthpost.md @@ -1,5 +1,5 @@ --- -title: This is my fourth post. +title: This is my fourth post! description: This is a post on My Blog about touchpoints and circling wagons. date: 2018-09-30 tags: second tag From a2a22ed1955b96c3c7afe4f57a3a49576bfb1e42 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Thu, 7 Mar 2024 08:09:42 -0600 Subject: [PATCH 8/9] Add current build date to output --- _includes/layouts/base.njk | 2 +- eleventy.config.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/_includes/layouts/base.njk b/_includes/layouts/base.njk index 3b3226f..ae7f5bd 100644 --- a/_includes/layouts/base.njk +++ b/_includes/layouts/base.njk @@ -56,6 +56,6 @@
- + diff --git a/eleventy.config.js b/eleventy.config.js index 3fba4b7..9f57b67 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -92,6 +92,10 @@ module.exports = function(eleventyConfig) { }); }); + eleventyConfig.addShortcode("currentBuildDate", () => { + return (new Date()).toISOString(); + }) + // Features to make your build faster (when you need them) // If your passthrough copy gets heavy and cumbersome, add this line