npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gathercontent.js

v1.0.1

Published

A helpful JS library for GatherContent.

Downloads

202

Readme

'GatherContent & JS working together'

gathercontent.js

A Javascript library for getting content out of GatherContent.

Install

npm install gathercontent.js

Usage

Content is written on items in GatherContent. Items are stored in projects, so the main function in this library is called getProjectData.

import { getProjectData } from "gathercontent.js"

const projectId = "project_id" // you can find the id in your project settings.
const credentials = {
  email: "[email protected]", // the one you signed up with. 😊
  apiKey: "api_key", // https://docs.gathercontent.com/reference#authentication 🔑
}

const project = getProjectData(projectId, credentials)

getProjectData returns key pieces of project data from the GatherContent API.

{
  project: {},
  folders: [],
  templates: [],
  items: [],
}

Data structure

You can understand the structure of the data by reading the API docs;

Items are a little more complex;

Content is retrieved and sorted into an itemContent property;

const item = {
  ...itemProperties,
  itemContent: {
    slugOfFieldGroup: {
      slugOfField: "This is content",
    },
  },
}

Slugs

This library appends slugs where helpful by converting the name. Items, templates, folders and workflow statuses all have slugs added. For content, we use the slug to help key the fields.

const item = {
  name: "Hello [world]",
  slug: "hello-world", // item name is converted
  itemContent: {
    metaData: {
      // field group name is converted
      pageHeading: "Page heading", // field name is converted
    },
  },
}

Using the name for slugs is logical but comes with a downside, duplicate names.

Duplicate names are automatically handled. For example if you have a group of fields with duplicate names the conversion will append a position to the end of the key. E.g. fieldName2.

Casing

The GatherContent api uses snake case but this library converts the data to camelcase.

const itemBefore = {
  id: 0,
  project_id: 0,
  folder_uuid: "uuid",
}

const itemAfter = {
  id: 0,
  projectId: 0,
  folderUuid: "uuid",
}

Testing

To run the tests you can run;

npm run test

When you are testing the use of gathercontent.js there are a number of helpers that can aid the mocking of http requests.

You can find these in __tests__/mocks/nocks. We utilise the nock package to do this.

Or if you wish you can also mock the implementation of functions like getProjectData so it can return a specific response for your testing needs.

Rate Limiting

GatherContent implements rate limiting (as many APIs do). This library implements a repeat and proactive rate limiting strategy, which should handle all your needs.

Feedback

If you have feedback or experience any issues, create a Github issue.

You're more than welcome to contribute to the repo. To do so fork the repo, create a PR and be sure to test your work before submitting it 🙌