Giter VIP home page Giter VIP logo

contentbot's Introduction

Contentbot

Under construction, use at your own risk. This repo does not respect semver (yet) - things may break at any time.

GraphQL schema & API for creating/reading/updating/deleting pages in a static website which stores pages in a simple format on the file system, similarly to Kirby.

Usage

1. Define your schema

Define a file site.graphql containing the types of pages that your site should support, and the custom fields that should be included on each page:

type About {
  bio: String
}

type Film  {
  role: String
  pitch: String
  description: String
  youtubeUrl: String
}

(You will not be able to add any arguments to the fields.)

Contentbot will generate the following GraphQL schema:

# TODO

For every type in site.graphql, it will create a set of CRUD mutations, and a corresponding input type.

2. Serve the schema

eg. using graphql-yoga:

const Contentbot = require('contentbot')
const GraphQLServer = require('graphql-yoga')

const schema = `
type About {
  bio: String
}

type Film  {
  role: String
  pitch: String
  description: String
  youtubeUrl: String
}
`

async function main() {
  const contentbot = await Contentbot('content', { schema })
  const server = new GraphQLServer({ schema: contentbot })
  server.start()
}
main()

3. Start querying it from your frontend!

For example, to add a new film page:

mutation {
  writeFilm(content: {url: "/film/national-youth-orchestra", title: "Meet the National Youth Orchestra of Great Britain", youtubeUrl: "https://www.youtube.com/watch?v=uv2Y4AoWA-w"}) {
    url
  }
}

You can then get the film page like this:

query {
  page(url: "/film/national-youth-orchestra") {
    url
    title
    ... on Film {
      youtubeUrl
    }
  }
}

Notice that the query uses an inline fragment, which is required to get the type-specific custom fields. You can also define multiple inline fragments, so you could reuse the same query for different page types, for example:

query AnyPage($url: String!) {
  page(url: $url) {
    __typename
    url
    title
    ... on Film {
      youtubeUrl
    }
    ... on About {
      bio
    }
  }
}

You could then check the __typename field, and render different templates for different types of pages.

contentbot's People

Contributors

lachenmayer avatar

Watchers

 avatar  avatar  avatar

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.