Skip to content

Commit

Permalink
add cover canva
Browse files Browse the repository at this point in the history
  • Loading branch information
rqbazan committed Dec 6, 2024
1 parent 3017c77 commit 56f148e
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 16 deletions.
9 changes: 7 additions & 2 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { Opulento } from "uvcanvas";
import Heading from "~/layouts/default/components/heading.astro";
import DefaultLayout from "~/layouts/default/index.astro";
import Anchor from "~/ui/components/anchor.astro";
import CoverCanva from "~/ui/components/conver-canva.astro";
import CoverImgContainer from "~/ui/components/cover-img-container.astro";
import { getImageUrl } from "~/utils/get-image-url";
---

<DefaultLayout title="Ricardo Q. Bazan | Software Engineer">
Expand All @@ -28,9 +30,12 @@ import CoverImgContainer from "~/ui/components/cover-img-container.astro";
</Fragment>
</Heading>

<CoverImgContainer class="mb-9">
<CoverImgContainer>
<Fragment slot="image">
<Opulento client:load />
<CoverCanva src={getImageUrl("covers/opulento-v2")}>
{/* @ts-expect-error */}
<Opulento id="canva-container" client:load />
</CoverCanva>
</Fragment>
<Fragment slot="description">
<p class="small text-muted">
Expand Down
7 changes: 6 additions & 1 deletion src/pages/projects/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { Novatrix } from "uvcanvas";
import Heading from "~/layouts/default/components/heading.astro";
import DefaultLayout from "~/layouts/default/index.astro";
import Anchor from "~/ui/components/anchor.astro";
import ConverCanva from "~/ui/components/conver-canva.astro";
import CoverImgContainer from "~/ui/components/cover-img-container.astro";
import { getImageUrl } from "~/utils/get-image-url";
import ProjectPost from "./_components/project-post.astro";
---

Expand All @@ -25,7 +27,10 @@ import ProjectPost from "./_components/project-post.astro";

<CoverImgContainer class="mb-9">
<Fragment slot="image">
<Novatrix client:load />
<ConverCanva src={getImageUrl("covers/novatrix-v2")}>
{/* @ts-expect-error */}
<Novatrix id="canva-container" client:load />
</ConverCanva>
</Fragment>
<Fragment slot="description">
Novatrix by
Expand Down
68 changes: 68 additions & 0 deletions src/ui/components/conver-canva.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
import { Image } from "@unpic/astro";
import { Opulento } from "uvcanvas";
import { getImagePlaceholder } from "~/utils/get-image-placeholder";
import CoverImgContainer from "./cover-img-container.astro";
import ImgFrame from "./img-frame.astro";
interface Props {
src: string;
class?: string;
}
const { src, class: className } = Astro.props;
const placeholder = await getImagePlaceholder(src);
---

<CoverImgContainer class={className}>
<Fragment slot="image">
<ImgFrame class="aspect-[4/3] relative">
<slot id="canva-container" />
<a
id="image-link"
href={src}
target="_blank"
rel="noreferrer"
class="w-full h-full absolute inset-0"
>
<Image
src={src}
width={672}
height={504}
placeholder="blurhash"
background={placeholder}
priority
fetchpriority="high"
class="aspect-[4/3] w-full h-full"
/>
</a>
</ImgFrame>
</Fragment>
<Fragment slot="description">
<slot name="description" />
</Fragment>
</CoverImgContainer>

<script>
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
const { target } = mutation;

if ("querySelector" in target) {
const canvas = (target as HTMLElement).querySelector("canvas");
if (canvas) {
const imgLinkEl = document.getElementById("image-link");
if (imgLinkEl) {
imgLinkEl.style.opacity = "0";
}
observer.disconnect();
}
}
});
});

const containerEl = document.getElementById("canva-container");
if (containerEl) {
observer.observe(containerEl, { childList: true, subtree: true });
}
</script>
5 changes: 2 additions & 3 deletions src/ui/components/cover-img-container.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import { cn } from "~/utils/cn";
import ImgFrame from "./img-frame.astro";
interface Props {
description?: string;
Expand All @@ -11,9 +12,7 @@ const { class: className } = Astro.props;

<div class={cn(className, "flex flex-col items-center")}>
<div class="select-none w-full mb-3">
<div class="md:border-8 border-[6px] aspect-[4/3]">
<slot name="image" />
</div>
<slot name="image" />
</div>
<p class="small text-muted">
<slot name="description" />
Expand Down
24 changes: 14 additions & 10 deletions src/ui/components/cover-img.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Image } from "@unpic/astro";
import { getImagePlaceholder } from "~/utils/get-image-placeholder";
import CoverImgContainer from "./cover-img-container.astro";
import ImgFrame from "./img-frame.astro";
interface Props {
src: string;
Expand All @@ -17,16 +18,19 @@ const placeholder = await getImagePlaceholder(src);

<CoverImgContainer class={className}>
<Fragment slot="image">
<a href={src} target="_blank" rel="noreferrer" class="w-full h-full">
<Image
{...otherProps}
src={src}
placeholder="blurhash"
background={placeholder}
priority
fetchpriority="high"
/>
</a>
<ImgFrame>
<a href={src} target="_blank" rel="noreferrer" class="w-full h-full">
<Image
{...otherProps}
src={src}
placeholder="blurhash"
background={placeholder}
priority
fetchpriority="high"
class="aspect-[4/3] w-full h-full"
/>
</a>
</ImgFrame>
</Fragment>
<Fragment slot="description">
<slot name="description" />
Expand Down
13 changes: 13 additions & 0 deletions src/ui/components/img-frame.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
import { cn } from "~/utils/cn";
interface Props {
class?: string;
}
const { class: className } = Astro.props;
---

<div class={cn(className, "md:border-8 border-[6px]")}>
<slot />
</div>

0 comments on commit 56f148e

Please sign in to comment.