Coder Social home page Coder Social logo

strogo / gotell Goto Github PK

View Code? Open in Web Editor NEW

This project forked from netlify/gotell

0.0 3.0 0.0 45 KB

Netlify Comments is an API and build tool for handling large amounts of comments for JAMstack products

License: MIT License

Makefile 2.87% Go 97.13%

gotell's Introduction

GoTell

A commenting system for JAMstack sites.

How it works

GoTell is both a build tool and a small API.

The API accepts HTTP POST requests to a thread with a JSON body like:

  • POST /2016/09/this-is-a-thread-on-my-site
{
  "author": "Matt Biilmann",
  "email": "[email protected]",
  "www": "https://www.example.com",
  "body": "Hi there - this is a fantastic comment!"
}

GoTell will check to see that the thread exists and verify that it is still open, run some checks on the comment to classify obvious spam, and then push the comment to a Github repository as a JSON document.

That will trigger a build through Netlify with GoTell and a new version of the thread will be pushed as a JSON file to a static endpoint.

From your site, you can fetch comments and comment metadata from the static endpoint and let users POST new comments via the API.

GoTell is not a ready made comment system like Disqus or Facebook Comments, but a buildingblock for making your own custom styled comments on your site.

Getting Started

Setting up the static Comments

First clone our Netlify Comments starter template and push it to your own GitHub account.

Then visit Netlify and pick your new repository. Click Save and Netlify will start building your comment threads

Setting up the API

You'll need to run the API on a server. On the server, we recommend settings these environment variables:

GOTELL_SITE_URL=https://mysite.example.com # URL to your static site
GOTELL_REPOSITORY=user/repo # Username/repo of the GitHub repository created from netliy-comments-starter
GOTELL_ACCESS_TOKEN=1253523421313 # A Personal GitHub Access Token with write permissions to the repository

With these environment variables in place, run:

gotell api

Integrating with your site

Each post on your static site that should have comments, needs to add a metadata tag to it's page like this:

<script id="gotell" type="application/json">{"created_at":"2016-07-07T08:20:36Z"}</script>

To configure GoTell add a file called /gotell/settings.json to your site (this is optional). It should look like this:

{
  "banned_ips": [],
	"banned_keywords": [],
	"banned_emails": [],
	"timelimit": 604800
}

These settings controls the rudimentary spam filter and the time limit from a post is created and until commenting is closed for the thread.

To allow people to comment you'll need your comment form to send a request to the comment API. Here's an example using the modern fetch API:

const thread = document.location.pathname;
fetch(API_URL + thread, {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    author: data.name,
    email: data.email,
    body: data.message,
    parent: data.parent
  })
}).then((response) => {
  console.log("Comment posted!");
});

To display comments for a thread, fetch the JSON via:

const slug = document.location.pathname.replace(/\//g, '-').replace(/(^-|-$)/g, '') + '.json';
fetch(COMMENT_URL + '/' + slug).then((response) => {
  console.log("Got comments: %o", response);
});

GoTell also builds a file called threadname.count.json for each thread with a JSON object looking like:

{"count": 42}

As a lower bandwidth way to fetch comment counts for a thread.

Licence

GoTell is released under the MIT License. Please make sure you understand its implications and guarantees.

gotell's People

Contributors

bertrandkeller avatar biilmann avatar calavera avatar rybit 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.