-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
297 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
import { useState } from "preact/hooks" | ||
import useOuterClick from "#hooks/useOuterClick" | ||
import { JSX } from "preact/jsx-runtime" | ||
import { languageTag, sourceLanguageTag } from "#lang/paraglide/runtime" | ||
import Check from "~icons/eva/checkmark-outline" | ||
import { navigate } from "vike/client/router" | ||
|
||
type functionOption = { | ||
label: string | ||
function: () => void | ||
} | ||
|
||
type linkOption = { | ||
label: string | ||
link: string | ||
} | ||
|
||
export default function Picker(props: { | ||
position: "top" | "bottom" | ||
align: "right" | "left" | ||
options: (functionOption | linkOption)[] | ||
children: JSX.Element | ||
}) { | ||
const [open, setOpen] = useState(false) | ||
const elementsList = useOuterClick(() => { | ||
if (open) setOpen(false) | ||
}) | ||
|
||
return ( | ||
<div class="flex items-center relative"> | ||
<button | ||
onClick={() => (open ? setOpen(false) : setOpen(true))} | ||
class={ | ||
"text-xl p-1 rounded-md transition-colors hover:text-black hover:bg-zinc-100 before:opacity-0 dark:hover:text-white dark:hover:bg-zinc-900 " + | ||
(open | ||
? "text-black dark:text-white bg-zinc-100 dark:bg-zinc-900" | ||
: "text-zinc-400") | ||
} | ||
> | ||
{props.children} | ||
</button> | ||
<div | ||
// @ts-ignore | ||
ref={elementsList} | ||
class={ | ||
"absolute z-10 bg-zinc-50 border border-zinc-200 rounded-md flex flex-col transition-all overflow-hidden dark:bg-zinc-950 dark:border-zinc-800 " + | ||
(props.align === "left" ? "left-0 " : "right-0 ") + | ||
(open | ||
? "opacity-100 " + | ||
(props.position === "top" ? "bottom-9 " : "top-9 ") | ||
: "opacity-0 pointer-events-none " + | ||
(props.position === "top" ? "bottom-4 " : "top-4 ")) | ||
} | ||
> | ||
{props.options.map((option) => { | ||
return ( | ||
<a | ||
class={ | ||
"px-3 py-1.5 cursor-pointer transition-colors hover:bg-zinc-100 flex items-center gap-1.5 justify-start dark:hover:bg-zinc-900 " + | ||
(props.options.length - 1 === props.options.indexOf(option) | ||
? "" | ||
: " border-b border-b-zinc-200 dark:border-b-zinc-800") | ||
} | ||
href={"link" in option ? option.link : undefined} | ||
onClick={"function" in option ? option.function : undefined} | ||
> | ||
<p class="w-auto truncate">{option.label}</p> | ||
</a> | ||
) | ||
})} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
type Language = { | ||
name: string | ||
languageTag: string | ||
link: string | ||
} | ||
|
||
export function LanguagePicker(props: { | ||
position: "top" | "bottom" | ||
align: "right" | "left" | ||
}) { | ||
const [open, setOpen] = useState(false) | ||
const elementsList = useOuterClick(() => { | ||
if (open) setOpen(false) | ||
}) | ||
|
||
const languages = [ | ||
{ | ||
name: "English", | ||
languageTag: sourceLanguageTag, | ||
link: "/", | ||
}, | ||
{ | ||
name: "Chinese", | ||
languageTag: "zh", | ||
link: "/zh", | ||
}, | ||
] as Language[] | ||
|
||
return ( | ||
<div class="flex items-center relative"> | ||
<button | ||
onClick={() => (open ? setOpen(false) : setOpen(true))} | ||
class={ | ||
"text-xl p-1 rounded-md transition-colors hover:text-black hover:bg-zinc-100 before:opacity-0 dark:hover:text-white dark:hover:bg-zinc-900 " + | ||
(open | ||
? "text-black dark:text-white bg-zinc-100 dark:bg-zinc-900" | ||
: "text-zinc-400") | ||
} | ||
> | ||
<LanguageIcon /> | ||
</button> | ||
<div | ||
// @ts-ignore | ||
ref={elementsList} | ||
class={ | ||
"absolute z-10 bg-zinc-50 border border-zinc-200 rounded-md flex flex-col transition-all overflow-hidden dark:bg-zinc-950 dark:border-zinc-800 " + | ||
// (props.position === "top" ? "bottom-8 " : "top-8 ") + | ||
(props.align === "left" ? "left-0 " : "right-0 ") + | ||
(open | ||
? "opacity-100 " + | ||
(props.position === "top" ? "bottom-9 " : "top-9 ") | ||
: "opacity-0 pointer-events-none " + | ||
(props.position === "top" ? "bottom-4 " : "top-4 ")) | ||
} | ||
> | ||
{languages.map((locale) => { | ||
return ( | ||
<a | ||
class={ | ||
"px-3 py-1.5 transition-colors hover:bg-zinc-100 flex items-center gap-1.5 justify-end dark:hover:bg-zinc-900 " + | ||
(languages.length - 1 === languages.indexOf(locale) | ||
? "" | ||
: " border-b border-b-zinc-200 dark:border-b-zinc-800") | ||
} | ||
href={locale.link} | ||
onClick={(e) => { | ||
e.preventDefault() | ||
navigate(locale.link).then(() => | ||
window.open(locale.link, "_self") | ||
) | ||
}} | ||
> | ||
{locale.languageTag === languageTag() && <Check />} | ||
<p class="w-16">{locale.name}</p> | ||
</a> | ||
) | ||
})} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
function LanguageIcon() { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="currentColor" | ||
width="1em" | ||
height="1em" | ||
viewBox="0 0 512 512" | ||
> | ||
<title>ionicons-v5-l</title> | ||
<path d="M478.33,433.6l-90-218a22,22,0,0,0-40.67,0l-90,218a22,22,0,1,0,40.67,16.79L316.66,406H419.33l18.33,44.39A22,22,0,0,0,458,464a22,22,0,0,0,20.32-30.4ZM334.83,362,368,281.65,401.17,362Z" /> | ||
<path d="M267.84,342.92a22,22,0,0,0-4.89-30.7c-.2-.15-15-11.13-36.49-34.73,39.65-53.68,62.11-114.75,71.27-143.49H330a22,22,0,0,0,0-44H214V70a22,22,0,0,0-44,0V90H54a22,22,0,0,0,0,44H251.25c-9.52,26.95-27.05,69.5-53.79,108.36-31.41-41.68-43.08-68.65-43.17-68.87a22,22,0,0,0-40.58,17c.58,1.38,14.55,34.23,52.86,83.93.92,1.19,1.83,2.35,2.74,3.51-39.24,44.35-77.74,71.86-93.85,80.74a22,22,0,1,0,21.07,38.63c2.16-1.18,48.6-26.89,101.63-85.59,22.52,24.08,38,35.44,38.93,36.1a22,22,0,0,0,30.75-4.9Z" /> | ||
</svg> | ||
) | ||
} |
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,29 @@ | ||
export default function Markdown(props: { class?: string; content: string }) { | ||
// Regular expression pattern to capture video ID and image source | ||
const pattern = | ||
/<a\s+href="([A-Za-z0-9_-]{11})"\s*><img\s+src="([^"]+)"[^>]+><\/a>/g | ||
|
||
// Replace the matches with the cover image and add click event | ||
const replacedContent = props.content.replace( | ||
pattern, | ||
(match, videoId, imgSrc) => `<div | ||
class="video-container" | ||
onclick="this.innerHTML = '<iframe width="100%" height="100%" style="aspect-ratio: 16/9" src="https://www.youtube.com/embed/${videoId}?autoplay=1" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" frameborder="0" allowfullscreen autoplay></iframe>';" | ||
style="cursor: pointer; width: 100%; height: auto;"> | ||
<div class="video-wrapper"> | ||
<img | ||
src="${imgSrc}" | ||
class="video-overlay" | ||
alt="Video cover" | ||
style="width: 100%; height: auto;" | ||
/> | ||
</div> | ||
</div>` | ||
) | ||
|
||
return ( | ||
<article className={props.class}> | ||
<div dangerouslySetInnerHTML={{ __html: replacedContent }}></div> | ||
</article> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,11 +1,10 @@ | ||
import "#design-system/markdown.css" | ||
import Markdown from "#markdown/Markdown" | ||
|
||
export default function Page(props: Record<string, string>) { | ||
return ( | ||
<> | ||
<article class="lg:py-16 pb-16"> | ||
<div dangerouslySetInnerHTML={{ __html: props.content }}></div> | ||
</article> | ||
<Markdown class="lg:py-16 pb-16" content={props.content} /> | ||
</> | ||
) | ||
} |
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,11 +1,41 @@ | ||
import Picker from "#components/Picker" | ||
import "#design-system/feed.css" | ||
import Markdown from "#markdown/Markdown" | ||
import { useState } from "preact/hooks" | ||
import Share from "~icons/eva/share-outline" | ||
|
||
export default function Page(props: Record<string, string>) { | ||
const [copyLabel, setCopyLabel] = useState("Copy link") | ||
return ( | ||
<> | ||
<article class="lg:py-16 pb-16 max-w-lg mx-auto"> | ||
<div dangerouslySetInnerHTML={{ __html: props.content }}></div> | ||
</article> | ||
<div> | ||
<Markdown class="lg:mt-16 max-w-lg mx-auto" content={props.content} /> | ||
</div> | ||
<div class="flex items-center justify-end mb-16 mx-auto max-w-lg"> | ||
<Picker | ||
options={[ | ||
{ | ||
label: copyLabel, | ||
function: () => { | ||
// copy to clipboard the current page's url | ||
navigator.clipboard.writeText( | ||
typeof window !== "undefined" | ||
? window.location.href.replace(/\/$/, "") | ||
: "" | ||
) | ||
setCopyLabel("Copied!") | ||
setTimeout(() => { | ||
setCopyLabel("Copy link") | ||
}, 1000) | ||
}, | ||
}, | ||
]} | ||
position="top" | ||
align="right" | ||
> | ||
<Share /> | ||
</Picker> | ||
</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
Oops, something went wrong.
0ed980d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
florians-site-preview – ./
florians-site-preview.vercel.app
florians-site-preview-flornkm.vercel.app
florians-site-preview-git-new-portfolio-flornkm.vercel.app
preview.floriankiem.com