From 7dd82163421e86ac10db4ee808e9e03fb52a95e8 Mon Sep 17 00:00:00 2001 From: Engin Diri Date: Sun, 8 Feb 2026 20:43:57 +0100 Subject: [PATCH] Add path and branch parameters to github-card shortcode Support linking to specific folders within a repo by adding `path` and `branch` parameters. The branch defaults to "main" so users only need to provide the folder path. --- layouts/shortcodes/github-card.html | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/layouts/shortcodes/github-card.html b/layouts/shortcodes/github-card.html index ce7e61536a46..92c3e91c0975 100644 --- a/layouts/shortcodes/github-card.html +++ b/layouts/shortcodes/github-card.html @@ -6,15 +6,27 @@ Usage: {{< github-card repo="owner/repo" >}} + {{< github-card repo="owner/repo" path="example-folder" >}} + {{< github-card repo="owner/repo" branch="master" path="example-folder" >}} Parameters: - repo (required): The GitHub repository in "owner/repo" format + - path (optional): Path within the repo (e.g., "example-folder") + - branch (optional): Branch name, defaults to "main" */}} {{ $repo := .Get "repo" }} +{{ $path := .Get "path" }} +{{ $branch := .Get "branch" | default "main" }} {{ if $repo }} - +{{ $linkUrl := printf "https://github.com/%s" $repo }} +{{ $displayUrl := printf "github.com/%s" $repo }} +{{ if $path }} + {{ $linkUrl = printf "https://github.com/%s/tree/%s/%s" $repo $branch $path }} + {{ $displayUrl = printf "github.com/%s/tree/%s/%s" $repo $branch $path }} +{{ end }} + GitHub repository: {{ $repo }}
- github.com/{{ $repo }} + {{ $displayUrl }}