@content-streamline/nextjs 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/client.d.ts +2 -2
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +9 -4
- package/dist/components/PostsList.d.ts +8 -1
- package/dist/components/PostsList.d.ts.map +1 -1
- package/dist/components/PostsList.js +7 -3
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +13 -3
- package/package.json +1 -2
package/dist/api/client.d.ts
CHANGED
|
@@ -10,11 +10,11 @@ declare class ContentStreamlineAPI {
|
|
|
10
10
|
/**
|
|
11
11
|
* List all posts with pagination
|
|
12
12
|
*/
|
|
13
|
-
listPosts(page?: number): Promise<PostsResponse>;
|
|
13
|
+
listPosts(page?: number, platform?: string): Promise<PostsResponse>;
|
|
14
14
|
/**
|
|
15
15
|
* Get all posts by fetching all pages
|
|
16
16
|
*/
|
|
17
|
-
getAllPosts(): Promise<Post[]>;
|
|
17
|
+
getAllPosts(platform?: string): Promise<Post[]>;
|
|
18
18
|
/**
|
|
19
19
|
* Get a single post by ID
|
|
20
20
|
*/
|
package/dist/api/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,IAAI,EACJ,kBAAkB,EAClB,aAAa,EACd,MAAM,mBAAmB,CAAC;AAE3B,cAAM,oBAAoB;IACxB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAS;gBAEhB,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;YAKlC,KAAK;IAiCnB;;OAEG;IACG,SAAS,CAAC,IAAI,GAAE,MAAU,GAAG,OAAO,CAAC,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,IAAI,EACJ,kBAAkB,EAClB,aAAa,EACd,MAAM,mBAAmB,CAAC;AAE3B,cAAM,oBAAoB;IACxB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAS;gBAEhB,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;YAKlC,KAAK;IAiCnB;;OAEG;IACG,SAAS,CAAC,IAAI,GAAE,MAAU,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAS5E;;OAEG;IACG,WAAW,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAgBrD;;OAEG;IACG,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,aAAa,GAAE,UAAU,GAAG,MAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAIxG;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,oBAAoB,CAE1F"}
|
package/dist/api/client.js
CHANGED
|
@@ -38,18 +38,23 @@ class ContentStreamlineAPI {
|
|
|
38
38
|
/**
|
|
39
39
|
* List all posts with pagination
|
|
40
40
|
*/
|
|
41
|
-
async listPosts(page = 1) {
|
|
42
|
-
|
|
41
|
+
async listPosts(page = 1, platform) {
|
|
42
|
+
const params = new URLSearchParams();
|
|
43
|
+
params.set('page', page.toString());
|
|
44
|
+
if (platform) {
|
|
45
|
+
params.set('platform', platform);
|
|
46
|
+
}
|
|
47
|
+
return this.fetch(`/public/v1/posts?${params.toString()}`);
|
|
43
48
|
}
|
|
44
49
|
/**
|
|
45
50
|
* Get all posts by fetching all pages
|
|
46
51
|
*/
|
|
47
|
-
async getAllPosts() {
|
|
52
|
+
async getAllPosts(platform) {
|
|
48
53
|
const allPosts = [];
|
|
49
54
|
let currentPage = 1;
|
|
50
55
|
let hasMore = true;
|
|
51
56
|
while (hasMore) {
|
|
52
|
-
const response = await this.listPosts(currentPage);
|
|
57
|
+
const response = await this.listPosts(currentPage, platform);
|
|
53
58
|
allPosts.push(...response.data);
|
|
54
59
|
hasMore = response.pagination.next_page !== null;
|
|
55
60
|
currentPage = response.pagination.next_page || currentPage + 1;
|
|
@@ -7,6 +7,13 @@ export interface PostsListProps {
|
|
|
7
7
|
* Post URL will be: {baseUrl}/{postId}/{slug}
|
|
8
8
|
*/
|
|
9
9
|
baseUrl?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Platform filter for posts (default: 'blog')
|
|
12
|
+
* Valid values: 'x', 'linkedin', 'blog', 'facebook', 'instagram', 'other'
|
|
13
|
+
* Filters the posts to only show those matching this platform.
|
|
14
|
+
* For best performance, also pass platform to getAllPosts() when fetching.
|
|
15
|
+
*/
|
|
16
|
+
platform?: string;
|
|
10
17
|
/**
|
|
11
18
|
* Language to use for post translations (default: 'en')
|
|
12
19
|
*/
|
|
@@ -40,5 +47,5 @@ export interface PostsListProps {
|
|
|
40
47
|
*/
|
|
41
48
|
renderExcerpt?: (post: Post, translation: Post['post_translations'][0]) => React.ReactNode;
|
|
42
49
|
}
|
|
43
|
-
export declare function PostsList({ posts, baseUrl, language, className, cardClassName, showDate, showExcerpt, showImages, renderTitle, renderExcerpt, }: PostsListProps): import("react/jsx-runtime").JSX.Element;
|
|
50
|
+
export declare function PostsList({ posts, baseUrl, platform, language, className, cardClassName, showDate, showExcerpt, showImages, renderTitle, renderExcerpt, }: PostsListProps): import("react/jsx-runtime").JSX.Element;
|
|
44
51
|
//# sourceMappingURL=PostsList.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostsList.d.ts","sourceRoot":"","sources":["../../src/components/PostsList.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE9C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AAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,SAAS,CAAC;IACzF;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,SAAS,CAAC;CAC5F;AAED,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,OAAkB,EAClB,QAAiB,EACjB,QAAe,EACf,SAAc,EACd,aAAkB,EAClB,QAAe,EACf,WAAkB,EAClB,UAAiB,EACjB,WAAW,EACX,aAAa,GACd,EAAE,cAAc,2CAmFhB"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
export function PostsList({ posts, baseUrl = '/posts', language = 'en', className = '', cardClassName = '', showDate = true, showExcerpt = true, showImages = true, renderTitle, renderExcerpt, }) {
|
|
4
|
-
|
|
3
|
+
export function PostsList({ posts, baseUrl = '/posts', platform = 'blog', language = 'en', className = '', cardClassName = '', showDate = true, showExcerpt = true, showImages = true, renderTitle, renderExcerpt, }) {
|
|
4
|
+
// Filter posts by platform if specified
|
|
5
|
+
const filteredPosts = platform
|
|
6
|
+
? posts.filter(post => post.platform.toLowerCase() === platform.toLowerCase())
|
|
7
|
+
: posts;
|
|
8
|
+
if (filteredPosts.length === 0) {
|
|
5
9
|
return (_jsx("div", { className: `content-streamline-empty ${className}`, children: _jsx("p", { children: "No posts found." }) }));
|
|
6
10
|
}
|
|
7
|
-
return (_jsx("div", { className: `content-streamline-posts-list ${className}`, children:
|
|
11
|
+
return (_jsx("div", { className: `content-streamline-posts-list ${className}`, children: filteredPosts.map((post) => {
|
|
8
12
|
const translation = post.post_translations.find((t) => t.language === language) ||
|
|
9
13
|
post.post_translations[0];
|
|
10
14
|
if (!translation || !translation.slug)
|
package/dist/server/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { Post, PostDetailResponse } from '../types/index.js';
|
|
|
10
10
|
export declare function getAllPosts(options?: {
|
|
11
11
|
maxCacheAge?: number;
|
|
12
12
|
forceRefresh?: boolean;
|
|
13
|
+
platform?: string;
|
|
13
14
|
}): Promise<Post[]>;
|
|
14
15
|
/**
|
|
15
16
|
* Get a single post by ID
|
|
@@ -30,6 +31,7 @@ export declare function getPostBySlug(slug: string, options?: {
|
|
|
30
31
|
contentFormat?: 'markdown' | 'html';
|
|
31
32
|
maxCacheAge?: number;
|
|
32
33
|
forceRefresh?: boolean;
|
|
34
|
+
platform?: string;
|
|
33
35
|
}): Promise<PostDetailResponse | null>;
|
|
34
36
|
export type { Post, PostDetailResponse, PostTranslation, PostImage, PostsResponse, Pagination, } from '../types/index.js';
|
|
35
37
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAkBlE;;;GAGG;AACH,wBAAsB,WAAW,CAAC,OAAO,CAAC,EAAE;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAkBlE;;;GAGG;AACH,wBAAsB,WAAW,CAAC,OAAO,CAAC,EAAE;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CA2ClB;AAED;;;GAGG;AACH,wBAAsB,OAAO,CAC3B,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE;IACR,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,GACA,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAiCpC;AAED;;;GAGG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IACR,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACA,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CA2BpC;AAGD,YAAY,EACV,IAAI,EACJ,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,aAAa,EACb,UAAU,GACX,MAAM,mBAAmB,CAAC"}
|
package/dist/server/index.js
CHANGED
|
@@ -20,21 +20,30 @@ function getAPIConfig() {
|
|
|
20
20
|
* Use this in Server Components or API Routes
|
|
21
21
|
*/
|
|
22
22
|
export async function getAllPosts(options) {
|
|
23
|
-
const { maxCacheAge = 60, forceRefresh = false } = options || {};
|
|
23
|
+
const { maxCacheAge = 60, forceRefresh = false, platform } = options || {};
|
|
24
24
|
// Check cache freshness
|
|
25
25
|
if (!forceRefresh) {
|
|
26
26
|
const needsRefresh = await shouldRefreshCache(maxCacheAge);
|
|
27
27
|
if (!needsRefresh) {
|
|
28
28
|
const cached = await getAllCachedPosts();
|
|
29
29
|
if (cached.length > 0) {
|
|
30
|
-
|
|
30
|
+
// Filter cached posts by platform if specified
|
|
31
|
+
if (platform) {
|
|
32
|
+
const filtered = cached.filter(post => post.platform.toLowerCase() === platform.toLowerCase());
|
|
33
|
+
if (filtered.length > 0) {
|
|
34
|
+
return filtered;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return cached;
|
|
39
|
+
}
|
|
31
40
|
}
|
|
32
41
|
}
|
|
33
42
|
}
|
|
34
43
|
// Fetch from API
|
|
35
44
|
const { baseUrl, accessToken } = getAPIConfig();
|
|
36
45
|
const api = createAPIClient(baseUrl, accessToken);
|
|
37
|
-
const posts = await api.getAllPosts();
|
|
46
|
+
const posts = await api.getAllPosts(platform);
|
|
38
47
|
// Cache all posts
|
|
39
48
|
for (const post of posts) {
|
|
40
49
|
try {
|
|
@@ -88,6 +97,7 @@ export async function getPostBySlug(slug, options) {
|
|
|
88
97
|
const posts = await getAllPosts({
|
|
89
98
|
maxCacheAge: options?.maxCacheAge,
|
|
90
99
|
forceRefresh: options?.forceRefresh,
|
|
100
|
+
platform: options?.platform,
|
|
91
101
|
});
|
|
92
102
|
const language = options?.language || 'en';
|
|
93
103
|
// Find post with matching slug
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@content-streamline/nextjs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Next.js library for Content Streamline API with reusable components",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -49,4 +49,3 @@
|
|
|
49
49
|
"README.md"
|
|
50
50
|
]
|
|
51
51
|
}
|
|
52
|
-
|