Fix astro check errors on strict typescript, issue #293
This commit is contained in:
@ -4,8 +4,8 @@ import { getPermalink } from '~/utils/permalinks';
|
|||||||
import Button from '~/components/ui/Button.astro';
|
import Button from '~/components/ui/Button.astro';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
prevUrl: string;
|
prevUrl?: string;
|
||||||
nextUrl: string;
|
nextUrl?: string;
|
||||||
prevText?: string;
|
prevText?: string;
|
||||||
nextText?: string;
|
nextText?: string;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
---
|
---
|
||||||
|
import type { InferGetStaticPropsType, GetStaticPaths } from 'astro';
|
||||||
|
|
||||||
import Layout from '~/layouts/PageLayout.astro';
|
import Layout from '~/layouts/PageLayout.astro';
|
||||||
import BlogList from '~/components/blog/List.astro';
|
import BlogList from '~/components/blog/List.astro';
|
||||||
import Headline from '~/components/blog/Headline.astro';
|
import Headline from '~/components/blog/Headline.astro';
|
||||||
@ -9,11 +11,13 @@ import { blogListRobots, getStaticPathsBlogList } from '~/utils/blog';
|
|||||||
|
|
||||||
export const prerender = true;
|
export const prerender = true;
|
||||||
|
|
||||||
export async function getStaticPaths ({ paginate }) {
|
export const getStaticPaths = (async ({ paginate }) => {
|
||||||
return await getStaticPathsBlogList({ paginate });
|
return await getStaticPathsBlogList({ paginate });
|
||||||
}
|
}) satisfies GetStaticPaths;
|
||||||
|
|
||||||
const { page } = Astro.props;
|
type Props = InferGetStaticPropsType<typeof getStaticPaths>;
|
||||||
|
|
||||||
|
const { page } = Astro.props as Props;
|
||||||
const currentPage = page.currentPage ?? 1;
|
const currentPage = page.currentPage ?? 1;
|
||||||
|
|
||||||
// const allCategories = await findCategories();
|
// const allCategories = await findCategories();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
---
|
---
|
||||||
|
import type { InferGetStaticPropsType, GetStaticPaths } from 'astro';
|
||||||
import { blogCategoryRobots, getStaticPathsBlogCategory } from '~/utils/blog';
|
import { blogCategoryRobots, getStaticPathsBlogCategory } from '~/utils/blog';
|
||||||
|
|
||||||
import Layout from '~/layouts/PageLayout.astro';
|
import Layout from '~/layouts/PageLayout.astro';
|
||||||
@ -8,11 +9,13 @@ import Pagination from '~/components/blog/Pagination.astro';
|
|||||||
|
|
||||||
export const prerender = true;
|
export const prerender = true;
|
||||||
|
|
||||||
export async function getStaticPaths ({ paginate }) {
|
export const getStaticPaths = (async ({ paginate }) => {
|
||||||
return await getStaticPathsBlogCategory({ paginate });
|
return await getStaticPathsBlogCategory({ paginate });
|
||||||
}
|
}) satisfies GetStaticPaths;
|
||||||
|
|
||||||
const { page, category } = Astro.props;
|
type Props = InferGetStaticPropsType<typeof getStaticPaths> & { category: string };
|
||||||
|
|
||||||
|
const { page, category } = Astro.props as Props;
|
||||||
|
|
||||||
const currentPage = page.currentPage ?? 1;
|
const currentPage = page.currentPage ?? 1;
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
---
|
---
|
||||||
|
import type { InferGetStaticPropsType, GetStaticPaths } from 'astro';
|
||||||
import { blogTagRobots, getStaticPathsBlogTag } from '~/utils/blog';
|
import { blogTagRobots, getStaticPathsBlogTag } from '~/utils/blog';
|
||||||
|
|
||||||
import Layout from '~/layouts/PageLayout.astro';
|
import Layout from '~/layouts/PageLayout.astro';
|
||||||
@ -8,11 +9,13 @@ import Pagination from '~/components/blog/Pagination.astro';
|
|||||||
|
|
||||||
export const prerender = true;
|
export const prerender = true;
|
||||||
|
|
||||||
export async function getStaticPaths ({ paginate }) {
|
export const getStaticPaths = (async ({ paginate }) => {
|
||||||
return await getStaticPathsBlogTag({ paginate });
|
return await getStaticPathsBlogTag({ paginate });
|
||||||
}
|
}) satisfies GetStaticPaths;
|
||||||
|
|
||||||
const { page, tag } = Astro.props;
|
type Props = InferGetStaticPropsType<typeof getStaticPaths>;
|
||||||
|
|
||||||
|
const { page, tag } = Astro.props as Props;
|
||||||
|
|
||||||
const currentPage = page.currentPage ?? 1;
|
const currentPage = page.currentPage ?? 1;
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
---
|
---
|
||||||
|
import type { InferGetStaticPropsType, GetStaticPaths } from 'astro';
|
||||||
|
|
||||||
import merge from 'lodash.merge';
|
import merge from 'lodash.merge';
|
||||||
import type { ImageMetadata } from 'astro';
|
import type { ImageMetadata } from 'astro';
|
||||||
import Layout from '~/layouts/PageLayout.astro';
|
import Layout from '~/layouts/PageLayout.astro';
|
||||||
@ -8,17 +10,20 @@ import ToBlogLink from '~/components/blog/ToBlogLink.astro';
|
|||||||
import { getCanonical, getPermalink } from '~/utils/permalinks';
|
import { getCanonical, getPermalink } from '~/utils/permalinks';
|
||||||
import { getStaticPathsBlogPost, blogPostRobots } from '~/utils/blog';
|
import { getStaticPathsBlogPost, blogPostRobots } from '~/utils/blog';
|
||||||
import { findImage } from '~/utils/images';
|
import { findImage } from '~/utils/images';
|
||||||
|
import type { MetaData } from '~/types';
|
||||||
|
|
||||||
export const prerender = true;
|
export const prerender = true;
|
||||||
|
|
||||||
export async function getStaticPaths () {
|
export const getStaticPaths = (async () => {
|
||||||
return await getStaticPathsBlogPost();
|
return await getStaticPathsBlogPost();
|
||||||
}
|
}) satisfies GetStaticPaths;
|
||||||
|
|
||||||
const { post } = Astro.props;
|
type Props = InferGetStaticPropsType<typeof getStaticPaths>;
|
||||||
|
|
||||||
|
const { post } = Astro.props as Props;
|
||||||
|
|
||||||
const url = getCanonical(getPermalink(post.permalink, 'post'));
|
const url = getCanonical(getPermalink(post.permalink, 'post'));
|
||||||
const image = (await findImage(post.image)) as ImageMetadata | undefined;
|
const image = (await findImage(post.image)) as ImageMetadata | string | undefined;
|
||||||
|
|
||||||
const metadata = merge(
|
const metadata = merge(
|
||||||
{
|
{
|
||||||
@ -30,11 +35,11 @@ const metadata = merge(
|
|||||||
},
|
},
|
||||||
openGraph: {
|
openGraph: {
|
||||||
type: 'article',
|
type: 'article',
|
||||||
...(image ? { images: [{ url: image, width: image?.width, height: image?.height }] } : {}),
|
...(image ? { images: [{ url: image, width: (image as ImageMetadata)?.width, height: (image as ImageMetadata)?.height }] } : {}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ ...(post?.metadata ? { ...post.metadata, canonical: post.metadata?.canonical || url } : {}) }
|
{ ...(post?.metadata ? { ...post.metadata, canonical: post.metadata?.canonical || url } : {}) }
|
||||||
);
|
) as MetaData;
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout metadata={metadata}>
|
<Layout metadata={metadata}>
|
||||||
|
4
src/types.d.ts
vendored
4
src/types.d.ts
vendored
@ -1,5 +1,5 @@
|
|||||||
import type { AstroComponentFactory } from 'astro/runtime/server/index.js';
|
import type { AstroComponentFactory } from 'astro/runtime/server/index.js';
|
||||||
import type { HTMLAttributes } from 'astro/types';
|
import type { HTMLAttributes, ImageMetadata } from 'astro/types';
|
||||||
|
|
||||||
export interface Post {
|
export interface Post {
|
||||||
/** A unique ID number that identifies a post. */
|
/** A unique ID number that identifies a post. */
|
||||||
@ -21,7 +21,7 @@ export interface Post {
|
|||||||
/** Optional summary of post content. */
|
/** Optional summary of post content. */
|
||||||
excerpt?: string;
|
excerpt?: string;
|
||||||
/** */
|
/** */
|
||||||
image?: string;
|
image?: ImageMetadata | string;
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
category?: string;
|
category?: string;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import type { PaginateFunction } from 'astro';
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection } from 'astro:content';
|
||||||
import type { CollectionEntry } from 'astro:content';
|
import type { CollectionEntry } from 'astro:content';
|
||||||
import type { Post } from '~/types';
|
import type { Post } from '~/types';
|
||||||
@ -162,7 +163,7 @@ export const findLatestPosts = async ({ count }: { count?: number }): Promise<Ar
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
export const getStaticPathsBlogList = async ({ paginate }) => {
|
export const getStaticPathsBlogList = async ({ paginate }: { paginate: PaginateFunction }) => {
|
||||||
if (!isBlogEnabled || !isBlogListRouteEnabled) return [];
|
if (!isBlogEnabled || !isBlogListRouteEnabled) return [];
|
||||||
return paginate(await fetchPosts(), {
|
return paginate(await fetchPosts(), {
|
||||||
params: { blog: BLOG_BASE || undefined },
|
params: { blog: BLOG_BASE || undefined },
|
||||||
@ -182,16 +183,16 @@ export const getStaticPathsBlogPost = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
export const getStaticPathsBlogCategory = async ({ paginate }) => {
|
export const getStaticPathsBlogCategory = async ({ paginate }: { paginate: PaginateFunction }) => {
|
||||||
if (!isBlogEnabled || !isBlogCategoryRouteEnabled) return [];
|
if (!isBlogEnabled || !isBlogCategoryRouteEnabled) return [];
|
||||||
|
|
||||||
const posts = await fetchPosts();
|
const posts = await fetchPosts();
|
||||||
const categories = new Set();
|
const categories = new Set<string>();
|
||||||
posts.map((post) => {
|
posts.map((post) => {
|
||||||
typeof post.category === 'string' && categories.add(post.category.toLowerCase());
|
typeof post.category === 'string' && categories.add(post.category.toLowerCase());
|
||||||
});
|
});
|
||||||
|
|
||||||
return Array.from(categories).flatMap((category: string) =>
|
return Array.from(categories).flatMap((category) =>
|
||||||
paginate(
|
paginate(
|
||||||
posts.filter((post) => typeof post.category === 'string' && category === post.category.toLowerCase()),
|
posts.filter((post) => typeof post.category === 'string' && category === post.category.toLowerCase()),
|
||||||
{
|
{
|
||||||
@ -204,16 +205,16 @@ export const getStaticPathsBlogCategory = async ({ paginate }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
export const getStaticPathsBlogTag = async ({ paginate }) => {
|
export const getStaticPathsBlogTag = async ({ paginate }: { paginate: PaginateFunction }) => {
|
||||||
if (!isBlogEnabled || !isBlogTagRouteEnabled) return [];
|
if (!isBlogEnabled || !isBlogTagRouteEnabled) return [];
|
||||||
|
|
||||||
const posts = await fetchPosts();
|
const posts = await fetchPosts();
|
||||||
const tags = new Set();
|
const tags = new Set<string>();
|
||||||
posts.map((post) => {
|
posts.map((post) => {
|
||||||
Array.isArray(post.tags) && post.tags.map((tag) => tags.add(tag.toLowerCase()));
|
Array.isArray(post.tags) && post.tags.map((tag) => tags.add(tag.toLowerCase()));
|
||||||
});
|
});
|
||||||
|
|
||||||
return Array.from(tags).flatMap((tag: string) =>
|
return Array.from(tags).flatMap((tag) =>
|
||||||
paginate(
|
paginate(
|
||||||
posts.filter((post) => Array.isArray(post.tags) && post.tags.find((elem) => elem.toLowerCase() === tag)),
|
posts.filter((post) => Array.isArray(post.tags) && post.tags.find((elem) => elem.toLowerCase() === tag)),
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user