-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support themes via tailwind (#33)
- Loading branch information
Showing
28 changed files
with
462 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default function TagLink({ tag }: { tag: string }) { | ||
return ( | ||
<a | ||
id={`tag-link-${tag}`} | ||
href={`/archive/${tag}`} | ||
class="border border-light-mutedBackground dark:border-dark-mutedBackground text-light-mutedForeground dark:text-dark-mutedForeground py-1 px-2 rounded-lg inline-block hover:bg-light-mutedBackground dark:hover:bg-dark-mutedBackground" | ||
> | ||
{tag} | ||
</a> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import TagLink from "./TagLink.tsx"; | ||
|
||
export default function Tags({ tags, id }: { tags: string[]; id?: string }) { | ||
return ( | ||
<div class="flex space-x-2" id={id}> | ||
{tags.some((x) => x != null) && | ||
tags.map((tag, index) => <TagLink tag={tag} key={index} />)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,67 @@ | ||
import { BlogOptions } from "../plugin/blog.ts"; | ||
import { useSignal } from "https://esm.sh/*@preact/[email protected]"; | ||
import { useSignal } from "@preact/signals"; | ||
import ThemeToggle from "./ThemeToggle.tsx"; | ||
|
||
export default function NavigationBar( | ||
props: { active: string; class?: string; options: BlogOptions }, | ||
props: { class?: string; options: BlogOptions }, | ||
) { | ||
const isHome = props.active == "/"; | ||
const isOpen = useSignal(false); | ||
return ( | ||
<header class="sticky top-0 w-full z-10"> | ||
<div class="flex justify-between items-center px-4 py-2"> | ||
<a href="/" class="text-5xl font-bold"> | ||
{props.options.title} | ||
</a> | ||
<label | ||
class="lg:hidden cursor-pointer z-20" | ||
onClick={() => isOpen.value = !isOpen.value} | ||
<div> | ||
<label | ||
class="lg:hidden cursor-pointer z-10 relative" | ||
onClick={() => isOpen.value = !isOpen.value} | ||
> | ||
<span | ||
class={`${ | ||
isOpen.value | ||
? "block h-1 w-6 bg-light-foreground dark:bg-dark-foreground transform rotate-45" | ||
: "block h-1 w-6 bg-light-foreground dark:bg-dark-foreground" | ||
}`} | ||
> | ||
</span> | ||
<span | ||
class={`${ | ||
isOpen.value | ||
? "block h-1 w-6 bg-light-foreground dark:bg-dark-foreground my-1 opacity-0" | ||
: "block h-1 w-6 bg-light-foreground dark:bg-dark-foreground my-1" | ||
}`} | ||
> | ||
<span | ||
class={`${ | ||
isOpen.value | ||
? "block h-1 w-6 bg-black transform rotate-45" | ||
: "block h-1 w-6 bg-black" | ||
}`} | ||
> | ||
</span> | ||
<span | ||
class={`${ | ||
isOpen.value | ||
? "block h-1 w-6 bg-black my-1 opacity-0" | ||
: "block h-1 w-6 bg-black my-1" | ||
}`} | ||
> | ||
</span> | ||
<span | ||
class={`${ | ||
isOpen.value | ||
? "block h-1 w-6 bg-black transform -rotate-45" | ||
: "block h-1 w-6 bg-black" | ||
}`} | ||
> | ||
</span> | ||
</label> | ||
<nav | ||
</span> | ||
<span | ||
class={`${ | ||
isOpen.value | ||
? "w-full fixed top-0 left-0 overflow-hidden transition-max-height duration-500 lg:relative max-h-screen bg-gray-300" | ||
: "w-full fixed top-0 left-0 overflow-hidden transition-max-height duration-500 lg:relative max-h-0 lg:max-h-full" | ||
? "block h-1 w-6 bg-light-foreground dark:bg-dark-foreground transform -rotate-45" | ||
: "block h-1 w-6 bg-light-foreground dark:bg-dark-foreground" | ||
}`} | ||
> | ||
<ul class="flex flex-col lg:flex-row justify-center items-center gap-4 mx-4 my-6 flex-wrap"> | ||
{Object.entries(props.options.navbarItems).map(([key, value]) => ( | ||
<li key={key}> | ||
<a | ||
href={value} | ||
class={`p-2 block hover:underline ${ | ||
isHome | ||
? props.active == value | ||
? "text-black-900 font-bold" | ||
: "text-black-900" | ||
: props.active == value | ||
? "text-black-600 font-bold" | ||
: "text-black-600" | ||
}`} | ||
> | ||
{key} | ||
</a> | ||
</li> | ||
))} | ||
</ul> | ||
</nav> | ||
</div> | ||
</header> | ||
</span> | ||
</label> | ||
<h2 id="primary-navigation" class="sr-only">Primary Navigation</h2> | ||
<nav | ||
aria-labelledby="primary-navigation" | ||
class={`${ | ||
isOpen.value | ||
? "w-full fixed top-0 left-0 overflow-hidden transition-max-height duration-500 lg:relative max-h-screen bg-light-mutedBackground dark:bg-dark-mutedBackground" | ||
: "w-full fixed top-0 left-0 overflow-hidden transition-max-height duration-500 lg:relative max-h-0 lg:max-h-full" | ||
}`} | ||
> | ||
<ul class="flex flex-col lg:flex-row justify-center items-center gap-4 mx-0 flex-wrap"> | ||
{Object.entries(props.options.navbarItems).map(([key, value]) => ( | ||
<li key={key}> | ||
<a | ||
href={value} | ||
class="p-2 hover:underline aria-[current='page']:font-bold" | ||
> | ||
{key} | ||
</a> | ||
</li> | ||
))} | ||
<li> | ||
<ThemeToggle /> | ||
</li> | ||
</ul> | ||
</nav> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { useSignal } from "@preact/signals"; | ||
|
||
const sun = ( | ||
<svg | ||
class="w-6 h-6" | ||
aria-hidden="true" | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="currentColor" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
fill-rule="evenodd" | ||
d="M13 3a1 1 0 1 0-2 0v2a1 1 0 1 0 2 0V3ZM6.3 5A1 1 0 0 0 5 6.2l1.4 1.5a1 1 0 0 0 1.5-1.5L6.3 5Zm12.8 1.3A1 1 0 0 0 17.7 5l-1.5 1.4a1 1 0 0 0 1.5 1.5L19 6.3ZM12 7a5 5 0 1 0 0 10 5 5 0 0 0 0-10Zm-9 4a1 1 0 1 0 0 2h2a1 1 0 1 0 0-2H3Zm16 0a1 1 0 1 0 0 2h2a1 1 0 1 0 0-2h-2ZM7.8 17.7a1 1 0 1 0-1.5-1.5L5 17.7A1 1 0 1 0 6.3 19l1.5-1.4Zm9.9-1.5a1 1 0 0 0-1.5 1.5l1.5 1.4a1 1 0 0 0 1.4-1.4l-1.4-1.5ZM13 19a1 1 0 1 0-2 0v2a1 1 0 1 0 2 0v-2Z" | ||
clip-rule="evenodd" | ||
/> | ||
</svg> | ||
); | ||
|
||
const moon = ( | ||
<svg | ||
class="w-6 h-6" | ||
aria-hidden="true" | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="currentColor" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
fill-rule="evenodd" | ||
d="M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z" | ||
clip-rule="evenodd" | ||
/> | ||
</svg> | ||
); | ||
|
||
export default function ThemeToggle() { | ||
const currentTheme = localStorage.getItem("theme") ?? "light"; | ||
const isDarkMode = useSignal(currentTheme === "dark"); | ||
|
||
const toggleTheme = () => { | ||
isDarkMode.value = !isDarkMode.value; | ||
const theme = isDarkMode.value ? "dark" : "light"; | ||
|
||
document.documentElement.classList.toggle("dark", isDarkMode.value); | ||
const markdownBody = document.getElementById("markdown-body"); | ||
if (markdownBody) { | ||
markdownBody.setAttribute( | ||
"data-color-mode", | ||
isDarkMode.value ? "dark" : "light", | ||
); | ||
} | ||
|
||
document.cookie = `theme=${theme};path=/;max-age=31536000;SameSite=Lax`; | ||
localStorage.setItem("theme", theme); | ||
}; | ||
|
||
return ( | ||
<button onClick={toggleTheme} class="p-2 inline-block"> | ||
{isDarkMode.value ? sun : moon} | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.