@mobizerg/nest-ghost-content-api
v0.1.3
Published
Ghost Content Api integration module for Nest.js framework
Downloads
8
Maintainers
Readme
Installation
Yarn
yarn add @mobizerg/nest-ghost-content-api @tryghost/content-api
NPM
npm install @mobizerg/nest-ghost-content-api @tryghost/content-api --save
Description
Ghost Content Api integration module for Nest.js based on the Ghost Content Api package.
Usage
Import the GhostContentApiModule in app.module.ts
import { Module } from '@nestjs/common';
import { GhostContentApiModule } from '@mobizerg/nest-ghost-content-api';
@Module({
imports: [
GhostContentApiModule.register(options),
],
})
export class AppModule {}
With Async
import { Module } from '@nestjs/common';
import { GhostContentApiModule } from '@mobizerg/nest-ghost-content-api';
@Module({
imports: [
GhostContentApiModule.registerAsync({
imports: [ConfigModule],
useExisting: GhostContentApiConfigService,
}),
],
})
export class AppModule {}
Example config file (async)
import { Injectable } from '@nestjs/common';
import { ConfigService } from './config.service';
import { GhostContentApiModuleOptions, GhostContentApiOptionsFactory } from '@mobizerg/nest-ghost-content-api';
@Injectable()
export class GhostContentApiConfigService implements GhostContentApiOptionsFactory {
constructor(private readonly config: ConfigService) {}
createGhostContentApiOptions(name?: string): GhostContentApiModuleOptions {
return {
name,
url: 'https://demo.ghost.io',
key: '22444f78447824223cefc48062',
version: 'v3',
};
}
}
Importing inside services
import { Injectable } from '@nestjs/common';
import { GhostContentApiService, PostResponse } from '@mobizerg/nest-ghost-content-api';
@Injectable()
export class BlogService {
constructor(private readonly ghostContentApiService: GhostContentApiService) {}
async findPosts(): Promise<PostResponse> {
return await this.ghostContentApiService.findPosts({
filter: 'tag:demo',
page: query.page,
limit: query.limit,
order: {
propertyName: 'created_at',
sortOrder: Order.ASC,
},
});
}
}
License
MIT