diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..3e0be4a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,23 @@ +{ + "image": "mcr.microsoft.com/devcontainers/go:1", + "features": { + "ghcr.io/devcontainers/features/hugo:1": { + "extended": true, + "version": "0.116.1" + }, + "ghcr.io/devcontainers/features/node:1": {} + }, + "customizations": { + "vscode": { + "extensions": [ + "mhutchie.git-graph", + "esbenp.prettier-vscode", + "bradlc.vscode-tailwindcss", + "tamasfe.even-better-toml", + "budparr.language-hugo-vscode" + ] + } + }, + "postCreateCommand": "npm install", + "forwardPorts": [1313] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9460f5e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "editor.tabSize": 2, + "css.customData": [".vscode/tailwind.json"] +} diff --git a/.vscode/tailwind.json b/.vscode/tailwind.json new file mode 100644 index 0000000..96a1f57 --- /dev/null +++ b/.vscode/tailwind.json @@ -0,0 +1,55 @@ +{ + "version": 1.1, + "atDirectives": [ + { + "name": "@tailwind", + "description": "Use the `@tailwind` directive to insert Tailwind's `base`, `components`, `utilities` and `screens` styles into your CSS.", + "references": [ + { + "name": "Tailwind Documentation", + "url": "https://tailwindcss.com/docs/functions-and-directives#tailwind" + } + ] + }, + { + "name": "@apply", + "description": "Use the `@apply` directive to inline any existing utility classes into your own custom CSS. This is useful when you find a common utility pattern in your HTML that you’d like to extract to a new component.", + "references": [ + { + "name": "Tailwind Documentation", + "url": "https://tailwindcss.com/docs/functions-and-directives#apply" + } + ] + }, + { + "name": "@responsive", + "description": "You can generate responsive variants of your own classes by wrapping their definitions in the `@responsive` directive:\n```css\n@responsive {\n .alert {\n background-color: #E53E3E;\n }\n}\n```\n", + "references": [ + { + "name": "Tailwind Documentation", + "url": "https://tailwindcss.com/docs/functions-and-directives#responsive" + } + ] + }, + { + "name": "@screen", + "description": "The `@screen` directive allows you to create media queries that reference your breakpoints by **name** instead of duplicating their values in your own CSS:\n```css\n@screen sm {\n /* ... */\n}\n```\n…gets transformed into this:\n```css\n@media (min-width: 640px) {\n /* ... */\n}\n```\n", + "references": [ + { + "name": "Tailwind Documentation", + "url": "https://tailwindcss.com/docs/functions-and-directives#screen" + } + ] + }, + { + "name": "@variants", + "description": "Generate `hover`, `focus`, `active` and other **variants** of your own utilities by wrapping their definitions in the `@variants` directive:\n```css\n@variants hover, focus {\n .btn-brand {\n background-color: #3182CE;\n }\n}\n```\n", + "references": [ + { + "name": "Tailwind Documentation", + "url": "https://tailwindcss.com/docs/functions-and-directives#variants" + } + ] + } + ] +} diff --git a/assets/js/theme.js b/assets/js/theme.js index 3b52b16..bba443e 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -1,44 +1,36 @@ // Dark theme toggle -// https://flowbite.com/docs/customize/dark-mode/ -const themeToggleBtn = document.getElementById("theme-toggle"); - -const themeToggleDarkIcon = document.getElementById("theme-toggle-dark-icon"); -const themeToggleLightIcon = document.getElementById("theme-toggle-light-icon"); +const themeToggleButtons = document.querySelectorAll(".theme-toggle"); // Change the icons inside the button based on previous settings if ( localStorage.getItem("color-theme") === "dark" || (!("color-theme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches) ) { - themeToggleLightIcon.classList.remove("hidden"); + themeToggleButtons.forEach((el) => el.dataset.theme = "dark"); } else { - themeToggleDarkIcon.classList.remove("hidden"); + themeToggleButtons.forEach((el) => el.dataset.theme = "light"); } -themeToggleBtn.addEventListener("click", function () { - // toggle icons inside button - themeToggleDarkIcon.classList.toggle("hidden"); - themeToggleLightIcon.classList.toggle("hidden"); - - // if set via local storage previously - if (localStorage.getItem("color-theme")) { - if (localStorage.getItem("color-theme") === "light") { - document.documentElement.classList.add("dark"); - localStorage.setItem("color-theme", "dark"); +themeToggleButtons.forEach((el) => { + el.addEventListener("click", function () { + if (localStorage.getItem("color-theme")) { + if (localStorage.getItem("color-theme") === "light") { + document.documentElement.classList.add("dark"); + localStorage.setItem("color-theme", "dark"); + } else { + document.documentElement.classList.remove("dark"); + localStorage.setItem("color-theme", "light"); + } } else { - document.documentElement.classList.remove("dark"); - localStorage.setItem("color-theme", "light"); + if (document.documentElement.classList.contains("dark")) { + document.documentElement.classList.remove("dark"); + localStorage.setItem("color-theme", "light"); + } else { + document.documentElement.classList.add("dark"); + localStorage.setItem("color-theme", "dark"); + } } - - // if NOT set via local storage previously - } else { - if (document.documentElement.classList.contains("dark")) { - document.documentElement.classList.remove("dark"); - localStorage.setItem("color-theme", "light"); - } else { - document.documentElement.classList.add("dark"); - localStorage.setItem("color-theme", "dark"); - } - } + el.dataset.theme = document.documentElement.classList.contains("dark") ? "dark" : "light"; + }); }); diff --git a/content/blog/_index.md b/content/blog/_index.md new file mode 100644 index 0000000..9873cf8 --- /dev/null +++ b/content/blog/_index.md @@ -0,0 +1,3 @@ +--- +title: "Hextra Blog" +--- diff --git a/content/blog/markdown.md b/content/blog/markdown.md new file mode 100644 index 0000000..df32871 --- /dev/null +++ b/content/blog/markdown.md @@ -0,0 +1,175 @@ +--- +title: Markdown +math: true +date: 2020-01-01 +authors: + - name: John Doe + link: https://example.com/johndoe + image: https://example.com/johndoe.png +--- + +This article offers a sample of basic Markdown syntax that can be used in Hugo content files, also it shows whether basic HTML elements are decorated with CSS in a Hugo theme. + + +## Headings + +The following HTML `

`—`

` elements represent six levels of section headings. `

` is the highest section level while `

` is the lowest. + +# H1 +## H2 +### H3 +#### H4 +##### H5 +###### H6 + +## Paragraph + +Xerum, quo qui aut unt expliquam qui dolut labo. Aque venitatiusda cum, voluptionse latur sitiae dolessi aut parist aut dollo enim qui voluptate ma dolestendit peritin re plis aut quas inctum laceat est volestemque commosa as cus endigna tectur, offic to cor sequas etum rerum idem sintibus eiur? Quianimin porecus evelectur, cum que nis nust voloribus ratem aut omnimi, sitatur? Quiatem. Nam, omnis sum am facea corem alique molestrunt et eos evelece arcillit ut aut eos eos nus, sin conecerem erum fuga. Ri oditatquam, ad quibus unda veliamenimin cusam et facea ipsamus es exerum sitate dolores editium rerore eost, temped molorro ratiae volorro te reribus dolorer sperchicium faceata tiustia prat. + +Itatur? Quiatae cullecum rem ent aut odis in re eossequodi nonsequ idebis ne sapicia is sinveli squiatum, core et que aut hariosam ex eat. + +## Blockquotes + +The blockquote element represents content that is quoted from another source, optionally with a citation which must be within a `footer` or `cite` element, and optionally with in-line changes such as annotations and abbreviations. + +#### Blockquote without attribution + +> Tiam, ad mint andaepu dandae nostion secatur sequo quae. +> **Note** that you can use *Markdown syntax* within a blockquote. + +#### Blockquote with attribution + +> Don't communicate by sharing memory, share memory by communicating.
+> — Rob Pike[^1] + +[^1]: The above quote is excerpted from Rob Pike's [talk](https://www.youtube.com/watch?v=PAAkCSZUG1c) during Gopherfest, November 18, 2015. + +## Tables + +Tables aren't part of the core Markdown spec, but Hugo supports them out-of-the-box. + + Name | Age +--------|------ + Bob | 27 + Alice | 23 + +#### Inline Markdown within tables + +| Italics | Bold | Code | +| -------- | -------- | ------ | +| *italics* | **bold** | `code` | + +## Code Blocks + +### Code block with triple backticks + +``` +def say_hello(): + print("Hello!") +``` + + +```python +def say_hello(): + print("Hello!") +``` + +### Code block with filename + +```python {filename="hello.py"} +def say_hello(): + print("Hello!") +``` + +### Code block highlight with line numbers + +```python {linenos=table,hl_lines=[1, 2],linenostart=1} +def say_hello(): + print("Hello!") + +def main(): + say_hello() +``` + +```python {linenos=table,hl_lines=[1, 2],linenostart=1,filename="hello.py"} +def say_hello(): + print("Hello!") + +def main(): + say_hello() +``` + +## Diagrams + +[Mermaid](https://github.com/mermaid-js/mermaid#readme) is a JavaScript based diagramming and charting tool that takes Markdown-inspired text definitions and creates diagrams dynamically in the browser. + +```mermaid +sequenceDiagram + participant Alice + participant Bob + Alice->>John: Hello John, how are you? + loop Healthcheck + John->>John: Fight against hypochondria + end + Note right of John: Rational thoughts
prevail! + John-->>Alice: Great! + John->>Bob: How about you? + Bob-->>John: Jolly good! +``` + +## List Types + +#### Ordered List + +1. First item +2. Second item +3. Third item + +#### Unordered List + +* List item +* Another item +* And another item + +#### Nested list + +* Fruit + * Apple + * Orange + * Banana +* Dairy + * Milk + * Cheese + +## Math + +[KaTeX](https://github.com/KaTeX/KaTeX) is a fast math typesetting library for the web. It uses javascript for client-side rendering. + +### Inline + +``` +This $\int\limits_1^\infty \frac{1}{k}\,dk$ is inline. +``` + +This $\int\limits_1^\infty \frac{1}{k}\,dk$ is inline. + +### Separate Paragraph + +``` +$$f(x) = \int_{-\infty}^\infty \hat f(\xi)\,e^{2 \pi i \xi x} \,d\xi$$ +``` + +$$f(x) = \int_{-\infty}^\infty \hat f(\xi)\,e^{2 \pi i \xi x} \,d\xi$$ + + +## Other Elements — abbr, sub, sup, kbd, mark + +GIF is a bitmap image format. + +H2O + +Xn + Yn = Zn + +Press CTRL+ALT+Delete to end the session. + +Most salamanders are nocturnal, and hunt for insects, worms, and other small creatures. diff --git a/hugo.toml b/hugo.toml index 0efdbb7..ddf6f3d 100644 --- a/hugo.toml +++ b/hugo.toml @@ -56,8 +56,8 @@ defaultContentLanguage = 'en' pageRef = '/docs' weight = 10 [[menu.main]] - name = 'Showcase' - pageRef = '/showcase' + name = 'Blog' + pageRef = '/blog' weight = 20 [[menu.main]] name = 'About' @@ -81,3 +81,8 @@ defaultContentLanguage = 'en' name = 'Hugo Docs ↗' url = 'https://gohugo.io/documentation/' weight = 20 + +[params] + dateFormat = 'January 2, 2006' + + displayUpdatedDate = true diff --git a/layouts/blog/list.html b/layouts/blog/list.html new file mode 100644 index 0000000..7afab8f --- /dev/null +++ b/layouts/blog/list.html @@ -0,0 +1,21 @@ +{{ define "main" }} +
+ {{ partial "sidebar.html" (dict "context" . "disableSidebar" true) }} +
+
+

{{ .Title }}

+ {{ range .Pages.ByDate }} +
+

{{ .Title }}

+

+ {{- partial "utils/page-description" . }} + Read more → +

+

{{ partial "utils/format-date" .Date }}

+
+ {{ end }} +
+
+ +
+{{ end }} diff --git a/layouts/blog/single.html b/layouts/blog/single.html new file mode 100644 index 0000000..e9317f4 --- /dev/null +++ b/layouts/blog/single.html @@ -0,0 +1,33 @@ +{{ define "main" }} +
+ {{ partial "sidebar.html" (dict "context" . "disableSidebar" true) }} + {{ partial "toc.html" . }} +
+
+ {{ partial "breadcrumb.html" . }} +

{{ .Title }}

+ {{ with $date := .Date }} +
+ {{ partial "utils/format-date" $date }} + {{- if $.Params.authors }} by {{ end -}} + {{- with $.Params.authors }} + {{- range $i, $author := . -}} + {{- if $i }},{{ end -}} + {{- if $author.link }} + {{ $author.name }} + {{ else }} + {{ $author.name }} + {{ end -}} + {{- end -}} + {{- end -}} +
+ {{ end }} +
+ {{ .Content }} +
+
+ {{ partial "pager.html" . }} +
+
+
+{{ end }} diff --git a/layouts/docs/list.html b/layouts/docs/list.html index c896fda..ae0bd28 100644 --- a/layouts/docs/list.html +++ b/layouts/docs/list.html @@ -1,6 +1,6 @@ {{ define "main" }}
- {{ partial "sidebar.html" . }} + {{ partial "sidebar.html" (dict "context" .) }} {{ partial "toc.html" . }}
diff --git a/layouts/docs/single.html b/layouts/docs/single.html index c896fda..ae0bd28 100644 --- a/layouts/docs/single.html +++ b/layouts/docs/single.html @@ -1,6 +1,6 @@ {{ define "main" }}
- {{ partial "sidebar.html" . }} + {{ partial "sidebar.html" (dict "context" .) }} {{ partial "toc.html" . }}
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index e33257b..bba5521 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -1,4 +1,8 @@ +{{- $enableFooterSwitches := .Scratch.Get "enableFooterSwitches" | default false -}} + +
+ {{- if $enableFooterSwitches }}{{ template "footer-switches" }}{{ end -}}
@@ -12,3 +16,9 @@
+ +{{- define "footer-switches" -}} +
+ {{ partial "theme-toggle.html" }} +
+{{- end -}} diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html index 88a8586..3991268 100644 --- a/layouts/partials/sidebar.html +++ b/layouts/partials/sidebar.html @@ -1,3 +1,11 @@ +{{ $context := .context }} +{{ $disableSidebar := .disableSidebar | default false }} + +{{ $navRoot := cond (eq site.Home.Type "docs") site.Home $context.FirstSection }} +{{ $navPages := union $navRoot.RegularPages $navRoot.Sections }} +{{ $pageURL := $context.RelPermalink }} + + +{{- define "sidebar-main" -}} + {{ $pages := .pages }} + {{ $toc := .toc | default false }} + {{ $pageURL := .pageURL }} + + {{- with $pages -}} + {{- range .ByWeight -}} + {{ template "sidebar-item" (dict "item" . "pageURL" $pageURL "toc" $toc) }} + {{ template "sidebar-tree" (dict "context" . "level" 1 "pageURL" $pageURL "toc" $toc) }} + {{- end -}} + {{ end }} +{{- end -}} + {{- define "sidebar-footer" -}} {{- range site.Menus.sidebar -}} {{ if eq .Params.type "separator" }} @@ -113,10 +125,14 @@ {{- $active := eq .pageURL .item.RelPermalink -}} {{- $title := .item.LinkTitle | default .item.File.BaseFileName -}} {{- $link := .item.RelPermalink -}} + {{- $toc := .toc | default false -}}
  • {{ template "sidebar-item-link" dict "active" $active "title" $title "link" $link }} + {{ if and $toc $active }} + {{ template "sidebar-toc" dict "page" .item }} + {{ end }}
  • {{- end -}} @@ -136,20 +152,15 @@ {{- end -}} +{{- define "sidebar-separator" -}} +
    +{{- end -}} + {{- define "theme-switch" -}} - -
    + {{- $class := .class -}} +
    - + {{ partial "theme-toggle" }}
    {{- end -}} diff --git a/layouts/partials/theme-toggle.html b/layouts/partials/theme-toggle.html new file mode 100644 index 0000000..c42fe22 --- /dev/null +++ b/layouts/partials/theme-toggle.html @@ -0,0 +1,8 @@ + diff --git a/layouts/partials/utils/format-date.html b/layouts/partials/utils/format-date.html new file mode 100644 index 0000000..94cbdc4 --- /dev/null +++ b/layouts/partials/utils/format-date.html @@ -0,0 +1,3 @@ +{{- with . -}} + {{- . | time.Format (site.Params.dateFormat | default ":date_long") -}} +{{- end -}} diff --git a/layouts/partials/utils/page-description.html b/layouts/partials/utils/page-description.html new file mode 100644 index 0000000..3529fbe --- /dev/null +++ b/layouts/partials/utils/page-description.html @@ -0,0 +1,11 @@ +{{ with .Description | plainify -}} + {{ . -}} +{{ else -}} + {{ if .IsPage -}} + {{ .Summary | plainify | chomp -}} + {{ else -}} + {{ with .Site.Params.description | plainify -}} + {{ . -}} + {{ end -}} + {{ end -}} +{{ end -}}