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 }}