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
clearCache(): voidClears every cached article response held by the client. Call it when a content.* webhook arrives
so the next read fetches fresh data.
Returns: void
// In a Next.js route handler receiving a Lynkow webhook:
if (event.type === 'content.updated') {
lynkow.contents.clearCache()
}getBySlug
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 |
|---|---|---|
|
| The article slug, such as |
|
| Request options. |
Returns: Promise<Content>
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 categorieslist
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 |
|---|---|---|
|
| Pagination ( |
|
| Request options. |
Returns: Promise<ContentsListResponse>
// 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' })