Service for retrieving content categories and their hierarchical structure.
Accessible via lynkow.categories. Categories organize blog articles and can be
nested (parent/child). Each category includes a content count and optional image.
Responses are cached for 5 minutes (SHORT TTL) when a cache adapter is configured.
Access via: lynkow.categories
Methods
4 methods
clearCache
clearCache(): voidInvalidates all cached category responses (lists, tree, and detail views). Call this after knowing categories have been updated to force fresh data on the next request.
Returns: void
getBySlug
getBySlug(slug: string, options?: CategoryOptions & BaseRequestOptions): Promise<CategoryDetailResponse>Retrieves a single category by its slug, along with a paginated list of the published articles that belong to it. Cached for 5 minutes per slug+locale+pagination combination.
Parameter | Type | Description |
|---|---|---|
|
| The unique URL slug of the category (e.g. |
|
| Combined category and request options:<br> - |
Returns: Promise<CategoryDetailResponse>
const { category, contents } = await lynkow.categories.getBySlug('tech', {
page: 1,
limit: 10
})
console.log(category.name) // "Tech"
console.log(contents.data.length) // Number of articles on this page
console.log(contents.meta.hasMorePages) // Whether more pages existlist
list(options?: BaseRequestOptions): Promise<CategoriesListResponse>Retrieves a flat list of all categories with their content counts. Useful for building navigation menus, sidebars, or category filters. Cached for 5 minutes per locale.
Parameter | Type | Description |
|---|---|---|
|
| Request options; use |
Returns: Promise<CategoriesListResponse>
const { data, blogUrlMode } = await lynkow.categories.list()
data.forEach(cat => {
console.log(`${cat.name} (${cat.contentCount} articles)`)
})tree
tree(options?: BaseRequestOptions): Promise<CategoryTreeResponse>Retrieves the full category hierarchy as a nested tree structure.
Root categories appear at the top level, each with a children array
containing their subcategories (recursively). Useful for building
hierarchical navigation or breadcrumbs. Cached for 5 minutes per locale.
Parameter | Type | Description |
|---|---|---|
|
| Request options; use |
Returns: Promise<CategoryTreeResponse>
const { data } = await lynkow.categories.tree()
// Iterate root categories and their children
data.forEach(root => {
console.log(root.name)
root.children.forEach(child => {
console.log(` - ${child.name}`)
})
})