Migrate more code to typescript

This commit is contained in:
prototypa
2023-01-02 12:20:26 -05:00
parent 6998cc7602
commit 024825ec59
14 changed files with 68 additions and 37 deletions

View File

@ -16,11 +16,7 @@ const { prevUrl, nextUrl, prevText = 'Newer posts', nextText = 'Older posts' } =
(prevUrl || nextUrl) && ( (prevUrl || nextUrl) && (
<div class="container flex"> <div class="container flex">
<div class="flex flex-row mx-auto container justify-between"> <div class="flex flex-row mx-auto container justify-between">
<a <a href={getRelativeLink(prevUrl)} class={`btn btn-ghost px-3 mr-2 ${!prevUrl ? 'invisible' : ''}`}>
href={getRelativeLink(prevUrl)}
class={`btn btn-ghost px-3 mr-2
${!prevUrl ? 'invisible' : ''}`}
>
<div class="flex flex-row align-middle"> <div class="flex flex-row align-middle">
<Icon name="tabler:arrow-left" class="w-6 h-6" /> <Icon name="tabler:arrow-left" class="w-6 h-6" />
<p class="ml-2">{prevText}</p> <p class="ml-2">{prevText}</p>

View File

@ -1,7 +1,7 @@
--- ---
import { getPermalink } from '~/utils/permalinks'; import { getPermalink } from '~/utils/permalinks';
import type { Post } from '~/utils/posts'; import type { Post } from "~/types"
export interface Props { export interface Props {
tags: Post['tags']; tags: Post['tags'];

View File

@ -1,6 +1,6 @@
--- ---
import Item from '~/components/blog/GridItem.astro'; import Item from '~/components/blog/GridItem.astro';
import type { Post } from '~/utils/posts'; import type { Post } from "~/types"
export interface Props { export interface Props {
posts: Array<Post>; posts: Array<Post>;

View File

@ -4,7 +4,7 @@ import { Picture } from '@astrojs/image/components';
import { findImage } from '~/utils/images'; import { findImage } from '~/utils/images';
import { getPermalink } from '~/utils/permalinks'; import { getPermalink } from '~/utils/permalinks';
import type { Post } from '~/utils/posts'; import type { Post } from "~/types"
export interface Props { export interface Props {
post: Post; post: Post;

View File

@ -1,6 +1,6 @@
--- ---
import Item from '~/components/blog/ListItem.astro'; import Item from '~/components/blog/ListItem.astro';
import type { Post } from '~/utils/posts'; import type { Post } from "~/types"
export interface Props { export interface Props {
posts: Array<Post>; posts: Array<Post>;

View File

@ -6,7 +6,7 @@ import { getPermalink } from '~/utils/permalinks';
import { findImage } from '~/utils/images'; import { findImage } from '~/utils/images';
import { getFormattedDate } from '~/utils/utils'; import { getFormattedDate } from '~/utils/utils';
import type { Post } from '~/utils/posts'; import type { Post } from "~/types"
export interface Props { export interface Props {
post: Post; post: Post;

View File

@ -5,7 +5,7 @@ import SocialShare from '~/components/atoms/SocialShare.astro';
import { getFormattedDate } from '~/utils/utils'; import { getFormattedDate } from '~/utils/utils';
import type { Post } from '~/utils/posts'; import type { Post } from "~/types"
export interface Props { export interface Props {
post: Post; post: Post;

View File

@ -11,6 +11,8 @@ import Fonts from '../atoms/Fonts.astro';
import ExtraMetaTags from '../atoms/ExtraMetaTags.astro'; import ExtraMetaTags from '../atoms/ExtraMetaTags.astro';
import SplitbeeAnalytics from './SplitbeeAnalytics.astro'; import SplitbeeAnalytics from './SplitbeeAnalytics.astro';
import { MetaSEO } from '~/types';
const { src: defaultImage } = await getImage({ const { src: defaultImage } = await getImage({
src: defaultImageSrc, src: defaultImageSrc,
alt: 'Default image', alt: 'Default image',
@ -18,6 +20,8 @@ const { src: defaultImage } = await getImage({
height: 628, height: 628,
}); });
export interface Props extends MetaSEO {}
const { const {
title = SITE.name, title = SITE.name,
description = '', description = '',

2
src/env.d.ts vendored
View File

@ -1 +1 @@
/// <reference types="astro/client" /> /// <reference types="@astrojs/image/client" />

View File

@ -4,6 +4,12 @@ import '~/assets/styles/base.css';
import MetaTags from '~/components/core/MetaTags.astro'; import MetaTags from '~/components/core/MetaTags.astro';
import BasicScripts from '~/components/core/BasicScripts.astro'; import BasicScripts from '~/components/core/BasicScripts.astro';
import { MetaSEO } from '~/types';
export interface Props {
meta?: MetaSEO;
}
const { meta = {} } = Astro.props; const { meta = {} } = Astro.props;
--- ---

View File

@ -1,6 +1,12 @@
--- ---
import Layout from '~/layouts/PageLayout.astro'; import Layout from '~/layouts/PageLayout.astro';
import { MetaSEO } from '~/types';
export interface Props {
meta?: MetaSEO;
}
const { meta } = Astro.props; const { meta } = Astro.props;
--- ---

View File

@ -4,6 +4,12 @@ import Header from '~/components/widgets/Header.astro';
import Footer from '~/components/widgets/Footer.astro'; import Footer from '~/components/widgets/Footer.astro';
import Announcement from '~/components/widgets/Announcement.astro'; import Announcement from '~/components/widgets/Announcement.astro';
import { MetaSEO } from '~/types';
export interface Props {
meta?: MetaSEO;
}
const { meta } = Astro.props; const { meta } = Astro.props;
--- ---

37
src/types.ts Normal file
View File

@ -0,0 +1,37 @@
export interface Post {
id: string;
slug: string;
publishDate: Date;
title: string;
description?: string;
image?: string;
canonical?: string | URL;
permalink?: string;
draft?: boolean;
excerpt?: string;
category?: string;
tags?: Array<string>;
authors?: Array<string>;
Content: unknown;
content?: string;
readingTime: number;
}
export interface MetaSEO {
title?: string,
description?: string,
image?: string,
canonical?: string,
noindex?: boolean,
nofollow?: boolean,
ogTitle?: string,
ogType?: string,
}

View File

@ -1,30 +1,6 @@
import { getCollection, getEntry } from 'astro:content'; import { getCollection, getEntry } from 'astro:content';
import type { CollectionEntry } from 'astro:content'; import type { CollectionEntry } from 'astro:content';
import type { Post } from "~/types"
export interface Post {
id: string;
slug: string;
publishDate: Date;
title: string;
description?: string;
image?: string;
canonical?: string;
permalink?: string;
draft?: boolean;
excerpt?: string;
category?: string;
tags?: Array<string>;
authors?: Array<string>;
Content: unknown;
content?: string;
readingTime: number;
}
const getNormalizedPost = async (post: CollectionEntry<'blog'>): Promise<Post> => { const getNormalizedPost = async (post: CollectionEntry<'blog'>): Promise<Post> => {
const { id, slug, data } = post; const { id, slug, data } = post;