Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add view transitions to post index/detail #7

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/components/Post.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ export interface Props {
title: string;
publishDate: Date;
tags: string[];
slug: string;
}

const { title, publishDate, tags } = Astro.props;
const { title, publishDate, tags, slug } = Astro.props;
---

<article>
<header>
<p class="mb-1 font-mono text-gray-400 sm:mb-2">
<p
class="mb-1 font-mono text-gray-400 sm:mb-2"
transition:name={`post-date-${slug}`}
>
{
publishDate.toLocaleDateString('en-US', {
month: 'long',
Expand All @@ -20,11 +24,21 @@ const { title, publishDate, tags } = Astro.props;
}
</p>

<h2 class="h1 mb-2 text-yellow-400">{title}</h2>
<h2
class="h1 mb-2 text-yellow-400"
transition:name={`post-title-${slug}`}
transition:animate="initial"
>
{title}
</h2>

{
tags ? (
<div class="blog-tags my-4 md:my-6">
<div
class="blog-tags my-4 md:my-6"
transition:name={`post-tags-${slug}`}
transition:animate="initial"
>
{tags.map(
(tag: string) =>
<a class="blog-tag" rel="prefetch" href={`/writing/tags/${tag}`}>{tag}</a>, // prettier-ignore
Expand Down
8 changes: 6 additions & 2 deletions src/components/PostPreview.astro
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const { post } = Astro.props;
<header>
<p
class="mb-1 font-mono text-sm text-gray-400 group-hover:text-green-500 md:mb-2"
transition:name={`post-date-${post.slug}`}
>
{
new Date(post.data.publishDate).toLocaleDateString('en-US', {
Expand All @@ -27,14 +28,17 @@ const { post } = Astro.props;
}
</p>

<h1 class="h1 mb-2 decoration-green-500 group-hover:underline">
<h1
class="h1 mb-2 decoration-green-500 group-hover:underline"
transition:name={`post-title-${post.slug}`}
>
{post.data.title}
</h1>
</header>

{
post.data.tags ? (
<div class="blog-tags my-2">
<div class="blog-tags my-2" transition:name={`post-tags-${post.slug}`}>
{post.data.tags.map((tag) => (
<span class="blog-tag">{tag}</span>
))}
Expand Down
3 changes: 3 additions & 0 deletions src/layouts/Page.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
import { ViewTransitions } from 'astro:transitions';

import BaseHead from '@/components/BaseHead.astro';
import PageHeader from '@/components/PageHeader.astro';

Expand All @@ -9,6 +11,7 @@ const { title, description } = content;
<html lang="en">
<head>
<BaseHead {title} {description} />
<ViewTransitions />
</head>

<body>
Expand Down
5 changes: 4 additions & 1 deletion src/layouts/PostLayout.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import type { CollectionEntry } from 'astro:content';
import { ViewTransitions } from 'astro:transitions';

import BaseHead from '@/components/BaseHead.astro';
import Logo from '@/components/Logo.astro';
Expand All @@ -10,21 +11,23 @@ type Props = {
frontmatter: CollectionEntry<'posts'>['data'];
};

const { slug } = Astro.params as { slug: string };
const { frontmatter } = Astro.props;
const { title, description, publishDate, tags } = frontmatter;
---

<html lang="en">
<head>
<BaseHead {title} {description} />
<ViewTransitions />
</head>

<body>
<PageHeader />

<main id="content" class="container mx-auto my-4 max-w-3xl px-4">
<div class="mt-8 sm:mt-12 md:mt-16">
<Post {title} {publishDate} {tags}>
<Post {title} {publishDate} {tags} {slug}>
<slot />
</Post>
</div>
Expand Down