🚨 Fix type issues
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -13,5 +13,6 @@ export default defineConfig({
|
|||||||
integrations: [mdx(), alpinejs()],
|
integrations: [mdx(), alpinejs()],
|
||||||
redirects: {
|
redirects: {
|
||||||
'/posts/[...slug]': '/blog/[...slug]',
|
'/posts/[...slug]': '/blog/[...slug]',
|
||||||
|
'/blog': '/blog/page/1',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,11 +25,19 @@ const { title, date, slug } = Astro.props;
|
|||||||
font-size: 1.3rem;
|
font-size: 1.3rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.calendar-icon {
|
|
||||||
transform: translateY(0.3rem);
|
|
||||||
}
|
|
||||||
|
|
||||||
strong {
|
strong {
|
||||||
font-weight: bolder;
|
font-weight: bolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.blog-header {
|
||||||
|
margin: 1rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.blog-header > h2 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.calendar-icon {
|
||||||
|
transform: translateY(0.3rem);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,27 +1,18 @@
|
|||||||
---
|
---
|
||||||
import BlogHeader from '@components/BlogHeader.astro';
|
import BlogHeader from '@components/BlogHeader.astro';
|
||||||
import Tags from '@components/Tags.astro';
|
import Tags from '@components/Tags.astro';
|
||||||
|
import type { CollectionEntry } from 'astro:content';
|
||||||
interface Post {
|
|
||||||
data: {
|
|
||||||
title: string;
|
|
||||||
pubDate: Date;
|
|
||||||
tags: string[];
|
|
||||||
};
|
|
||||||
slug: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
post: Post;
|
post: CollectionEntry<'blog'>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { post } = Astro.props;
|
const { post } = Astro.props;
|
||||||
const { data, slug } = post;
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<article>
|
<article>
|
||||||
<BlogHeader title={post.data.title} date={data.pubDate} slug={slug} />
|
<BlogHeader title={post.data.title} date={post.data.pubDate} slug={post.id} />
|
||||||
<Tags tags={data.tags} />
|
<Tags tags={post.data.tags} />
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -31,6 +22,5 @@ const { data, slug } = post;
|
|||||||
|
|
||||||
article:not(:first-child) {
|
article:not(:first-child) {
|
||||||
border-top: var(--border);
|
border-top: var(--border);
|
||||||
padding-top: 20px;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const { tags } = Astro.props;
|
|||||||
{
|
{
|
||||||
tags.sort().map((tag: string, index: number) => (
|
tags.sort().map((tag: string, index: number) => (
|
||||||
<>
|
<>
|
||||||
<a class="tag" href={`/blog/archive/${tag}`}>
|
<a class="tag" href={`/blog/tag/${tag}`}>
|
||||||
{tag}
|
{tag}
|
||||||
</a>
|
</a>
|
||||||
{index < tags.length - 1 ? ' | ' : ''}
|
{index < tags.length - 1 ? ' | ' : ''}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection, render } from 'astro:content';
|
||||||
|
|
||||||
import Layout from '@layouts/Layout.astro';
|
import Layout from '@layouts/Layout.astro';
|
||||||
import BlogHeader from '@components/BlogHeader.astro';
|
import BlogHeader from '@components/BlogHeader.astro';
|
||||||
@@ -8,7 +8,7 @@ import Tags from '@components/Tags.astro';
|
|||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const posts = await getCollection('blog');
|
const posts = await getCollection('blog');
|
||||||
return posts.map((post) => ({
|
return posts.map((post) => ({
|
||||||
params: { slug: post.slug },
|
params: { slug: post.id },
|
||||||
props: { post },
|
props: { post },
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -17,10 +17,11 @@ const { post } = Astro.props;
|
|||||||
|
|
||||||
const { data } = post;
|
const { data } = post;
|
||||||
|
|
||||||
const { Content } = await post.render();
|
const { Content } = await render(post);
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout title={data.title}>
|
<Layout title={data.title}>
|
||||||
|
<h1></h1>
|
||||||
<article>
|
<article>
|
||||||
<BlogHeader title={data.title} date={data.pubDate} />
|
<BlogHeader title={data.title} date={data.pubDate} />
|
||||||
<Content />
|
<Content />
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
---
|
|
||||||
import { getCollection } from 'astro:content';
|
|
||||||
|
|
||||||
import Layout from '@layouts/Layout.astro';
|
|
||||||
import PostPreview from '@components/PostPreview.astro';
|
|
||||||
|
|
||||||
const posts = await getCollection('blog');
|
|
||||||
---
|
|
||||||
|
|
||||||
<Layout title="Blog">
|
|
||||||
{
|
|
||||||
posts
|
|
||||||
.sort(
|
|
||||||
(a, b) =>
|
|
||||||
new Date(b.data.pubDate).valueOf() -
|
|
||||||
new Date(a.data.pubDate).valueOf()
|
|
||||||
)
|
|
||||||
.slice(0, 10)
|
|
||||||
.map((post) => <PostPreview post={post} />)
|
|
||||||
}
|
|
||||||
{
|
|
||||||
posts.length < 6 ? null : (
|
|
||||||
<div class="all-posts">
|
|
||||||
<a href="/blog/archive/all">All Posts</a>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
</Layout>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.all-posts {
|
|
||||||
text-align: center;
|
|
||||||
padding: 1rem;
|
|
||||||
font-size: 1.2rem;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
---
|
||||||
|
import { getCollection, type CollectionEntry } from 'astro:content';
|
||||||
|
import type { Page } from 'astro';
|
||||||
|
|
||||||
|
import Layout from '@layouts/Layout.astro';
|
||||||
|
import PostPreview from '@components/PostPreview.astro';
|
||||||
|
|
||||||
|
export async function getStaticPaths({ paginate }) {
|
||||||
|
const allPosts = await getCollection('blog');
|
||||||
|
|
||||||
|
allPosts.sort(
|
||||||
|
(a, b) =>
|
||||||
|
Date.parse(String(b.data.pubDate)) - Date.parse(String(a.data.pubDate))
|
||||||
|
);
|
||||||
|
|
||||||
|
return paginate(allPosts, { pageSize: 10 });
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
page: Page<CollectionEntry<'blog'>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { page } = Astro.props;
|
||||||
|
---
|
||||||
|
|
||||||
|
<Layout title="Blog Archive">
|
||||||
|
<ul>
|
||||||
|
{page.data.map((post) => <PostPreview post={post} />)}
|
||||||
|
</ul>
|
||||||
|
<div class="pagination">
|
||||||
|
{
|
||||||
|
page.currentPage !== 1 ? (
|
||||||
|
<a href={`/blog/page/${page.currentPage - 1}`}>Previous</a>
|
||||||
|
) : (
|
||||||
|
<span class="disabled">Previous</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
page.currentPage !== page.lastPage ? (
|
||||||
|
<a href={`/blog/page/${page.currentPage + 1}`}>Next</a>
|
||||||
|
) : (
|
||||||
|
<span class="disabled">Next</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</Layout>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
ul {
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
margin-top: 2rem;
|
||||||
|
margin: auto;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.disabled {
|
||||||
|
color: var(--text);
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -8,6 +8,7 @@ export async function getStaticPaths() {
|
|||||||
const posts = await getCollection('blog');
|
const posts = await getCollection('blog');
|
||||||
|
|
||||||
const tags = ['all'];
|
const tags = ['all'];
|
||||||
|
|
||||||
posts.forEach((post) =>
|
posts.forEach((post) =>
|
||||||
post.data.tags.forEach((tag) => {
|
post.data.tags.forEach((tag) => {
|
||||||
if (!tags.includes(tag)) {
|
if (!tags.includes(tag)) {
|
||||||
@@ -46,14 +47,19 @@ posts.sort(
|
|||||||
);
|
);
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout title="Blog Archive">
|
<Layout title={`Blog - ${tag}`}>
|
||||||
|
<h1>All posts tagged: {tag}</h1>
|
||||||
<ul>
|
<ul>
|
||||||
{
|
{
|
||||||
posts.map(({ slug, data }) => (
|
posts.map((post) => (
|
||||||
<li>
|
<li>
|
||||||
<a href={`/posts/${slug}`}>{data.title}</a> -
|
{console.log(post)}
|
||||||
|
<a href={`/posts/${post.id}`}>{post.data.title}</a> -
|
||||||
<span>
|
<span>
|
||||||
{format(add(new Date(data.pubDate), { hours: 6 }), 'MMM do, y')}
|
{format(
|
||||||
|
add(new Date(post.data.pubDate), { hours: 6 }),
|
||||||
|
'MMM do, y'
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
))
|
))
|
||||||
Reference in New Issue
Block a user