From 94dbf50db8bab80e38bda69377cc6456c0ad7f50 Mon Sep 17 00:00:00 2001 From: piro-hiroki Date: Sat, 9 Mar 2024 21:24:45 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20Error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Card.tsx | 2 +- src/components/Search.tsx | 6 +++--- src/layouts/Policies.astro | 2 +- src/layouts/PolicyDetails.astro | 5 +---- src/layouts/PostDetails.astro | 2 +- src/layouts/Posts.astro | 2 +- src/layouts/TagPosts.astro | 2 +- src/pages/posts/[slug]/index.astro | 2 +- src/pages/posts/[slug]/index.png.ts | 9 ++++++--- src/pages/privacy-policies/[slug]/index.png.ts | 9 ++++++--- src/pages/tags/[tag]/[page].astro | 2 +- src/utils/generateOgImages.tsx | 4 +++- src/utils/getPostsByTag.ts | 5 ++++- src/utils/getSortedPosts.ts | 2 +- src/utils/getUniqueTags.ts | 2 +- src/utils/og-templates/post.tsx | 2 +- src/utils/postFilter.ts | 2 +- 17 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/components/Card.tsx b/src/components/Card.tsx index 711a252..66a730d 100644 --- a/src/components/Card.tsx +++ b/src/components/Card.tsx @@ -4,7 +4,7 @@ import type { CollectionEntry } from "astro:content"; export interface Props { href?: string; - frontmatter: CollectionEntry<"blog">["data"]; + frontmatter: CollectionEntry<"blog" | "policies">["data"]; secHeading?: boolean; } diff --git a/src/components/Search.tsx b/src/components/Search.tsx index e6f39ff..d3d6ff1 100644 --- a/src/components/Search.tsx +++ b/src/components/Search.tsx @@ -6,7 +6,7 @@ import type { CollectionEntry } from "astro:content"; export type SearchItem = { title: string; description: string; - data: CollectionEntry<"blog">["data"]; + data: CollectionEntry<"blog" | "policies">["data"]; slug: string; }; @@ -83,9 +83,9 @@ export default function SearchBar({ searchList }: Props) { Search []; + paginatedPosts: CollectionEntry<"blog" | "policies">[]; } const { currentPage, totalPages, paginatedPosts } = Astro.props; diff --git a/src/layouts/PolicyDetails.astro b/src/layouts/PolicyDetails.astro index 69823f1..1a6d5a5 100644 --- a/src/layouts/PolicyDetails.astro +++ b/src/layouts/PolicyDetails.astro @@ -1,15 +1,12 @@ --- import Layout from "@layouts/Layout.astro"; -import Footer from "@components/Footer.astro"; -import Tag from "@components/Tag.astro"; import Datetime from "@components/Datetime"; import type { CollectionEntry } from "astro:content"; import { slugifyStr } from "@utils/slugify"; -import ShareLinks from "@components/ShareLinks.astro"; import { SITE } from "@config"; export interface Props { - post: CollectionEntry<"blog">; + post: CollectionEntry<"blog" | "policies">; } const { post } = Astro.props; diff --git a/src/layouts/PostDetails.astro b/src/layouts/PostDetails.astro index aeb5d30..da88c76 100644 --- a/src/layouts/PostDetails.astro +++ b/src/layouts/PostDetails.astro @@ -10,7 +10,7 @@ import ShareLinks from "@components/ShareLinks.astro"; import { SITE } from "@config"; export interface Props { - post: CollectionEntry<"blog">; + post: CollectionEntry<"blog" | "policies">; } const { post } = Astro.props; diff --git a/src/layouts/Posts.astro b/src/layouts/Posts.astro index 9ee8619..a644cff 100644 --- a/src/layouts/Posts.astro +++ b/src/layouts/Posts.astro @@ -11,7 +11,7 @@ import { SITE } from "@config"; export interface Props { currentPage: number; totalPages: number; - paginatedPosts: CollectionEntry<"blog">[]; + paginatedPosts: CollectionEntry<"blog" | "policies">[]; } const { currentPage, totalPages, paginatedPosts } = Astro.props; diff --git a/src/layouts/TagPosts.astro b/src/layouts/TagPosts.astro index ebf169c..c7ec98b 100644 --- a/src/layouts/TagPosts.astro +++ b/src/layouts/TagPosts.astro @@ -11,7 +11,7 @@ import { SITE } from "@config"; export interface Props { currentPage: number; totalPages: number; - paginatedPosts: CollectionEntry<"blog">[]; + paginatedPosts: CollectionEntry<"blog" | "policies">[]; tag: string; tagName: string; } diff --git a/src/pages/posts/[slug]/index.astro b/src/pages/posts/[slug]/index.astro index 29bb602..5e6a2a8 100644 --- a/src/pages/posts/[slug]/index.astro +++ b/src/pages/posts/[slug]/index.astro @@ -7,7 +7,7 @@ import getPageNumbers from "@utils/getPageNumbers"; import getPagination from "@utils/getPagination"; export interface Props { - post: CollectionEntry<"blog">; + post: CollectionEntry<"blog" | "policies">; } export async function getStaticPaths() { diff --git a/src/pages/posts/[slug]/index.png.ts b/src/pages/posts/[slug]/index.png.ts index 839dc3e..3034c98 100644 --- a/src/pages/posts/[slug]/index.png.ts +++ b/src/pages/posts/[slug]/index.png.ts @@ -15,6 +15,9 @@ export async function getStaticPaths() { } export const GET: APIRoute = async ({ props }) => - new Response(await generateOgImageForPost(props as CollectionEntry<"blog">), { - headers: { "Content-Type": "image/png" }, - }); + new Response( + await generateOgImageForPost(props as CollectionEntry<"blog" | "policies">), + { + headers: { "Content-Type": "image/png" }, + } + ); diff --git a/src/pages/privacy-policies/[slug]/index.png.ts b/src/pages/privacy-policies/[slug]/index.png.ts index e4ac98b..3e756c8 100644 --- a/src/pages/privacy-policies/[slug]/index.png.ts +++ b/src/pages/privacy-policies/[slug]/index.png.ts @@ -15,6 +15,9 @@ export async function getStaticPaths() { } export const GET: APIRoute = async ({ props }) => - new Response(await generateOgImageForPost(props as CollectionEntry<"blog">), { - headers: { "Content-Type": "image/png" }, - }); + new Response( + await generateOgImageForPost(props as CollectionEntry<"blog" | "policies">), + { + headers: { "Content-Type": "image/png" }, + } + ); diff --git a/src/pages/tags/[tag]/[page].astro b/src/pages/tags/[tag]/[page].astro index 412dd1b..ea3e511 100644 --- a/src/pages/tags/[tag]/[page].astro +++ b/src/pages/tags/[tag]/[page].astro @@ -7,7 +7,7 @@ import getPageNumbers from "@utils/getPageNumbers"; import getPagination from "@utils/getPagination"; export interface Props { - post: CollectionEntry<"blog">; + post: CollectionEntry<"blog" | "policies">; tag: string; tagName: string; } diff --git a/src/utils/generateOgImages.tsx b/src/utils/generateOgImages.tsx index c6752b5..390d341 100644 --- a/src/utils/generateOgImages.tsx +++ b/src/utils/generateOgImages.tsx @@ -48,7 +48,9 @@ function svgBufferToPngBuffer(svg: string) { return pngData.asPng(); } -export async function generateOgImageForPost(post: CollectionEntry<"blog">) { +export async function generateOgImageForPost( + post: CollectionEntry<"blog" | "policies"> +) { const svg = await satori(postOgImage(post), options); return svgBufferToPngBuffer(svg); } diff --git a/src/utils/getPostsByTag.ts b/src/utils/getPostsByTag.ts index 8616170..ff07286 100644 --- a/src/utils/getPostsByTag.ts +++ b/src/utils/getPostsByTag.ts @@ -2,7 +2,10 @@ import type { CollectionEntry } from "astro:content"; import getSortedPosts from "./getSortedPosts"; import { slugifyAll } from "./slugify"; -const getPostsByTag = (posts: CollectionEntry<"blog">[], tag: string) => +const getPostsByTag = ( + posts: CollectionEntry<"blog" | "policies">[], + tag: string +) => getSortedPosts( posts.filter(post => slugifyAll(post.data.tags).includes(tag)) ); diff --git a/src/utils/getSortedPosts.ts b/src/utils/getSortedPosts.ts index 10a02c8..ef34ecf 100644 --- a/src/utils/getSortedPosts.ts +++ b/src/utils/getSortedPosts.ts @@ -1,7 +1,7 @@ import type { CollectionEntry } from "astro:content"; import postFilter from "./postFilter"; -const getSortedPosts = (posts: CollectionEntry<"blog">[]) => { +const getSortedPosts = (posts: CollectionEntry<"blog" | "policies">[]) => { if (!posts) return []; return posts diff --git a/src/utils/getUniqueTags.ts b/src/utils/getUniqueTags.ts index a4b103a..762f6a9 100644 --- a/src/utils/getUniqueTags.ts +++ b/src/utils/getUniqueTags.ts @@ -7,7 +7,7 @@ interface Tag { tagName: string; } -const getUniqueTags = (posts: CollectionEntry<"blog">[]) => { +const getUniqueTags = (posts: CollectionEntry<"blog" | "policies">[]) => { const tags: Tag[] = posts .filter(postFilter) .flatMap(post => post.data.tags) diff --git a/src/utils/og-templates/post.tsx b/src/utils/og-templates/post.tsx index a0dcf60..71501d3 100644 --- a/src/utils/og-templates/post.tsx +++ b/src/utils/og-templates/post.tsx @@ -1,7 +1,7 @@ import { SITE } from "@config"; import type { CollectionEntry } from "astro:content"; -export default (post: CollectionEntry<"blog">) => { +export default (post: CollectionEntry<"blog" | "policies">) => { return (
) => { +const postFilter = ({ data }: CollectionEntry<"blog" | "policies">) => { const isPublishTimePassed = Date.now() > new Date(data.pubDatetime).getTime() - SITE.scheduledPostMargin;