Ghost provides a flexible promise-based JavaScript library for accessing the Content API. The library can be used in any JavaScript project, client or server side and abstracts away all the pain points of working with API data.
Custom Integration
under the Integrations screen in Ghost Admin.
url
- API domain, must not end in a trailing slash.key
- hex string copied from the “Integrations” screen in Ghost Adminversion
- should be set to ‘v6.0’browse()
method will return an array of objects, and the read()
method will return a single object. The settings.browse()
endpoint always returns a single object with all the available key-value pairs.
See the documentation on Content API resources for a full description of the response for each resource.
yarn add @tryghost/content-api
npm install @tryghost/content-api
You can also use the standalone UMD build:
https://unpkg.com/@tryghost/content-api@{version}/umd/content-api.min.js
filter
parameter to fetch your content with endless possibilities! Especially useful for retrieving posts according to their tags, authors or other properties.
Ghost uses the NQL query language to create filters in a simple yet powerful string format. See the NQL Syntax Reference for full details.
Filters are provided to client libraries via the filter
property of any browse
method.
featured:true
- all resources with a field featured
that is set to true
.featured:true+feature_image:null
- looks for featured posts which don’t have a feature image set by using +
(and).tag:hash-noimg
- tag
is an alias for tags.slug
and hash-noimg
would be the slug for an internal tag called #NoImg
. This filter would allow us to find any post that has this internal tag.tags:[photo, video, audio]
- filters posts which have any one of the listed tags, []
(grouping) is more efficient than using or when querying the same field.primary_author:my-author
- primary_author
is an alias for the first author, allowing for filtering based on the first author.published_at:>'2017-06-03 23:43:12'
- looks for posts published after a date, using a date string wrapped in single quotes and the >
operator@tryghost/helpers
tags
array.
Options
The tag helper supports multiple options so that you can control exactly what is output, without having to write any logic.
limit
{integer} - limits the number of tags to be returnedfrom
{integer, default:1} - index of the tag to start iterating fromto
{integer} - index of the last tag to iterate overseparator
{string, default:”,”} - string used between each tagprefix
{string} - string to output before each tagsuffix
{string} - string to output after each tagvisibility
{string, default:“public”} - change to “all” to include internal tagsfallback
{object} - a fallback tag to output if there are nonefn
{function} - function to call on each tag, default returns tag.namehtml
string. If a feature_image
is present, this is taken into account.
Options
The output of the reading time helper can be customised through format strings.
minute
{string, default:“1 min read”} - format for reading times <= 1 minuteminutes
{string, default:”% min read”} - format for reading times > 1 minuteyarn add @tryghost/helpers
npm install @tryghost/helpers
You can also use the standalone UMD build:
https://unpkg.com/@tryghost/helpers@{version}/umd/helpers.min.js
Usage
ES modules:
@tryghost/string
requiredChangesOnly
{boolean, default:false} - don’t perform optional cleanup, e.g. removing extra dashesyarn add @tryghost/string
npm install @tryghost/string
Usage
Node.js: