|
| 1 | +# @changespage/core |
| 2 | + |
| 3 | +Framework-agnostic JavaScript SDK for changes.page. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install @changespage/core |
| 9 | +``` |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +```ts |
| 14 | +import { createChangesPageClient } from '@changespage/core'; |
| 15 | + |
| 16 | +const client = createChangesPageClient({ |
| 17 | + baseUrl: 'https://yourpage.changes.page' |
| 18 | +}); |
| 19 | + |
| 20 | +const { posts, totalCount, hasMore } = await client.getPosts({ limit: 10 }); |
| 21 | + |
| 22 | +const latestPost = await client.getLatestPost(); |
| 23 | + |
| 24 | +const pinnedPost = await client.getPinnedPost(); |
| 25 | +``` |
| 26 | + |
| 27 | +## API |
| 28 | + |
| 29 | +### `createChangesPageClient(config)` |
| 30 | + |
| 31 | +| Option | Type | Description | |
| 32 | +|--------|------|-------------| |
| 33 | +| `baseUrl` | `string` | Your changes.page URL | |
| 34 | + |
| 35 | +### `client.getPosts(options?)` |
| 36 | + |
| 37 | +| Option | Type | Default | Description | |
| 38 | +|--------|------|---------|-------------| |
| 39 | +| `limit` | `number` | 10 | Posts per page (max 50) | |
| 40 | +| `offset` | `number` | 0 | Pagination offset | |
| 41 | + |
| 42 | +Returns `{ posts, totalCount, hasMore }` |
| 43 | + |
| 44 | +### `client.getLatestPost()` |
| 45 | + |
| 46 | +Returns the most recent post or `null`. |
| 47 | + |
| 48 | +### `client.getPinnedPost()` |
| 49 | + |
| 50 | +Returns the pinned post or `null` if none is pinned. |
| 51 | + |
| 52 | +## Utilities |
| 53 | + |
| 54 | +### `getTagLabel(tag)` |
| 55 | + |
| 56 | +Returns a display label for a post tag. |
| 57 | + |
| 58 | +```ts |
| 59 | +import { getTagLabel } from '@changespage/core'; |
| 60 | + |
| 61 | +getTagLabel('new'); // "New" |
| 62 | +getTagLabel('fix'); // "Fix" |
| 63 | +``` |
| 64 | + |
| 65 | +## Types |
| 66 | + |
| 67 | +```ts |
| 68 | +type PostTag = 'fix' | 'new' | 'improvement' | 'announcement' | 'alert'; |
| 69 | + |
| 70 | +interface Post { |
| 71 | + id: string; |
| 72 | + title: string; |
| 73 | + content: string; |
| 74 | + tags: PostTag[]; |
| 75 | + publication_date: string | null; |
| 76 | + updated_at: string; |
| 77 | + created_at: string; |
| 78 | + url: string; |
| 79 | + plain_text_content: string; |
| 80 | +} |
| 81 | +``` |
0 commit comments