API reference
Most symbols are exported from @next-md-blog/core. App Router metadata file helpers (getBlogSitemap, getBlogRobots, createRssFeedResponse) are also available from @next-md-blog/core/next (and re-exported from the main package). Types are TypeScript-only where noted.
Components
MarkdownContent
Server-friendly markdown renderer (uses react-markdown).
Props (MarkdownContentProps):
content—string(required)className— optional wrapper classcomponents— partialMarkdownComponentsmap (extendsreact-markdownComponents)remarkPlugins/rehypePlugins— optional plugin arrays
defaultMarkdownComponents
Default markdown element components used by MarkdownContent. Spread or merge when overriding individual tags.
OgImage
Layout helper for Open Graph images (intended for use with @vercel/og / ImageResponse).
Props (OgImageProps): title (required), optional description, siteName, backgroundColor, textColor, width, height.
BlogPostSEO
Injects JSON-LD <script type="application/ld+json"> tags for a post: article schema plus optional breadcrumbs.
Props (BlogPostSEOProps):
post—BlogPost(required)config—Config(optional; falls back togetConfig())breadcrumbs— optional{ name, url }[]forgenerateBreadcrumbsSchemaincludeBreadcrumbs— defaulttrueasGraph— whentrue, emits one@graphscript (Organization +BlogPosting+BreadcrumbList) with publisher by@id
Data loading
getBlogPost(slug, options?)
Returns Promise<BlogPost | null>. Resolves .md then .mdx under the posts directory. Uses options.config when parsing authors. Throws FileReadError / validation errors; BlogPostNotFoundError can surface from parse path in edge cases.
GetBlogPostOptions: postsDir?, locale?, config?.
getAllBlogPosts(options?)
Returns Promise<BlogPostMetadata[]> sorted by frontmatter.date descending. Skips invalid files with a console warning. Returns [] if the directory is missing or unreadable in safe cases.
getAllBlogPostSlugs(options?)
Returns Promise<string[]> of slugs from getAllBlogPosts.
Configuration helpers
createConfig(config: Config): Config— user-facing merge +siteUrlnormalization.loadConfig(): Promise<Config>— async defaults only.getConfig(): Config— sync defaults only.
Prefer importing your next-md-blog.config.ts and passing config into loaders and SEO functions.
SEO and feeds
generateBlogPostMetadata(post, config?)— NextMetadatafor a post (hreflang fromfrontmatter.alternateLanguagesorconfig.alternateLanguages; relative URLs are resolved withsiteUrl).generateBlogListMetadata(posts, config?)—Metadatafor an index page (Open Graph URL usesblogIndexPathor default{siteUrl}/blogs).generateBlogPostSchema(post, config?, options?)— Schema.orgBlogPostingJSON-LD; optionalBlogPostSchemaOptions.publisherReferencefor@graphusage.generateBlogPostSchemaGraph(post, config?, breadcrumbs?, includeBreadcrumbs?)— single@context+@graphobject.generateBreadcrumbsSchema(post, config?, breadcrumbs?)—BreadcrumbListJSON-LD (default blog link usesblogIndexPathor{siteUrl}/blogs).generateOrganizationSchema(config?)— standaloneOrganizationJSON-LD (for root layout), including@id, optionalorganization.logo,sameAs, etc.getBlogSitemapEntries(posts, config?)— array of sitemap rows (same shape as NextMetadataRoute.Sitemapentries).generateRSSFeed(posts, config?)— RSS 2.0 XML string (usually consumed viacreateRssFeedResponse).
@next-md-blog/core/next (and main re-exports)
getBlogSitemap(posts, config?)— typed forapp/sitemap.ts(MetadataRoute.Sitemap).getBlogRobots(config?)— typed forapp/robots.ts(MetadataRoute.Robots).createRssFeedResponse(posts, config?, init?)—NextResponseforapp/feed.xml/route.ts.
See SEO & feeds.
Utilities
calculateReadingTime(content: string): numbercalculateWordCount(content: string): numbernormalizeAuthors(author?, authors?, configAuthors?)— returns(string | Author)[], resolving frontmatterauthor/authorsagainst optionalconfig.authors.resolvePostUrl,resolvePostUrlWithConfig,getBlogPostPathSegment,resolveHreflangMap,resolveBlogIndexUrl,resolveCanonicalUrl,escapeXml— URL and feed helpers used by SEO generators.
Constants
POSTS_DIR_NAME—'posts'.getPostsDirectory(customPath?, locale?)— absolute path underprocess.cwd().
Errors
MdxBlogError — base class (code: string). Import it to catch any library error by prototype.
BlogPostNotFoundErrorFileReadError—filePath, optionaloriginalError,contextDirectoryError
Types
Exported types: BlogPost, BlogPostMetadata, BlogPostFrontmatter, GetBlogPostOptions, Author, Config, SiteOrganization, BlogPostSchemaOptions, BlogSitemapEntry.
Author
name (required); optional email, bio, avatar, twitter, github, url.