Skip to content
This repository was archived by the owner on Jan 1, 2025. It is now read-only.

Commit 784cb63

Browse files
view transition updates (#18)
1 parent b7eec6b commit 784cb63

File tree

10 files changed

+72
-13
lines changed

10 files changed

+72
-13
lines changed

.changeset/friendly-pets-boil.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@matthiesenxyz/astro-hashnode": patch
3+
---
4+
5+
view transition updates

package/src/components/Author.astro

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,24 @@ const { post } = Astro.props;
2020
height={50}
2121
class="rounded-3xl mr-3"
2222
loading="eager"
23+
transition:animate={"fade"}
24+
transition:name={'author:' + post.author.profilePicture}
2325
/>
2426
<div class="mt-3 flex">
25-
<span>{post.author.name}</span>
27+
<span transition:animate={"fade"}
28+
transition:name={'author:' + post.author.name}
29+
>{post.author.name}</span>
2630
<span class="mx-3 block font-bold text-slate-500">.</span>
2731
</div>
2832
</div>
2933
</div>
30-
<div class="mb-5 flex w-full flex-row items-center justify-center md:mb-0 md:w-auto md:justify-start">
31-
<span>{getFormattedDate(post.publishedAt)}</span>
34+
<div class="mb-5 flex w-full flex-row items-center justify-center md:mb-0 md:w-auto md:justify-start" >
35+
<span transition:animate={"fade"}
36+
transition:name={'hero:' + post.publishedAt}
37+
>{getFormattedDate(post.publishedAt)}</span>
3238
<span class="mx-3 block font-bold text-slate-500">.</span>
33-
<span>{post.readTimeInMinutes} min read</span>
39+
<span transition:animate={"fade"}
40+
transition:name={'hero:' + post.readTimeInMinutes}
41+
>{post.readTimeInMinutes} min read</span>
3442
</div>
3543
</div>

package/src/components/Header.astro

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ const aboutPageData = await getAboutPage();
77
88
const baseURL = import.meta.env.BASE_URL;
99
10+
const pathname = new URL(Astro.request.url).pathname;
11+
12+
// remove leading and trailing slash
13+
const removeTrailingAndLeadingSlash = (str:string) => {
14+
// define checked string as the original string
15+
let checkedStr = str;
16+
17+
// remove leading slash
18+
if (str.startsWith("/")) {
19+
checkedStr = str.slice(1);
20+
}
21+
// remove trailing slash
22+
if (str.endsWith("/")) {
23+
checkedStr = str.slice(0, -1);
24+
}
25+
// return checked string
26+
return checkedStr;
27+
}
28+
29+
const currentPath = removeTrailingAndLeadingSlash(pathname);
30+
1031
---
1132
<header class="flex bg-blue-200 w-full p-3">
1233
<h1 class="text-2xl">
@@ -35,8 +56,22 @@ const baseURL = import.meta.env.BASE_URL;
3556
</a>
3657
</h1>
3758
<div class="ml-5 pt-0.5 text-lg">
38-
<a class="mr-3" href={baseURL}>Home</a>
39-
<a class="mr-3" href={`${baseURL}blog`}>Blog</a>
40-
{aboutPageData && <a href={`${baseURL}blog/about/`}>About</a>}
59+
<a
60+
class=`mr-3 ${currentPath === "" ? "font-bold" : ""}`
61+
href={baseURL}
62+
>Home
63+
</a>
64+
<a
65+
class=`mr-3 ${currentPath === "blog" ? "font-bold" : ""}`
66+
href={`${baseURL}blog`}
67+
>Blog
68+
</a>
69+
{ aboutPageData && (
70+
<a
71+
class=`mr-3 ${currentPath === "blog/about" ? "font-bold" : ""}`
72+
href={`${baseURL}blog/about`}
73+
>About
74+
</a>
75+
) }
4176
</div>
4277
</header>

package/src/components/PostCard.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const p = await getPost(post.slug);
2626
src={p.coverImage.url}
2727
alt={post.title}
2828
inferSize={true}
29+
transition:name={'hero:' + p.coverImage.url}
2930
/>
3031
<div class="flex flex-col m-4">
3132
<p class="mb-2 text-lg">{post.brief}</p>

package/src/layouts/Layout.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const { pageTitle, hideFooter, hideHeader, ogImage } = Astro.props as AstroHashn
6262
</head>
6363
<body>
6464
<div class="flex flex-col">
65-
{!hideHeader && <Header />}
65+
{!hideHeader && <Header transition:animate="none" />}
6666
<div class="flex flex-wrap flex-col mt-0 mr-auto mb-0 ml-auto lg:w-[60%]">
6767
<slot />
6868
</div>

package/src/pages/blog/[slug].astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ const post = await getPost(slug);
2828
alt={post.title}
2929
inferSize={true}
3030
loading="eager"
31+
transition:name={'hero:' + post.coverImage.url}
3132
/>
32-
<h1 class="text-4xl font-bold pt-5">{post.title}</h1>
33+
<h1 class="text-4xl font-bold pt-5" transition:name={'banner'} transition:animate={'fade'}>{post.title}</h1>
3334
<h2 class="text-xl pt-3 pb-3" aria-label="CoverPhoto Subtitle">{post.subtitle}</h2>
3435

35-
<Author post={post} />
36+
<Author post={post}/>
3637

3738
<div class="flex flex-wrap justify-center items-center mt-5 mb-5">
3839
{post.tags && post.tags.map((tag) => <Tag tag={tag} />)}

package/src/pages/blog/about.astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const data = await getAboutPage();
99

1010
<Layout pageTitle="About">
1111
<div class="flex flex-col justify-center p-2">
12-
<h2 class="text-3xl mb-3">{data.title} Page</h2>
12+
<h2 class="text-3xl mb-3"
13+
transition:name={'banner'}
14+
transition:animate={'fade'}>{data.title}</h2>
1315
<div class="about-content">
1416
<Markdown content={data.content.markdown}
1517
components={{

package/src/pages/blog/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const allPosts = data.publication.posts.edges;
1010
---
1111
<Layout pageTitle="Blog">
1212
<div class="flex flex-col justify-center items-center p-2">
13-
<h2 class="text-2xl pt-2 font-semibold">{`Welcome to ${pub.displayTitle || pub.title}`}</h2>
13+
<h2 transition:animate={'fade'} transition:name={'banner'} class="text-2xl pt-2 font-semibold">{`Welcome to ${pub.displayTitle || pub.title}`}</h2>
1414
<Posts allPosts={allPosts}/>
1515

1616
</div>

package/src/pages/index.astro

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ import background from "../assets/blog.jpg";
1313
height={1080}
1414
width={1920}
1515
loading="eager"
16+
transition:name={'background:' + background}
17+
transition:animate={'fade'}
1618
/>
17-
<div class="absolute p-2 flex flex-col justify-center items-center z-10 bg-purple-50 lg:w-2/5 h-1/4 rounded-md">
19+
<div
20+
class="absolute p-2 flex flex-col justify-center items-center z-10 bg-purple-50 lg:w-2/5 h-1/4 rounded-md"
21+
transition:name={'banner'}
22+
transition:animate={'fade'}
23+
>
1824
<div class="flex pb-5 mb-5 text-5xl text-purple-800">
1925
<p>Hashnode Blog</p>
2026
</div>

package/src/pages/ssr-pages/[slug].astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const post = await getPost(checkSlug(slug));
2727
alt={post.title}
2828
inferSize={true}
2929
loading="eager"
30+
transition:name={'hero:' + post.coverImage.url}
3031
/>
3132
<h1 class="text-4xl font-bold pt-5">{post.title}</h1>
3233
<h2 class="text-xl pt-3 pb-3" aria-label="CoverPhoto Subtitle">{post.subtitle}</h2>

0 commit comments

Comments
 (0)