Skip to content

Commit

Permalink
feat: add the btn-link shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Jun 29, 2023
1 parent c8d8142 commit e2426de
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
37 changes: 37 additions & 0 deletions layouts/partials/bootstrap/btn-link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{- $url := "" }}
{{- $style := "primary" }}
{{- $size := "" }}
{{- $outline := false }}
{{- $class := "" }}
{{- if .IsNamedParams }}
{{- with .Get "url" }}{{ $url = . }}{{ end }}
{{- with .Get "style" }}{{ $style = . }}{{ end }}
{{- with .Get "outline" }}{{ $outline = . }}{{ end }}
{{- with .Get "size" }}{{ $size = . }}{{ end }}
{{- with .Get "class" }}{{ $class = . }}{{ end }}
{{- else }}
{{- with .Get 0 }}{{ $url = . }}{{ end }}
{{- with .Get 1 }}{{ $style = . }}{{ end }}
{{- with .Get 2 }}{{ $outline = . }}{{ end }}
{{- with .Get 3 }}{{ $size = . }}{{ end }}
{{- end }}
{{- $uri := urls.Parse $url }}
{{- $external := true }}
{{- if not $uri.Scheme }}
{{- $external = false }}
{{- with .Page.GetPage $url }}
{{- $url = .RelPermalink }}
{{- else }}
{{- $url = relURL $url }}
{{- end }}
{{- end }}
{{- $classes := slice "btn" }}
{{- $classes = $classes | append (printf (cond $outline "btn-outline-%s" "btn-%s") $style) }}
{{- with $size }}{{ $classes = $classes | append (printf "btn-%s" .) }}{{ end }}
{{- with $class }}{{ $classes = $classes | append . }}{{ end }}
<a
class="{{ delimit $classes ` ` }}"
href="{{ $url }}"
{{ if $external }}target="_blank" rel="external"{{ end }}>
{{- .Inner -}}
</a>
2 changes: 2 additions & 0 deletions layouts/shortcodes/bootstrap/btn-link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{- if .Inner }}{{ end }}
{{ partial "bootstrap/btn-link" . }}
2 changes: 2 additions & 0 deletions layouts/shortcodes/bs/btn-link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{- if .Inner }}{{ end }}
{{ partial "bootstrap/btn-link" . }}

0 comments on commit e2426de

Please sign in to comment.