Files
ghost/ts/classes.page.ts

66 lines
1.5 KiB
TypeScript
Raw Permalink Normal View History

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;
}
}
}