feat(core): Enhanced post fetching and creation with additional metadata and support for HTML source

This commit is contained in:
2024-07-06 17:47:06 +02:00
parent 5d3cfe2f93
commit d82c58e608
5 changed files with 106 additions and 7 deletions

View File

@@ -18,19 +18,19 @@ export class Ghost {
this.adminApi = new plugins.GhostAdminAPI({
url: this.options.baseUrl,
key: this.options.adminApiKey,
version: "v3"
version: 'v3',
});
this.contentApi = new plugins.GhostContentAPI({
url: this.options.baseUrl,
key: this.options.contentApiKey,
version: "v3"
version: 'v3',
});
}
public async getPosts(limit: number = 1000): Promise<Post[]> {
try {
const postsData = await this.contentApi.posts.browse({ limit });
const postsData = await this.contentApi.posts.browse({ limit, include: 'tags,authors' });
return postsData.map((postData: IPostOptions) => new Post(this, postData));
} catch (error) {
console.error('Error fetching posts:', error);
@@ -57,4 +57,12 @@ export class Ghost {
throw error;
}
}
public async createPostFromHtml(optionsArg: { title: string; html: string }) {
const postData = await this.adminApi.posts.add(
{ title: optionsArg.title, html: optionsArg.html },
{ source: 'html' } // Tell the API to use HTML as the content source, instead of Lexical
);
return new Post(this, postData);
}
}