Blog Kit

API Reference

The complete reference for everything exported by Blog Kit. For tutorials and usage examples, see Getting Started and Guides.


Core Package (@haroonwaves/blog-kit-core)

All core functions require Node.js (fs module) and only work in server environments (Next.js SSR/SSG, Node.js scripts, etc.).

getAllBlogsMeta(config: BlogConfig): BlogMeta[]

Returns an array of all blog metadata sorted by date (newest first).

Parameters:

  • config.contentDirectory (string): Path to your content directory
  • config.blogSubdirectory (string, optional): Subdirectory for blog files (defaults to 'blog')

Returns: Array of BlogMeta objects

const blogsMeta = getAllBlogsMeta({
	contentDirectory: process.cwd(),
	blogSubdirectory: 'content/blog',
});

blogsMeta.forEach((meta) => {
	console.log(meta.title, meta.slug, meta.readingTime);
});

getBlog(slug: string, config: BlogConfig): Blog | null

Returns the full blog data (metadata + content) for a specific slug.

Parameters:

  • slug (string): The blog post slug (filename without .md)
  • config.contentDirectory (string): Path to your content directory
  • config.blogSubdirectory (string, optional): Subdirectory for blog files (defaults to 'blog')

Returns: Blog object or null if not found

const blog = getBlog('my-blog-post', {
	contentDirectory: process.cwd(),
	blogSubdirectory: 'content/blog',
});

if (blog) {
	console.log(blog.metadata.title);
	console.log(blog.metadata.readingTime);
	console.log(blog.content);
}

React Package (@haroonwaves/blog-kit-react)

Components

BlogList

A stateless component that renders a list of blog cards. Works with both server-side and client-side rendering.

PropTypeDefaultDescription
metadataBlogMeta[]requiredArray of blog metadata to render
titlestringPage title (rendered as h1)
descriptionstringPage description
basePathstring'/blog'Base URL for blog post links
renderLink(href, children) => ReactNodeCustom link renderer (e.g. Next.js Link)
classNamestringCSS class for the card container
emptyMessagestring'No blog posts found.'Message when list is empty
cardPropsOmit<BlogCardProps, 'metadata' | 'basePath' | 'renderLink'>Props forwarded to each BlogCard
classNames{ title?, description? }CSS overrides for title and description

BlogCard

Renders a single blog post card with category badges, reading time, and date.

PropTypeDefaultDescription
metadataBlogMetarequiredBlog metadata object
basePathstring'/blog'Base path for blog links
renderLink(href, children) => ReactNodeCustom link renderer (e.g. Next.js Link)
classNamestringAdditional CSS classes
showCategorybooleantrueShow category badge
showReadingTimebooleantrueShow reading time
showDatebooleantrueShow publication date

BlogRenderer

Renders markdown content with syntax highlighting (Prism), GFM support, heading anchor links, and styled typography. Supports custom component overrides.

PropTypeDefaultDescription
contentstringrequiredMarkdown content to render
metadataBlogMetarequiredBlog metadata object
classNamestringAdditional CSS classes
componentsRecord<string, ComponentType>Override default HTML element renderers
showCategorybooleantrueShow category badge
showReadingTimebooleantrueShow reading time
showDatebooleantrueShow publication date

Overridable elements: h1h6, p, a, blockquote, code, pre, img, table, thead, tbody, tr, th, td, ul, ol, li, strong, em, del, hr, br, input


Filter

A client component for searching and category filtering.

PropTypeDefaultDescription
searchTermstringrequiredCurrent search input value
setSearchTerm(term: string) => voidrequiredCallback for search input changes
selectedCategorystring | nullrequiredCurrently selected category
setSelectedCategory(cat: string | null) => voidrequiredCallback for category changes
categoriesstring[]requiredList of available category labels
postsCountnumberNumber of results to display
placeholderstring'Search blogs...'Search input placeholder text
classNamestringContainer CSS class
classNamesobjectCSS overrides (see below)

classNames keys: input, categoryContainer, pill, activePill, inactivePill, postsCount


BlogPlaceholder

Renders animated skeleton loading cards.

PropTypeDefaultDescription
countnumber3Number of placeholder skeletons
classNamestringAdditional CSS classes

Hooks

useBlogs(blogsMeta: BlogMeta[])

A client-side hook that provides search and category filter state management with debounced search (500ms).

Parameters:

  • blogsMeta (BlogMeta[]): Array of blog metadata to filter

Returns:

FieldTypeDescription
metadataBlogMeta[]Filtered blog posts
searchTermstringCurrent search input value
setSearchTerm(term: string) => voidUpdate the search term
selectedCategorystring | nullCurrently selected category
setSelectedCategory(cat: string | null) => voidUpdate selected category
categoriesstring[]All unique categories from input blogs

Utility Functions

filterBlogs(blogs: BlogMeta[], searchTerm?: string, selectedCategory?: string | null): BlogMeta[]

Pure utility to filter blogs by search term (matches title and description) and/or category. Useful for server-side filtering or custom implementations outside of useBlogs.

getAvailableCategories(blogs: BlogMeta[]): string[]

Returns a deduplicated array of all categories across the provided blog metadata.


Types

All types are exported from both @haroonwaves/blog-kit-core and @haroonwaves/blog-kit-react.

interface BlogMeta {
	title: string;
	description: string;
	date: string;
	categories?: string[];
	slug: string;
	readingTime: string;
}

interface Blog {
	metadata: BlogMeta;
	content: string;
}

interface BlogConfig {
	contentDirectory: string;
	blogSubdirectory?: string; // defaults to 'blog'
}