Skip to content

Commit d2a0f14

Browse files
committed
Add gh shortcode for linking to github PRs or commit hashes
1 parent 71809d7 commit d2a0f14

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

eleventy.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,19 @@ export default function (eleventyConfig: any) {
385385
}
386386
);
387387

388+
// Renders a link to a GitHub commit or pull request, in parentheses
389+
eleventyConfig.addShortcode("gh", (id: string) => {
390+
if (/^#\d+$/.test(id)) {
391+
const num = id.slice(1);
392+
return `<a href="https://github.com/${GH_ORG}/${GH_REPO}/pull/${num}" aria-label="pull request ${num}">${id}</a>`
393+
}
394+
else if (/^[0-9a-f]{7,}$/.test(id)) {
395+
const sha = id.slice(0, 7); // Truncate in case full SHA was passed
396+
return `<a href="https://github.com/${GH_ORG}/${GH_REPO}/commit/${sha}" aria-label="commit ${sha}">${sha}</a>`
397+
}
398+
else throw new Error(`Invalid SHA or PR ID passed to gh tag: ${id}`);
399+
});
400+
388401
// Renders a section box (used for About this Technique and Guideline / SC)
389402
eleventyConfig.addPairedShortcode(
390403
"sectionbox",

0 commit comments

Comments
 (0)