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.).

getAllContentMeta(config: ContentConfig): ContentMeta[]

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

Parameters:

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

Returns: Array of ContentMeta objects

import { getAllContentMeta } from '@haroonwaves/blog-kit-core';

const docsMeta = getAllContentMeta({
	contentDirectory: process.cwd(),
	contentSubdirectory: 'content/docs',
});

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

getContent(slug: string, config: ContentConfig): Content | null

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

Parameters:

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

Returns: Content object or null if not found

import { getContent } from '@haroonwaves/blog-kit-core';

const doc = getContent('getting-started', {
	contentDirectory: process.cwd(),
	contentSubdirectory: 'content/docs',
});

if (doc) {
	console.log(doc.metadata.title);
	console.log(doc.metadata.readingTime);
	console.log(doc.body);
}

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

Components

ContentList

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

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

ContentCard

Renders a single content item card with category badges, reading time, and date.

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

ContentRenderer

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

PropTypeDefaultDescription
bodystringrequiredMarkdown content to render
metadataContentMetarequiredContent 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
contentCountnumberNumber of results to display
placeholderstring'Search content...'Search input placeholder text
classNamestringContainer CSS class
classNamesobjectCSS overrides (see below)

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


ContentPlaceholder

Renders animated skeleton loading cards.

PropTypeDefaultDescription
countnumber3Number of placeholder skeletons
classNamestringAdditional CSS classes

Hooks

useContent(allContentMeta: ContentMeta[])

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

Parameters:

  • allContentMeta (ContentMeta[]): Array of content metadata to filter

Returns:

FieldTypeDescription
metadataContentMeta[]Filtered content items
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

Utility Functions

filterContent(items: ContentMeta[], searchTerm?: string, selectedCategory?: string | null): ContentMeta[]

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

getAvailableCategories(items: ContentMeta[]): string[]

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


Types

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

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

interface Content {
	metadata: ContentMeta;
	body: string;
}

interface ContentConfig {
	contentDirectory: string;
	contentSubdirectory?: string; // defaults to 'blog'
}