Skip to content

Commit f6ea991

Browse files
authored
Merge pull request #127 from techulus/develop
2 parents 2fe485b + 6bfa4e3 commit f6ea991

21 files changed

Lines changed: 281 additions & 92 deletions

File tree

apps/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"dependencies": {
1313
"@ai-sdk/react": "^2.0.115",
1414
"@arcjet/next": "1.0.0-alpha.20",
15-
"@changespage/react": "workspace:*",
15+
"@changespage/react": "0.2.0",
1616
"@changespage/supabase": "workspace:*",
1717
"@changespage/ui": "workspace:*",
1818
"@changespage/utils": "workspace:*",

apps/web/pages/changelog.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@ export default function Changelog({
4747
<div className="space-y-12">
4848
{posts.map((post, index) => (
4949
<ChangelogPost key={post.id} post={post}>
50-
{({ title, content, tags, formattedDate }) => (
50+
{({ title, content, tags, publicationDate }) => (
5151
<article className="md:border-l-2 md:border-gray-200 md:dark:border-gray-700 md:pl-6">
52-
<time className="text-sm text-gray-500 dark:text-gray-400">
53-
{formattedDate}
54-
</time>
52+
{publicationDate && (
53+
<time className="text-sm text-gray-500 dark:text-gray-400">
54+
{new Date(publicationDate).toLocaleDateString("en-US", {
55+
year: "numeric",
56+
month: "long",
57+
day: "numeric",
58+
})}
59+
</time>
60+
)}
5561
<h2 className={`text-2xl font-semibold text-gray-900 dark:text-white mt-1 mb-3 underline ${UNDERLINE_COLORS[index % UNDERLINE_COLORS.length]}`}>
5662
{title}
5763
</h2>

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "changes-page",
33
"version": "1.1.0",
4+
"private": true,
45
"scripts": {
56
"build": "pnpm --filter './packages/*' -r build",
67
"dev:page": "pnpm --filter './apps/page' -r dev",

packages/core-sdk/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
```

packages/core-sdk/package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "@changespage/core",
3+
"version": "0.1.0",
4+
"type": "module",
5+
"module": "./dist/index.js",
6+
"types": "./dist/index.d.ts",
7+
"exports": {
8+
".": {
9+
"import": "./dist/index.js",
10+
"types": "./dist/index.d.ts"
11+
}
12+
},
13+
"files": [
14+
"dist"
15+
],
16+
"scripts": {
17+
"build": "rimraf dist && tsc",
18+
"prepublishOnly": "npm run build"
19+
},
20+
"dependencies": {},
21+
"devDependencies": {
22+
"rimraf": "^6.1.0",
23+
"typescript": "^5.3.3"
24+
},
25+
"author": "Arjun Komath <arjunkomath@gmail.com>",
26+
"license": "MIT",
27+
"repository": {
28+
"type": "git",
29+
"url": "https://github.com/techulus/changes-page.git"
30+
},
31+
"publishConfig": {
32+
"access": "public"
33+
}
34+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,30 @@ export function createChangesPageClient(config: ClientConfig): ChangesPageClient
5252
return result.posts[0] ?? null;
5353
}
5454

55+
async function getPinnedPost(): Promise<Post | null> {
56+
const response = await fetch(`${baseUrl}/api/pinned`, {
57+
headers: {
58+
"X-API-Version": API_VERSION,
59+
},
60+
});
61+
62+
if (!response.ok) {
63+
if (response.status === 404) {
64+
return null;
65+
}
66+
const errorData = await response.json().catch(() => ({}));
67+
const errorMessage =
68+
(errorData as { error?: string }).error || response.statusText;
69+
throw new Error(errorMessage);
70+
}
71+
72+
const data: Post | null = await response.json();
73+
return data;
74+
}
75+
5576
return {
5677
getPosts,
5778
getLatestPost,
79+
getPinnedPost,
5880
};
5981
}

packages/core-sdk/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export { createChangesPageClient } from "./client";
2+
export { getTagLabel } from "./utils";
3+
export type {
4+
ChangesPageClient,
5+
ClientConfig,
6+
GetPostsOptions,
7+
GetPostsResult,
8+
Post,
9+
PostTag,
10+
} from "./types";

packages/core-sdk/src/types.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export type PostTag = "fix" | "new" | "improvement" | "announcement" | "alert";
2+
3+
export interface Post {
4+
id: string;
5+
title: string;
6+
content: string;
7+
tags: PostTag[];
8+
publication_date: string | null;
9+
updated_at: string;
10+
created_at: string;
11+
url: string;
12+
plain_text_content: string;
13+
}
14+
15+
export interface ClientConfig {
16+
baseUrl: string;
17+
}
18+
19+
export interface GetPostsOptions {
20+
limit?: number;
21+
offset?: number;
22+
}
23+
24+
export interface GetPostsResult {
25+
posts: Post[];
26+
totalCount: number;
27+
hasMore: boolean;
28+
}
29+
30+
export interface ChangesPageClient {
31+
getPosts: (options?: GetPostsOptions) => Promise<GetPostsResult>;
32+
getLatestPost: () => Promise<Post | null>;
33+
getPinnedPost: () => Promise<Post | null>;
34+
}

packages/core-sdk/src/utils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { PostTag } from "./types";
2+
3+
const tagLabels: Record<PostTag, string> = {
4+
fix: "Fix",
5+
new: "New",
6+
improvement: "Improvement",
7+
announcement: "Announcement",
8+
alert: "Alert",
9+
};
10+
11+
export function getTagLabel(tag: PostTag): string {
12+
return tagLabels[tag] ?? tag;
13+
}

packages/core-sdk/tsconfig.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "ESNext",
5+
"moduleResolution": "bundler",
6+
"lib": ["ES2022", "DOM"],
7+
"declaration": true,
8+
"declarationMap": true,
9+
"sourceMap": true,
10+
"rootDir": "./src",
11+
"outDir": "./dist",
12+
"strict": true,
13+
"esModuleInterop": true,
14+
"skipLibCheck": true,
15+
"forceConsistentCasingInFileNames": true,
16+
"isolatedModules": true,
17+
"verbatimModuleSyntax": true
18+
},
19+
"include": ["src"],
20+
"exclude": ["node_modules", "dist"]
21+
}

0 commit comments

Comments
 (0)