Reads published blog articles, available as lynkow.contents. Draft, scheduled and archived content is never returned. With cache: true, responses are cached for 5 minutes.

Access via: lynkow.contents

Methods

3 methods

clearCache

TypeScript
clearCache(): void

Clears every cached article response held by the client. Call it when a content.* webhook arrives so the next read fetches fresh data.

Returns: void

TypeScript
// In a Next.js route handler receiving a Lynkow webhook:
if (event.type === 'content.updated') {
  lynkow.contents.clearCache()
}

getBySlug

TypeScript
getBySlug(slug: string, options?: BaseRequestOptions): Promise<Content>

Fetches one published article by slug, with its HTML body, SEO fields, author, categories, tags, structured data and translations (alternates). With a locale, a missing translation is served from the fallback locale and flagged isFallback: pass fallback: false in options to get a 404 instead. With cache: true, cached for 5 minutes. Throws LynkowError NOT_FOUND for an unknown or unpublished slug, and for an empty, '.' or '..' slug, which is refused without a request.

Parameter

Type

Description

slug

string

The article slug, such as 'my-article'.

options

BaseRequestOptions

Request options. locale selects the translation, fallback: false refuses a fallback.

Returns: Promise<Content>

TypeScript
const content = await lynkow.contents.getBySlug('my-article')
console.log(content.title)          // Article title
console.log(content.body)           // HTML body string
console.log(content.author?.fullName) // Author name
console.log(content.categories)     // Associated categories

list

TypeScript
list(filters?: ContentsFilters, options?: BaseRequestOptions): Promise<ContentsListResponse>

Fetches a page of published articles, newest first by default. Defaults to 20 per page, at most 100. search matches the title and slug, case-insensitively and by partial match. With a locale, each translation group appears once and a missing translation is served from the fallback locale: pass fallback: false in options to drop those items. With cache: true, cached for 5 minutes. Resolves to { data, meta }. Throws LynkowError VALIDATION_ERROR for a limit above 100 or an unknown sort or order value.

Parameter

Type

Description

filters

ContentsFilters

Pagination (page, limit), category and tag slugs, search, sort (a column such as 'published_at' or 'title'), order ('asc' or 'desc') and locale.

options

BaseRequestOptions

Request options. options.locale takes precedence over filters.locale.

Returns: Promise<ContentsListResponse>

TypeScript
// Fetch the first page of articles in the "tech" category
const { data, meta } = await lynkow.contents.list({
  page: 1,
  limit: 10,
  category: 'tech'
})

// Search for articles
const results = await lynkow.contents.list({ search: 'typescript' })