Skip to content

Commit

Permalink
feat: support github style alerts (#513)
Browse files Browse the repository at this point in the history
* feat: basic github style alerts support

* feat: implement github style alert

* chore: re-generate css

* chore: add missing prettier config

* docs: add alerts instructions to markdown

* chore: revert "docs: add alerts instructions to markdown"

This reverts commit 3a70540.

* chore: redo "docs: add alerts instructions to markdown""

This reverts commit 8399373.

* chore(build): bump hugo version
  • Loading branch information
imfing authored Dec 14, 2024
1 parent 0c90c1a commit 68dd327
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"plugins": [
"prettier-plugin-go-template"
],
"goTemplateBracketSpacing": true,
"htmlWhitespaceSensitivity": "css",
"printWidth": 200,
Expand Down
69 changes: 69 additions & 0 deletions assets/css/compiled/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,10 @@ video {
.hx-border-t {
border-top-width: 1px;
}
.hx-border-amber-200 {
--tw-border-opacity: 1;
border-color: rgb(253 230 138 / var(--tw-border-opacity));
}
.hx-border-black\/5 {
border-color: rgb(0 0 0 / 0.05);
}
Expand All @@ -967,6 +971,14 @@ video {
--tw-border-opacity: 1;
border-color: rgb(107 114 128 / var(--tw-border-opacity));
}
.hx-border-green-200 {
--tw-border-opacity: 1;
border-color: rgb(187 247 208 / var(--tw-border-opacity));
}
.hx-border-indigo-200 {
--tw-border-opacity: 1;
border-color: rgb(199 210 254 / var(--tw-border-opacity));
}
.hx-border-orange-100 {
--tw-border-opacity: 1;
border-color: rgb(255 237 213 / var(--tw-border-opacity));
Expand All @@ -982,6 +994,10 @@ video {
--tw-border-opacity: 1;
border-color: rgb(254 249 195 / var(--tw-border-opacity));
}
.hx-bg-amber-100 {
--tw-bg-opacity: 1;
background-color: rgb(254 243 199 / var(--tw-bg-opacity));
}
.hx-bg-black\/80 {
background-color: rgb(0 0 0 / 0.8);
}
Expand All @@ -996,6 +1012,14 @@ video {
--tw-bg-opacity: 1;
background-color: rgb(243 244 246 / var(--tw-bg-opacity));
}
.hx-bg-green-100 {
--tw-bg-opacity: 1;
background-color: rgb(220 252 231 / var(--tw-bg-opacity));
}
.hx-bg-indigo-100 {
--tw-bg-opacity: 1;
background-color: rgb(224 231 255 / var(--tw-bg-opacity));
}
.hx-bg-neutral-50 {
--tw-bg-opacity: 1;
background-color: rgb(250 250 250 / var(--tw-bg-opacity));
Expand Down Expand Up @@ -1161,6 +1185,9 @@ video {
.hx-text-center {
text-align: center;
}
.hx-align-middle {
vertical-align: middle;
}
.hx-align-text-bottom {
vertical-align: text-bottom;
}
Expand Down Expand Up @@ -1237,6 +1264,10 @@ video {
--tw-text-opacity: 1;
color: hsl(var(--primary-hue) 100% 50% / var(--tw-text-opacity));
}
.hx-text-amber-900 {
--tw-text-opacity: 1;
color: rgb(120 53 15 / var(--tw-text-opacity));
}
.hx-text-blue-900 {
--tw-text-opacity: 1;
color: rgb(30 58 138 / var(--tw-text-opacity));
Expand Down Expand Up @@ -1268,6 +1299,14 @@ video {
--tw-text-opacity: 1;
color: rgb(17 24 39 / var(--tw-text-opacity));
}
.hx-text-green-900 {
--tw-text-opacity: 1;
color: rgb(20 83 45 / var(--tw-text-opacity));
}
.hx-text-indigo-900 {
--tw-text-opacity: 1;
color: rgb(49 46 129 / var(--tw-text-opacity));
}
.hx-text-orange-800 {
--tw-text-opacity: 1;
color: rgb(154 52 18 / var(--tw-text-opacity));
Expand Down Expand Up @@ -2931,6 +2970,9 @@ body:is(html[class~="dark"] *) {
.dark\:hx-hidden:is(html[class~="dark"] *) {
display: none;
}
.dark\:hx-border-amber-200\/30:is(html[class~="dark"] *) {
border-color: rgb(253 230 138 / 0.3);
}
.dark\:hx-border-blue-200\/30:is(html[class~="dark"] *) {
border-color: rgb(191 219 254 / 0.3);
}
Expand All @@ -2941,6 +2983,12 @@ body:is(html[class~="dark"] *) {
--tw-border-opacity: 1;
border-color: rgb(156 163 175 / var(--tw-border-opacity));
}
.dark\:hx-border-green-200\/30:is(html[class~="dark"] *) {
border-color: rgb(187 247 208 / 0.3);
}
.dark\:hx-border-indigo-200\/30:is(html[class~="dark"] *) {
border-color: rgb(199 210 254 / 0.3);
}
.dark\:hx-border-neutral-700:is(html[class~="dark"] *) {
--tw-border-opacity: 1;
border-color: rgb(64 64 64 / var(--tw-border-opacity));
Expand All @@ -2961,6 +3009,9 @@ body:is(html[class~="dark"] *) {
.dark\:hx-border-yellow-200\/30:is(html[class~="dark"] *) {
border-color: rgb(254 240 138 / 0.3);
}
.dark\:hx-bg-amber-900\/30:is(html[class~="dark"] *) {
background-color: rgb(120 53 15 / 0.3);
}
.dark\:hx-bg-black\/60:is(html[class~="dark"] *) {
background-color: rgb(0 0 0 / 0.6);
}
Expand All @@ -2977,6 +3028,12 @@ body:is(html[class~="dark"] *) {
.dark\:hx-bg-gray-50\/10:is(html[class~="dark"] *) {
background-color: rgb(249 250 251 / 0.1);
}
.dark\:hx-bg-green-900\/30:is(html[class~="dark"] *) {
background-color: rgb(20 83 45 / 0.3);
}
.dark\:hx-bg-indigo-900\/30:is(html[class~="dark"] *) {
background-color: rgb(49 46 129 / 0.3);
}
.dark\:hx-bg-neutral-800:is(html[class~="dark"] *) {
--tw-bg-opacity: 1;
background-color: rgb(38 38 38 / var(--tw-bg-opacity));
Expand Down Expand Up @@ -3012,6 +3069,10 @@ body:is(html[class~="dark"] *) {
.dark\:hx-to-gray-400:is(html[class~="dark"] *) {
--tw-gradient-to: #9ca3af var(--tw-gradient-to-position);
}
.dark\:hx-text-amber-200:is(html[class~="dark"] *) {
--tw-text-opacity: 1;
color: rgb(253 230 138 / var(--tw-text-opacity));
}
.dark\:hx-text-blue-200:is(html[class~="dark"] *) {
--tw-text-opacity: 1;
color: rgb(191 219 254 / var(--tw-text-opacity));
Expand All @@ -3036,6 +3097,14 @@ body:is(html[class~="dark"] *) {
--tw-text-opacity: 1;
color: rgb(249 250 251 / var(--tw-text-opacity));
}
.dark\:hx-text-green-200:is(html[class~="dark"] *) {
--tw-text-opacity: 1;
color: rgb(187 247 208 / var(--tw-text-opacity));
}
.dark\:hx-text-indigo-200:is(html[class~="dark"] *) {
--tw-text-opacity: 1;
color: rgb(199 210 254 / var(--tw-text-opacity));
}
.dark\:hx-text-neutral-200:is(html[class~="dark"] *) {
--tw-text-opacity: 1;
color: rgb(229 229 229 / var(--tw-text-opacity));
Expand Down
38 changes: 38 additions & 0 deletions exampleSite/content/docs/guide/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,44 @@ Blockquote with attribution
[^1]: The above quote is excerpted from Rob Pike's [talk](https://www.youtube.com/watch?v=PAAkCSZUG1c) during Gopherfest, November 18, 2015.
```

### Alerts

Alerts are a Markdown extension based on the blockquote syntax that you can use to emphasize critical information.
[GitHub-style alerts](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts) are supported.
Please make sure you are using the latest version of Hextra and [Hugo v0.134.0](https://github.com/gohugoio/hugo/releases/tag/v0.134.0) or later.

> [!NOTE]
> Useful information that users should know, even when skimming content.
> [!TIP]
> Helpful advice for doing things better or more easily.
> [!IMPORTANT]
> Key information users need to know to achieve their goal.
> [!WARNING]
> Urgent info that needs immediate user attention to avoid problems.
> [!CAUTION]
> Advises about risks or negative outcomes of certain actions.
```markdown {filename=Markdown}
> [!NOTE]
> Useful information that users should know, even when skimming content.

> [!TIP]
> Helpful advice for doing things better or more easily.

> [!IMPORTANT]
> Key information users need to know to achieve their goal.

> [!WARNING]
> Urgent info that needs immediate user attention to avoid problems.

> [!CAUTION]
> Advises about risks or negative outcomes of certain actions.
```

### Tables

Tables aren't part of the core Markdown spec, but Hugo supports them out-of-the-box.
Expand Down
19 changes: 19 additions & 0 deletions exampleSite/hugo_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,14 @@
"dark:hover:hx-text-gray-50",
"dark:hover:hx-text-neutral-50",
"dark:hover:hx-text-white",
"dark:hx-bg-amber-900/30",
"dark:hx-bg-black/60",
"dark:hx-bg-blue-900/30",
"dark:hx-bg-dark",
"dark:hx-bg-dark/50",
"dark:hx-bg-gray-50/10",
"dark:hx-bg-green-900/30",
"dark:hx-bg-indigo-900/30",
"dark:hx-bg-neutral-800",
"dark:hx-bg-neutral-900",
"dark:hx-bg-orange-400/20",
Expand All @@ -155,9 +158,12 @@
"dark:hx-bg-red-900/30",
"dark:hx-bg-yellow-700/30",
"dark:hx-block",
"dark:hx-border-amber-200/30",
"dark:hx-border-blue-200/30",
"dark:hx-border-gray-100/20",
"dark:hx-border-gray-400",
"dark:hx-border-green-200/30",
"dark:hx-border-indigo-200/30",
"dark:hx-border-neutral-700",
"dark:hx-border-neutral-800",
"dark:hx-border-orange-400/30",
Expand All @@ -171,12 +177,15 @@
"dark:hx-shadow-[0_-12px_16px_#111]",
"dark:hx-shadow-[0_-1px_0_rgba(255,255,255,.1)_inset]",
"dark:hx-shadow-none",
"dark:hx-text-amber-200",
"dark:hx-text-blue-200",
"dark:hx-text-gray-100",
"dark:hx-text-gray-200",
"dark:hx-text-gray-300",
"dark:hx-text-gray-400",
"dark:hx-text-gray-50",
"dark:hx-text-green-200",
"dark:hx-text-indigo-200",
"dark:hx-text-neutral-200",
"dark:hx-text-neutral-400",
"dark:hx-text-orange-300",
Expand Down Expand Up @@ -256,15 +265,19 @@
"hover:hx-text-primary-600",
"hx-absolute",
"hx-align-[-2.5px]",
"hx-align-middle",
"hx-align-text-bottom",
"hx-appearance-none",
"hx-aspect-auto",
"hx-bg-amber-100",
"hx-bg-black/80",
"hx-bg-black/[.05]",
"hx-bg-blue-100",
"hx-bg-clip-text",
"hx-bg-gradient-to-r",
"hx-bg-gray-100",
"hx-bg-green-100",
"hx-bg-indigo-100",
"hx-bg-neutral-50",
"hx-bg-orange-50",
"hx-bg-primary-100",
Expand All @@ -277,12 +290,15 @@
"hx-bg-yellow-50",
"hx-block",
"hx-border",
"hx-border-amber-200",
"hx-border-b",
"hx-border-b-2",
"hx-border-black/5",
"hx-border-blue-200",
"hx-border-gray-200",
"hx-border-gray-500",
"hx-border-green-200",
"hx-border-indigo-200",
"hx-border-orange-100",
"hx-border-red-200",
"hx-border-t",
Expand Down Expand Up @@ -468,6 +484,7 @@
"hx-text-[.65rem]",
"hx-text-[10px]",
"hx-text-[color:hsl(var(--primary-hue),100%,50%)]",
"hx-text-amber-900",
"hx-text-base",
"hx-text-blue-900",
"hx-text-center",
Expand All @@ -479,6 +496,8 @@
"hx-text-gray-700",
"hx-text-gray-800",
"hx-text-gray-900",
"hx-text-green-900",
"hx-text-indigo-900",
"hx-text-left",
"hx-text-lg",
"hx-text-orange-800",
Expand Down
9 changes: 9 additions & 0 deletions layouts/_default/_markup/render-blockquote-alert.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- if not (in (slice "note" "tip" "important" "warning" "caution") .AlertType) -}}
{{- warnf "Alert type %s is not supported" .AlertType -}}
{{- end -}}

{{- $content := .Text -}}
{{- $alertType := .AlertType -}}
{{- $alertTitle := .AlertTitle -}}

{{- partial "components/github-style-alert.html" (dict "content" $content "alertType" $alertType "alertTitle" $alertTitle) -}}
3 changes: 3 additions & 0 deletions layouts/_default/_markup/render-blockquote-regular.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<blockquote>
{{ .Text }}
</blockquote>
42 changes: 42 additions & 0 deletions layouts/partials/components/github-style-alert.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{- $content := .content -}}
{{- $alertType := .alertType -}}
{{- $alertTitle := .alertTitle -}}

{{- $icons := dict
"note" "information-circle"
"tip" "light-bulb"
"important" "information-circle"
"warning" "exclamation"
"caution" "exclamation-circle"
-}}

{{- $icon := index $icons $alertType -}}
{{- $title := or $alertTitle (or (i18n $alertType) (title $alertType)) -}}

{{- $defaultClass := "hx-border-orange-100 hx-bg-orange-50 hx-text-orange-800 dark:hx-border-orange-400/30 dark:hx-bg-orange-400/20 dark:hx-text-orange-300" }}

{{- $alertClasses := dict
"note" "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"
"tip" "hx-border-green-200 hx-bg-green-100 hx-text-green-900 dark:hx-border-green-200/30 dark:hx-bg-green-900/30 dark:hx-text-green-200"
"important" "hx-border-indigo-200 hx-bg-indigo-100 hx-text-indigo-900 dark:hx-border-indigo-200/30 dark:hx-bg-indigo-900/30 dark:hx-text-indigo-200"
"warning" "hx-border-amber-200 hx-bg-amber-100 hx-text-amber-900 dark:hx-border-amber-200/30 dark:hx-bg-amber-900/30 dark:hx-text-amber-200"
"caution" "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"
-}}

{{- $class := index $alertClasses $alertType | default $defaultClass -}}


<div class="hx-overflow-x-auto hx-mt-6 hx-flex hx-flex-col hx-rounded-lg hx-border hx-py-4 hx-px-4 contrast-more:hx-border-current contrast-more:dark:hx-border-current {{ $class }}">
<p class="hx-flex hx-items-center hx-font-medium">
{{- with $icon -}}
{{- partial "utils/icon.html" (dict "name" . "attributes" `height=16px class="hx-inline-block hx-align-middle hx-mr-2"`) -}}
{{- end -}}
{{- $title -}}
</p>

<div class="hx-w-full hx-min-w-0 hx-leading-7">
<div class="hx-mt-6 hx-leading-7 first:hx-mt-0">
{{- $content -}}
</div>
</div>
</div>
28 changes: 28 additions & 0 deletions layouts/partials/shortcodes/callout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- $content := .content -}}
{{- $emoji := .emoji -}}
{{- $icon := .icon -}}

{{- $defaultClass := "hx-border-orange-100 hx-bg-orange-50 hx-text-orange-800 dark:hx-border-orange-400/30 dark:hx-bg-orange-400/20 dark:hx-text-orange-300" -}}

{{- $class := .class | default $defaultClass -}}


<div class="hx-overflow-x-auto hx-mt-6 hx-flex hx-rounded-lg hx-border hx-py-2 ltr:hx-pr-4 rtl:hx-pl-4 contrast-more:hx-border-current contrast-more:dark:hx-border-current {{ $class }}">
<div class="ltr:hx-pl-3 ltr:hx-pr-2 rtl:hx-pr-3 rtl:hx-pl-2">
{{- with $emoji -}}
<div class="hx-select-none hx-text-xl" style="font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';">
{{- . -}}
</div>
{{- else -}}
{{- with $icon -}}
{{ partial "utils/icon.html" (dict "name" . "attributes" `height=1.2em class="hx-inline-block hx-align-middle"`) -}}
{{- end -}}
{{- end -}}
</div>

<div class="hx-w-full hx-min-w-0 hx-leading-7">
<div class="hx-mt-6 hx-leading-7 first:hx-mt-0">
{{- $content -}}
</div>
</div>
</div>
Loading

0 comments on commit 68dd327

Please sign in to comment.