@contentrain/core
Core functionality for Contentrain SDK.
Installation
npm install @contentrain/core
Usage
import { ContentrainCore } from '@contentrain/core'
const core = new ContentrainCore()
const customCore = new ContentrainCore({
contentPath: 'custom/content/path',
modelsPath: 'custom/models/path',
locale: 'en'
})
const metadata = await core.getModelMetadata('posts')
const posts = await core.getContent('posts')
const post = await core.getContentById('posts', '123')
const collections = await core.getAvailableCollections()
API Reference
Constructor
constructor(config?: ContentrainConfig, customFs?: ContentrainFileSystem)
Creates a new instance of ContentrainCore.
Parameters
Methods
getModelMetadata
getModelMetadata(collection: string): Promise<ContentrainModelMetadata>
Gets metadata for a specific collection.
getContent
getContent<T>(collection: string): Promise<T[]>
Gets all content items from a collection.
getContentById
getContentById<T>(collection: string, id: string): Promise<T>
Gets a specific content item by ID.
getAvailableCollections
getAvailableCollections(): Promise<string[]>
Gets a list of all available collections.
getLocale
getLocale(): string | undefined
Gets the current locale setting.
License
MIT