Giter Site home page Giter Site logo

gatsby-plugin-gitalk's Introduction

Gatsby Plugin Gitalk

A plugin that simplifies adding Gitalk comments to Gatsby

Demo

Demo

https://github.com/suziwen/my-gatsby-gitalk-demo

Description

The goal of this plugin is to allow users to bring their content to life and cultivate engaged communities by integrating Gitalk comments into their blazing-fast Gatsby websites. After struggling to integrate different Gitalk components into my Gatsby site, creating an easily-configured plugin for the Gatsby ecosystem felt like a no-brainer.

Install

$ yarn add gatsby-plugin-gitalk

or

$ npm install -S gatsby-plugin-gitalk

Configure

Add the plugin to your gatsby-config.js file with your Gitalk config

// gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: `gatsby-plugin-gitalk`,
      options: {
        config: gitalkConfig
      }
    },
  ]
}

Usage

You can use the plugin as shown in this brief example:

import Gitalk from 'gatsby-plugin-gitalk'
import '@suziwen/gitalk/dist/gitalk.css'

const PostTemplate = () => {
  let gitalkConfig = {
    id: post.slug || post.id,
    title: post.title,
  }
  return (
     <Gitalk options={gitalkConfig}/>
  )
}

export default PostTemplate

Custom style

Copy the file node_modules/@suziwen/gitalk/dist/gitalk.css , and edit it, then import your modified version.

Auto create new issue

This operation is option, you can create issue manually

// gatsby-node.js

....
const {GitalkPluginHelper} = require('gatsby-plugin-gitalk');
const gitalkOpts = {...}
....
exports.createPages = async ({ graphql, actions, getNode, reporter }) => {

  // this token (GITALK_CREATE_ISSUE_TOKEN) apply from https://github.com/settings/tokens/new
  // which must have create new issue permission,
  // and for security issue, dont push public
  const gitalkCreateIssueToken = process.env.GITALK_CREATE_ISSUE_TOKEN
  // Due to github api request limit, it is recommended to  create issue for recently added articles
  // select articles from table order by createdate desc limit 10
  if (gitalkOpts && gitalkCreateIssueToken) {
    for (let i=0; i< articles.length; i++) {
      const article = articles[i];
      const issueOptions = Object.assign({}, gitalkOpts, {
        id: '{article.id}',
        title: '{article.title}',
        description: '{article.description}',
        url: '{article.url}',
      }, {
        personalToken: gitalkCreateIssueToken
      })
      // this function will try create new issue when it doesnt exist;
      await GitalkPluginHelper.createIssue(issueOptions)
      reporter.info(`create issue success`)
    }
  }

gatsby-plugin-gitalk's People

Contributors

suziwen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gatsby-plugin-gitalk's Issues

Validation Failed

Hello, I'm trying to get this plugin to work.

Here's my gatsby-config.js:

let gitalkConfig =
  {
    clientID: `value from OAuth application settings`,
    clientSecret: `value from OAuth application settings`,
    repo: `.git link of my repo given by GitHub`,
    owner: `my GitHub username`,
    admin: [`my GitHub username`],
    language: `en`
  }
module.exports =
  {
    plugins: [
      {
        resolve: `gatsby-plugin-gitalk`,
          options:
            {
              config: gitalkConfig
            }
      }]
  }

In my post.js, I've this:

import Gitalk from 'gatsby-plugin-gitalk'
const Post = ( ) =>
  {
    let gitalkConfig = {id: path, title: title} //path and title give me the respective details in my case
    return ({<Gitalk options = {gitalkConfig}/>})
  }
export default Post

However, on the page, once it's rendered, I get this

Error: Validation Failed. The listed users and repositories cannot be searched either because the resources do not exist or you do not have permission to view them.

I've no idea what am I doing wrong. Is it because I'm just viewing this in development and my code isn't on GitHub yet? Seems unlikely though.

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.