Typescript

Create typed components for your content easily with Zenblog's types.

Importing types

Zenblog exports types for all the data returned from the API. You can use them to create typed components for your content. Import them from the zenblog/types after installing the package with npm install zenblog.

lib/zenblog.ts
1import { Post, PostWithContent, Author, Category, Tag } from "zenblog/types";

Post type

Posts without html_content property. Used to list posts.

lib/zenblog.ts
1export type Post = {
2  title: string;
3  slug: string;
4  published_at: string;
5  cover_image?: string;
6  excerpt?: string;
7  tags: Tag[];
8  category: Category | null;
9  authors: Author[];
10};

PostWithContent type

Posts with html_content property. Used to render a post.

lib/zenblog.ts
1export type PostWithContent = Post & {
2  html_content: string;
3};

Author type

Authors of the post.

lib/zenblog.ts
1export type Author = {
2  name: string;
3  slug: string;
4  image_url: string;
5  bio?: string;
6  twitter_url?: string;
7  website_url?: string;
8};

Category type

Category of the post. Posts can have one category.

lib/zenblog.ts
1export type Category = {
2  slug: string;
3  name: string;
4};

Tag type

Tags of the post. Posts can have multiple tags.

lib/zenblog.ts
1export type Tag = {
2  slug: string;
3  name: string;
4};