Skip to content

Commit

Permalink
fix: canva container (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
rqbazan authored Dec 6, 2024
1 parent bc674b4 commit b6756cc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 37 deletions.
22 changes: 9 additions & 13 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,16 @@ import { getImageUrl } from "~/utils/get-image-url";
</Fragment>
</Heading>

<CoverImgContainer>
<Fragment slot="image">
<CoverCanva src={getImageUrl("covers/opulento-v2")}>
{/* @ts-expect-error */}
<Opulento id="canva-container" client:load />
</CoverCanva>
<CoverCanva src={getImageUrl("covers/opulento-v2")}>
<Fragment slot="canva">
{/* @ts-expect-error */}
<Opulento id="canva-container" client:load />
</Fragment>
<Fragment slot="description">
<p class="small text-muted">
Opulento by
<Anchor href="https://troyni.com">Troy Ni</Anchor> on <Anchor
href="https://uvcanvas.com">uvcanvas.com</Anchor
>
</p>
Opulento by
<Anchor href="https://troyni.com">Troy Ni</Anchor> on <Anchor
href="https://uvcanvas.com">uvcanvas.com</Anchor
>
</Fragment>
</CoverImgContainer>
</CoverCanva>
</DefaultLayout>
13 changes: 5 additions & 8 deletions src/pages/projects/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ 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,20 +24,18 @@ import ProjectPost from "./_components/project-post.astro";
</Fragment>
</Heading>

<CoverImgContainer class="mb-9">
<Fragment slot="image">
<ConverCanva src={getImageUrl("covers/novatrix-v2")}>
{/* @ts-expect-error */}
<Novatrix id="canva-container" client:load />
</ConverCanva>
<ConverCanva class="mb-9" src={getImageUrl("covers/novatrix-v2")}>
<Fragment slot="canva">
{/* @ts-expect-error */}
<Novatrix id="canva-container" client:load />
</Fragment>
<Fragment slot="description">
Novatrix by
<Anchor href="https://troyni.com">Troy Ni</Anchor> on <Anchor
href="https://uvcanvas.com">uvcanvas.com</Anchor
>
</Fragment>
</CoverImgContainer>
</ConverCanva>

<div class="flex flex-col space-y-8">
<ProjectPost
Expand Down
23 changes: 8 additions & 15 deletions src/ui/components/conver-canva.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
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";
Expand All @@ -16,15 +15,9 @@ 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"
>
<ImgFrame class="aspect-cover relative">
<slot name="canva" id="canva-container" />
<div id="image-container" class="w-full h-full absolute inset-0">
<Image
src={src}
width={672}
Expand All @@ -33,9 +26,9 @@ const placeholder = await getImagePlaceholder(src);
background={placeholder}
priority
fetchpriority="high"
class="aspect-[4/3] w-full h-full"
class="aspect-cover w-full h-full"
/>
</a>
</div>
</ImgFrame>
</Fragment>
<Fragment slot="description">
Expand All @@ -51,9 +44,9 @@ const placeholder = await getImagePlaceholder(src);
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";
const containerEl = document.getElementById("image-container");
if (containerEl) {
containerEl.style.opacity = "0";
}
observer.disconnect();
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/cover-img.astro
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const placeholder = await getImagePlaceholder(src);
background={placeholder}
priority
fetchpriority="high"
class="aspect-[4/3] w-full h-full"
class="aspect-cover w-full h-full"
/>
</a>
</ImgFrame>
Expand Down
3 changes: 3 additions & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ const config = {
small: "0.75rem",
tiny: "0.5rem",
},
aspectRatio: {
cover: "4/3",
},
},
},
plugins: [require("tailwindcss-animate")],
Expand Down

0 comments on commit b6756cc

Please sign in to comment.