From da7423997f047aca1e7328082383f43dfb4361ff Mon Sep 17 00:00:00 2001 From: "Kenneth G. Franqueiro" Date: Tue, 17 Dec 2024 17:19:58 -0500 Subject: [PATCH] Add gh shortcode for linking to github PRs or commit hashes --- eleventy.config.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/eleventy.config.ts b/eleventy.config.ts index d23ed1feeb..7b438dbc5e 100644 --- a/eleventy.config.ts +++ b/eleventy.config.ts @@ -385,6 +385,19 @@ export default function (eleventyConfig: any) { } ); + // Renders a link to a GitHub commit or pull request, in parentheses + eleventyConfig.addShortcode("gh", (id: string) => { + if (/^#\d+$/.test(id)) { + const num = id.slice(1); + return `${id}` + } + else if (/^[0-9a-f]{7,}$/.test(id)) { + const sha = id.slice(0, 7); // Truncate in case full SHA was passed + return `${sha}` + } + else throw new Error(`Invalid SHA or PR ID passed to gh tag: ${id}`); + }); + // Renders a section box (used for About this Technique and Guideline / SC) eleventyConfig.addPairedShortcode( "sectionbox",