Skip to content

Commit

Permalink
feat: add badge shortcode (#457)
Browse files Browse the repository at this point in the history
* feat: move badge to a separate partial

* feat: badge shortcode

* docs: add badge shortcode examples

* chore: generate css

* docs: add spaces between badges
  • Loading branch information
imfing authored Sep 22, 2024
1 parent cabdb42 commit c70900c
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 12 deletions.
8 changes: 7 additions & 1 deletion assets/css/compiled/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,9 @@ video {
.hx-text-4xl {
font-size: 2.25rem;
}
.hx-text-\[\.65rem\] {
font-size: .65rem;
}
.hx-text-\[10px\] {
font-size: 10px;
}
Expand Down Expand Up @@ -2269,7 +2272,6 @@ article details > summary::before {
top: 5px;
right: 5px;
z-index: 10;
font-size: .65rem;
}
.steps h3 {
counter-increment: step;
Expand Down Expand Up @@ -2594,6 +2596,10 @@ nav .search-wrapper {
overflow: auto;
font-size: .75rem;
}
.hextra-badge {
display: inline-flex;
align-items: center;
}
html {
font-size: 1rem;
-webkit-font-smoothing: antialiased;
Expand Down
3 changes: 3 additions & 0 deletions assets/css/components/badge.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.hextra-badge {
@apply hx-inline-flex hx-items-center;
}
1 change: 0 additions & 1 deletion assets/css/components/cards.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@
top: 5px;
right: 5px;
z-index: 10;
font-size: .65rem;
}
1 change: 1 addition & 0 deletions assets/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@import "components/code-copy.css";
@import "components/hextra/feature-grid.css";
@import "components/jupyter.css";
@import "components/badge.css";

html {
@apply hx-text-base hx-antialiased;
Expand Down
35 changes: 35 additions & 0 deletions exampleSite/content/docs/guide/shortcodes/others.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,41 @@ sidebar:
These shortcodes are considered less stable and may be changed anytime.
{{< /callout >}}

## Badge

```
{{</* badge "Badge" */>}}
```

Result:

{{< badge "Badge" >}}

Variants:

```
{{</* badge content="info" type="info" */>}}
{{</* badge content="warning" type="warning" */>}}
{{</* badge content="error" type="error" */>}}
```

Result:

{{< badge content="info" type="info" >}} &nbsp;
{{< badge content="warning" type="warning" >}} &nbsp;
{{< badge content="error" type="error" >}}

With link:

```
{{</* badge content="Releases" link="https://github.com/imfing/hextra/releases" */>}}
```

Result:

{{< badge content="Releases" link="https://github.com/imfing/hextra/releases" >}}


## YouTube

Embed a YouTube video.
Expand Down
3 changes: 2 additions & 1 deletion exampleSite/hugo_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
"group-hover:hx-underline",
"group-open:before:hx-rotate-90",
"hamburger-menu",
"hextra-badge",
"hextra-card",
"hextra-card-icon",
"hextra-card-image",
Expand Down Expand Up @@ -464,6 +465,7 @@
"hx-sticky",
"hx-text-2xl",
"hx-text-4xl",
"hx-text-[.65rem]",
"hx-text-[10px]",
"hx-text-[color:hsl(var(--primary-hue),100%,50%)]",
"hx-text-base",
Expand All @@ -488,7 +490,6 @@
"hx-text-white",
"hx-text-xl",
"hx-text-xs",
"hx-text-xxs",
"hx-text-yellow-900",
"hx-to-gray-600",
"hx-top-0",
Expand Down
16 changes: 16 additions & 0 deletions layouts/partials/shortcodes/badge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- $content := .content -}}
{{- $type := .type -}}
{{- $class := .class | default "" -}}
{{- $border := .border | default false -}}

{{- $defaultClass := "hx-text-gray-600 hx-bg-gray-100 dark:hx-bg-neutral-800 dark:hx-text-neutral-200 hx-border-gray-200 dark:hx-border-neutral-700" -}}
{{- $warningClass := "hx-border-yellow-100 hx-bg-yellow-50 hx-text-yellow-900 dark:hx-border-yellow-200/30 dark:hx-bg-yellow-700/30 dark:hx-text-yellow-200" -}}
{{- $infoClass := "hx-border-blue-200 hx-bg-blue-100 hx-text-blue-900 dark:hx-border-blue-200/30 dark:hx-bg-blue-900/30 dark:hx-text-blue-200" -}}
{{- $errorClass := "hx-border-red-200 hx-bg-red-100 hx-text-red-900 dark:hx-border-red-200/30 dark:hx-bg-red-900/30 dark:hx-text-red-200" -}}

{{- $borderClass := cond (eq $border true) "hx-border" "" -}}
{{- $badgeClass := cond (eq $type "info") $infoClass (cond (eq $type "warning") $warningClass (cond (eq $type "error") $errorClass $defaultClass)) -}}
<div class="hextra-badge {{ $class }}">
<div class="hx-inline-flex hx-items-center hx-rounded-full hx-px-2.5 hx-leading-6 hx-text-[.65rem] {{ $borderClass }} {{ $badgeClass }}">{{- $content -}}</div>
</div>
{{- /* Strip trailing newline. */ -}}
16 changes: 7 additions & 9 deletions layouts/partials/shortcodes/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@
{{- end -}}

{{- if $tag }}
{{ $defaultClass := "hx-text-gray-600 hx-text-xxs hx-bg-gray-100 dark:hx-bg-neutral-800 dark:hx-text-neutral-200" }}
{{ $warningClass := "hx-border-yellow-100 hx-bg-yellow-50 hx-text-yellow-900 dark:hx-border-yellow-200/30 dark:hx-bg-yellow-700/30 dark:hx-text-yellow-200" }}
{{ $infoClass := "hx-border-blue-200 hx-bg-blue-100 hx-text-blue-900 dark:hx-border-blue-200/30 dark:hx-bg-blue-900/30 dark:hx-text-blue-200" }}
{{ $errorClass := "hx-border-red-200 hx-bg-red-100 hx-text-red-900 dark:hx-border-red-200/30 dark:hx-bg-red-900/30 dark:hx-text-red-200" }}

{{ $tagClass := cond (eq $tagType "info") $infoClass (cond (eq $tagType "warning") $warningClass (cond (eq $tagType "error") $errorClass $defaultClass)) }}
<div class="hextra-card-tag">
<span class="hx-inline-block hx-rounded-full hx-px-2.5 hx-leading-6 {{ $tagClass }}">{{ $tag }}</span>
</div>
{{- partial "shortcodes/badge.html" (dict
"content" $tag
"type" $tagType
"class" "hextra-card-tag"
"border" true
)
-}}
{{- end -}}
</a>
{{- /* Strip trailing newline. */ -}}
33 changes: 33 additions & 0 deletions layouts/shortcodes/badge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{- if .IsNamedParams -}}
{{- $content := .Get "content" -}}
{{- $type := .Get "type" | default "" -}}
{{- $class := .Get "class" | default "" -}}
{{- $link := .Get "link" | default "" -}}

{{- if $link -}}
<a href="{{ $link }}" title="{{ $content | plainify }}" target="_blank">
{{- partial "shortcodes/badge.html" (dict
"content" $content
"type" $type
"class" $class
"border" true
)
-}}
</a>
{{- else -}}
{{- partial "shortcodes/badge.html" (dict
"content" $content
"type" $type
"class" $class
"border" true
)
-}}
{{- end -}}
{{- else -}}
{{- $content := .Get 0 -}}
{{- partial "shortcodes/badge.html" (dict
"content" $content
"border" true
)
-}}
{{- end -}}

0 comments on commit c70900c

Please sign in to comment.