Giter Site home page Giter Site logo

metalsmith-disqus's Introduction

metalsmith-disqus

npm version npm

A Metalsmith plugin that adds Disqus commenting widget and counter scripts. For more information you can read article.

Installation

$ npm install --save-dev metalsmith-disqus

Usage

Place metalsmith-disqus plugin after html files generation, for example after metalsmith-layouts.

const Metalsmith = require('metalsmith');
const disqus     = require('metalsmith-disqus');

Metalsmith(__dirname)
  ...
  .use(disqus({
    siteurl: 'my-site.com',
    shortname: 'my-site'
  }));

In your templates you need to add <div id="disqus_thread"></div> for commenting widget. For comments counter add element with class name disqus-comment-count and data attribute data-disqus-key with renedered key to generate id.

Examples:

Page with comments template using handlebars:

<p>Your page markup<p>
{{#if comments }}
<!-- Comments widget will be rendered in this element -->
<div id="disqus_thread"></div>
{{/if}}

Page with counters template using handlebars:

<p>Your page markup<p>

{{#if comments }}
<!-- Comments counter will be rendered in this element -->
<span class="disqus-comment-count" data-disqus-key="{{title}}"></span>
{{/if}}

To enable comments for page just add comments: true to page metadata. Example:

---
title: Hello World
comments: true
---

To enable comments counter for page just add comments-counter: true to page metadata. Example:

---
title: Post
comments-counter: true
---

To add Disqus DNS prefetch for entry page, for example homepage just add disqus-dns-prefetch: true to page metadata. It will speed up disqus scripts loading. Example:

---
title: My home page
disqus-dns-prefetch: true
---

To add Disqus scripts prefetch for page just add disqus-prefetch-widget: true (for comments widget script) or disqus-prefetch-counter: true (for counter script) to page metadata. It will speed up disqus scripts loading. Example:

---
title: My home page
disqus-prefetch-widget: true
disqus-prefetch-counter: true
---

Counter class name selector can be configured with options.

Options

siteurl - Required

Type: String

Default: ''

Your site url, used to generate page url in Disqus configuration.

shortname - Required

Type: String

Default: ''

Your site short name configured in Disqus, used to generate page url in Disqus configuration.

path

Type: String

Default: 'path'

Propery key in file metadata to get page path, used to generate page url in Disqus configuration. By default uses path property that metalsmith-permalinks plugins adds.

title

Type: String

Default: 'title'

Propery key in file metadata to get page title, used as page title in Disqus configuration.

identifier

Type: String

Default: 'title'

Propery key in file metadata to generate page identifier, used as page identifier in Disqus configuration.

counterSelector

Type: String

Default: '.disqus-comment-count'

CSS selector string to find elements in page template inside whitch insetr comments counter.

CLI

You can also use the plugin with the Metalsmith CLI by adding a key to your metalsmith.json file:

{
  "plugins": {
    "metalsmith-disqus": {
      "siteurl": "my-site.com",
      "shortname": "my-site"
    }
  }
}

License

MIT

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.