Mentionwell

The official SDK. Tiny TypeScript wrapper around the public API plus a few HTML cleanup helpers.

npm install mentionwell-reader

Modules

  • mentionwell-reader/api — typed fetch helpers for the public API.
  • mentionwell-reader/html-utils — clean and prepare post.html for safe injection (extracts TOC, strips scripts, normalises headings).
  • mentionwell-reader/styles — optional default CSS for the wb-* class names that the writer emits.

Config

export interface MentionwellApiConfig {
  apiUrl: string;     // MENTIONWELL_API_URL
  siteSlug: string;   // MENTIONWELL_SITE_SLUG
  apiKey: string;     // MENTIONWELL_API_KEY
}

API helpers

getBlogPostsViaApi(config, page = 1, perPage = 12)

Wraps GET /api/public/{siteSlug}/posts. Returns { posts, total, totalPages } so you can paginate without a second count request.

getBlogPostViaApi(config, slug)

Wraps GET /api/public/{siteSlug}/posts/{slug}. Returns the post or null on 404.

getAllBlogSlugsViaApi(config)

Pages through the list endpoint and returns string[] — every published slug. Useful for generateStaticParams.

getBlogPostSummariesViaApi(config)

Returns a lightweight { slug, updatedAt }[] for sitemap generation without pulling full post bodies.

HTML utils

prepareArticleHtml(html: string): string

Returns sanitised, normalised HTML safe to inject. Strips script tags, ensures alt on images, normalises heading levels. Single argument — no options object.

extractTocHtml(html: string): string | null

Returns the inline TOC block as HTML, or null if the article has no TOC. Useful when you want to render the TOC in a sidebar.

stripTocFromArticle(html: string): string

Returns the article body with the inline TOC removed (since you're now rendering it in the sidebar).

stripDuplicateChrome(html: string): string

Removes any duplicated header/footer chrome that the writer occasionally emits. prepareArticleHtml already calls this — only call it directly if you need finer control.

stripLegacyCtaLeaks(html: string): string

Removes literal [CTA] placeholder tokens older articles sometimes carried. Also called by prepareArticleHtml.

Source