0.1.3 • Published 4 years ago

@mobizerg/nest-ghost-content-api v0.1.3

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

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

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago