Skip to content

Commit

Permalink
feat: add the dropdowns shortcodes (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Sep 20, 2023
1 parent 942f4d9 commit 174cf65
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 16 deletions.
19 changes: 3 additions & 16 deletions layouts/partials/bootstrap/btn-link.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,14 @@
{{- with .Get 2 }}{{ $outline = . }}{{ end }}
{{- with .Get 3 }}{{ $size = . }}{{ end }}
{{- end }}
{{- $uri := urls.Parse $url }}
{{- $external := true }}
{{- if not $uri.Scheme }}
{{- $external = false }}
{{- with site.GetPage $url }}
{{- $url = .RelPermalink }}
{{- else }}
{{- if hasPrefix $url "/" }}
{{- $url = relURL $url }}
{{- else }}
{{- $url = printf "%s%s" .Page.RelPermalink $url }}
{{- end }}
{{- end }}
{{- end }}
{{- $uri := partial "bootstrap/functions/url" (dict "URL" $url "Page" .Page) }}
{{- $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 }}>
href="{{ $uri.URL }}"
{{ if $uri.External }}target="_blank" rel="external"{{ end }}>
{{- .Inner -}}
</a>
1 change: 1 addition & 0 deletions layouts/partials/bootstrap/dropdown-divider.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<li><hr class="dropdown-divider"></li>
18 changes: 18 additions & 0 deletions layouts/partials/bootstrap/dropdown-item.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- $url := "" }}
{{- $text := "" }}
{{- if .IsNamedParams }}
{{- $text = .Get "text" }}
{{- $url = .Get "url" }}
{{- else }}
{{- $text = .Get 0 }}
{{- $url = .Get 1 }}
{{- end }}
{{- $uri := partial "bootstrap/functions/url" (dict "URL" $url "Page" .Page) }}
<li>
<a
class="dropdown-item"
href="{{ $uri.URL }}"
{{ if $uri.External }}target="_blank" rel="external"{{ end }}>
{{ $text }}
</a>
</li>
25 changes: 25 additions & 0 deletions layouts/partials/bootstrap/dropdown.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- $name := "" }}
{{- $style := "primary" }}
{{- $size := "" }}
{{- $items := slice }}
{{- if .IsNamedParams }}
{{- $name = .Get "name" }}
{{- with .Get "style" }}{{ $style = . }}{{ end }}
{{- with .Get "size" }}{{ $size = . }}{{ end }}
{{- else }}
{{- $name = .Get 0 }}
{{- with .Get 1 }}{{ $style = . }}{{ end }}
{{- with .Get 2 }}{{ $size = . }}{{ end }}
{{- end }}
<div class="dropdown">
<button
type="button"
class="btn btn-{{ $style }} dropdown-toggle{{ with $size }} btn-{{ . }}{{ end }}"
data-bs-toggle="dropdown"
aria-expanded="false">
{{ $name }}
</button>
<ul class="dropdown-menu">
{{ .Inner }}
</ul>
</div>
16 changes: 16 additions & 0 deletions layouts/partials/bootstrap/functions/url.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- $url := .URL }}
{{- $uri := urls.Parse $url }}
{{- $external := true }}
{{- if not $uri.Scheme }}
{{- $external = false }}
{{- with site.GetPage $url }}
{{- $url = .RelPermalink }}
{{- else }}
{{- if hasPrefix $url "/" }}
{{- $url = relURL $url }}
{{- else }}
{{- $url = printf "%s%s" .Page.RelPermalink $url }}
{{- end }}
{{- end }}
{{- end }}
{{- return (dict "External" $external "URL" $url) }}
1 change: 1 addition & 0 deletions layouts/shortcodes/bootstrap/dropdown-divider.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- partialCached "bootstrap/dropdown-divider" . }}
1 change: 1 addition & 0 deletions layouts/shortcodes/bootstrap/dropdown-item.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- partial "bootstrap/dropdown-item" . }}
2 changes: 2 additions & 0 deletions layouts/shortcodes/bootstrap/dropdown.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{- if .Inner }}{{ end }}
{{- partial "bootstrap/dropdown" . }}
1 change: 1 addition & 0 deletions layouts/shortcodes/bs/dropdown-divider.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- partialCached "bootstrap/dropdown-divider" . }}
1 change: 1 addition & 0 deletions layouts/shortcodes/bs/dropdown-item.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- partial "bootstrap/dropdown-item" . }}
2 changes: 2 additions & 0 deletions layouts/shortcodes/bs/dropdown.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{- if .Inner }}{{ end }}
{{- partial "bootstrap/dropdown" . }}

0 comments on commit 174cf65

Please sign in to comment.