blog

Fetch the blog overview, filtered article lists and single articles.

Use blog for a blog index, an article page, or the category, tag and author listings. All calls are public.

import { blog } from '@salla.sa/twilight-theme-engine/api/blog';

const overview = await blog.get();
const { data, cursor } = await blog.articles.list({ category: categoryId }); // categoryId: string

Methods

MethodParametersReturnsRequestLogin needed
blog.getsignal?: AbortSignalPromise<BlogOverview>GET blogNo
blog.articles.listparams?: BlogArticlesListParamsPromise<BlogArticlesListResponse>GET blog/articles?...No
blog.articles.findid: string, signal?: AbortSignalPromise<ArticleDetail>GET blog/articles/{id}No
blog.articles.findOrThrowid: string, signal?: AbortSignalPromise<ArticleDetail>Same as findNo
  • BlogArticlesListParams: category, author, tag (strings), page, cursor, signal. Only the fields you set go into the query string.
  • BlogOverview: { categories, slides, articles, popular }, each an array.
  • BlogArticlesListResponse: { data, categories?, category, author, tag, cursor }, where cursor is { next?, previous?, current }.

Queries

QueryKey
queries.overview()['blog', 'overview']
queries.articles(params?)['blog', 'articles', params]
queries.article(id)['blog', 'article', id]

No key includes the locale or the active scope. Blog content is language-specific, so add the locale to your own key if the language can change without a reload. Each query passes TanStack Query's signal, so leaving the page cancels the request.

app/components/BlogList.tsx
import { useQuery } from '@tanstack/react-query';
import { blog } from '@salla.sa/twilight-theme-engine/api/blog';

export function BlogList({ categoryId }: { categoryId: string }) {
  const { data } = useQuery(blog.queries.articles({ category: categoryId }));
  const next = data?.cursor.next; // pass as `cursor` for the following page

  return <p>{data?.data.length} articles{next ? ', more available' : ''}</p>;
}

Gotchas

  • blog.get replaces missing lists with [], and articles.list replaces a missing data with [].
  • articles.find throws Error("Article {id} not found") when the API returns no data. HTTP errors throw the client's HTTPError. findOrThrow only turns a 404 or 410 into a not-found page, so the missing-article Error above (which has no HTTP status) still reaches the error boundary.
  • Paging is by cursor: pass cursor.next from the previous response as cursor.

See also

On this page