Skip to content

Commit

Permalink
Add gh shortcode for linking to github PRs or commit hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
kfranqueiro committed Dec 17, 2024
1 parent d1aa717 commit da74239
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions eleventy.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<a href="https://github.com/${GH_ORG}/${GH_REPO}/pull/${num}" aria-label="pull request ${num}">${id}</a>`
}
else if (/^[0-9a-f]{7,}$/.test(id)) {
const sha = id.slice(0, 7); // Truncate in case full SHA was passed
return `<a href="https://github.com/${GH_ORG}/${GH_REPO}/commit/${sha}" aria-label="commit ${sha}">${sha}</a>`
}
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",
Expand Down

0 comments on commit da74239

Please sign in to comment.