Code Monkey home page Code Monkey logo

nuxtjs-ghost's Introduction

nuxtjs-ghost

build npm version npm downloads bundle size License

NuxtJS module to easily interact with the ๐Ÿ‘ป Ghost API

๐Ÿ“– Release Notes

Setup

To start using the module you first need to install it using the package manager of your choice.

Installation with yarn

yarn add nuxtjs-ghost

Installation with npm

npm install nuxtjs-ghost

After that you need to register the plugin, that NuxtJS can pick it up. To do this, add nuxtjs-ghost to your modules section of nuxt.config.js.

{
  modules: [
    'nuxtjs-ghost',
  ]
}

Configuration

The plugin needs an API key of your site and its endpoint URL. Optionally you can pass the version of the Ghost API you want to use. Typically the endpoint for your API is your sites hostname.

To set these values you have two options:

  1. Use the default module options
  2. Add your options globally to the nuxt.config.js
  3. Use environment variables

Module Options

When registering the module, don't register it as a string, but an array. The syntax should be:

{
  modules: [
    [
      'nuxtjs-ghost',
      {
        url: 'YOUR_API_ENDPOINT',
        key: 'YOUR_API_KEY'
      }
    ]
  ]
}

Global Configuration

To set up a global configuration, add the following object to your export of nuxt.config.js:

ghost: {
  url: 'YOUR_API_ENDPOINT',
  key: 'YOUR_API_KEY'
}

Environment Variables

If you don't want sensitive data in your code, or got multiple environments, you can use environment variables to configure this plugin.

GHOST_API_KEY: Sets the API key. GHOST_API_URL: Sets the API endpoint.

Usage

The usage is pretty straight forward. This package is just a wrapper for the official JavaScript Content API. Please check out their documentation to learn about filtering or pagination. The filter parameter of the following methods is an object representation of the available query filters.

To access the wrapper it is getting exposed to the application context as $ghost. Use it in your pages created(), or mounted() functions using this.

export default {
  async created() {
    const posts = await this.$ghost.getPosts()
  }
}

Or use it in SSR-mode inside of asyncData()

export default {
  async asyncData({ $ghost }) {
    const posts = await $ghost.getPosts()
    return {
      posts
    }
  }
}

All available methods are documented below:


async getPosts(filter) - Gets all posts matching the filter query.

Parameters:

  • (optional) filter: Object used for filtering. E.g.: {limit: 2, include: 'tags,authors'}

Returns: An array of posts


async getPost(query, filter) - Gets the post matching the identifier given in query.

Parameters:

  • query: Object giving the identifier of the post. Can be slug or id. E.g.: {slug: 'my-post'}
  • (optional) filter: Object used for filtering. E.g.: {formats: ['html', 'plaintext']}}

Returns: An object representing a post


async getAuthors(filter) - Gets all authors matching the filter query.

Parameters:

  • (optional) filter: Object used for filtering. E.g.: {include: 'count.posts'}

Returns: An array of authors


async getAuthor(query, filter) - Gets the author matching the identifier given in query.

Parameters:

  • query: Object giving the identifier of the author. Can be slug or id. E.g.: {id: '1234'}
  • (optional) filter: Object used for filtering. E.g.: {page: 2}

Returns: An object representing an author


async getTags(filter) - Gets all tags matching the filter query.

Parameters:

  • (optional) filter: Object used for filtering. E.g.: {include: 'count.posts'}

Returns: An array of tags


async getTag(query, filter) - Gets the tag matching the identifier given in query.

Parameters:

  • query: Object giving the identifier of the tag. Can be slug or id. E.g.: {id: '1234'}
  • (optional) filter: Object used for filtering. E.g.: {include: 'count.posts'}

Returns: An object representing a tag


async getPages(filter) - Gets all pages matching the filter query.

Parameters:

  • (optional) filter: Object used for filtering. E.g.: {limit: 2}

Returns: An array of pages


async getPage(query, filter) - Gets the page matching the identifier given in query.

Parameters:

  • query: Object giving the identifier of the page. Can be slug or id. E.g.: {id: '1234'}
  • (optional) filter: Object used for filtering. E.g.: {fields: ['title']}

Returns: An object representing a page


async getSettings() - Gets your sites settings.

Returns: An object representing your settings


Development

  1. Clone this repository
  2. Install dependencies using yarn install or npm install
  3. Start development server using npm run dev

License

MIT License

Copyright (c) Tobias Dittmann

nuxtjs-ghost's People

Contributors

dependabot[bot] avatar ditschedev avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

nuxtjs-ghost's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Using npm packages for Renovate presets is now deprecated. Please migrate to repository-based presets instead.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/setup-node v3
  • actions/cache v3
  • codecov/codecov-action v3
npm
package.json
  • @tryghost/content-api ^1.11.4
  • babel-jest ^28.1.3
  • jest ^28.1.3
  • nuxt-edge ^2.13.0-26541346.39dd866b

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.