feat(ghost): Implement Tag, Author and Page models; add advanced filtering, search, bulk operations, image upload, related-posts, update tests and bump dependencies
This commit is contained in:
65
ts/classes.page.ts
Normal file
65
ts/classes.page.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import type { Ghost } from './classes.ghost.js';
|
||||
import type { IPost, IAuthor } from './classes.post.js';
|
||||
|
||||
export interface IPage extends IPost {}
|
||||
|
||||
export class Page {
|
||||
public ghostInstanceRef: Ghost;
|
||||
public pageData: IPage;
|
||||
|
||||
constructor(ghostInstanceRefArg: Ghost, pageData: IPage) {
|
||||
this.ghostInstanceRef = ghostInstanceRefArg;
|
||||
this.pageData = pageData;
|
||||
}
|
||||
|
||||
public getId(): string {
|
||||
return this.pageData.id;
|
||||
}
|
||||
|
||||
public getTitle(): string {
|
||||
return this.pageData.title;
|
||||
}
|
||||
|
||||
public getHtml(): string {
|
||||
return this.pageData.html;
|
||||
}
|
||||
|
||||
public getSlug(): string {
|
||||
return this.pageData.slug;
|
||||
}
|
||||
|
||||
public getFeatureImage(): string | undefined {
|
||||
return this.pageData.feature_image;
|
||||
}
|
||||
|
||||
public getAuthor(): IAuthor {
|
||||
return this.pageData.primary_author;
|
||||
}
|
||||
|
||||
public toJson(): IPage {
|
||||
return this.pageData;
|
||||
}
|
||||
|
||||
public async update(pageData: Partial<IPage>): Promise<Page> {
|
||||
try {
|
||||
const updatedPageData = await this.ghostInstanceRef.adminApi.pages.edit({
|
||||
...pageData,
|
||||
id: this.getId()
|
||||
});
|
||||
this.pageData = updatedPageData;
|
||||
return this;
|
||||
} catch (error) {
|
||||
console.error('Error updating page:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
public async delete(): Promise<void> {
|
||||
try {
|
||||
await this.ghostInstanceRef.adminApi.pages.delete({ id: this.getId() });
|
||||
} catch (error) {
|
||||
console.error(`Error deleting page with id ${this.getId()}:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user