@washingtonpost/talk-plugin-comment-count
TypeScript icon, indicating that this package has built-in type declarations

0.0.6-beta • Public • Published

talk-plugin-comment-count

This plugin enables a simple little embed that can live alongside any given Talk install:

<!-- By default, the /static/embed/count.js will replace the contents of the element targeted by the .talk_comment_count selector. Adding the href="#talk_embed" will allow when you click the comment count, it will jump to the comments! -->
<a href="#talk_embed" class="talk_comment_count">Comments</a>
<script src="{{ TALK_URL }}/static/embed/count.js"></script>

<!-- ... -->

<div id="talk_embed"></div> <!-- The div where the Talk embed will load. -->
<script src="{{ TALK_URL }}/static/embed.js" onload="
  Coral.Talk.render(document.getElementById('talk_embed'), {
    talk: '{{ TALK_URL }}'
  })
"></script>

Which will add the comment count to the page on the selected element! It'll even be translated!

Installing

Currently in beta!

Modify/create your plugins.json file to include the plugin:

{
  "server": [
    // ...
    {"@washingtonpost/talk-plugin-comment-count": "^0.0.6-beta"},
    // ...
  ],
  "client": [
    // ...
  ]
}

Which will enable it. You then need to add the /static/embed/count.js file on your HTML page, which will allow the file to be generated that will add the comment count.

URL Options

The reference to the /static/embed/count.js accepts query parameters which you may combine in any order you choose:

  • id (optional, but highly recommended) - if provided it will lookup the counts for the asset directly, possibly without even hitting MongoDB.
  • url (optional) - if provided, it will lookup the asset referenced by the url and return the count, this should be the same URL that you provide the Talk widget directly.
  • selector (optional, defaults to .talk_comment_count) - if provided, you can specify a selector where all matching elements will have their innerText replaced by the comment count.
  • notext (optional) - when specified, it will not add the Comment(s) text to the element, and will only replace the count. By default, it will include the translated text version of Comment(s).

Note that these parameters are required to be URI encoded, you can utilize the encodeURIComponent method to encode each parameter.

Examples

Get the comment count for a specific Asset by ID:

/static/embed/count.js?id=a-specific-asset-id

Get the comment count for a specific Asset by URL:

/static/embed/count.js?url=https%3A%2F%2Fcoralproject.net%2Fblog%2Fhappy-hacktoberfest%2F

Configuration

You can specify the following environment variables that can customize how the comment count files that are generated are cached:

  • TALK_COMMENT_COUNT_CACHE_DURATION (default 2m) - a string representing the duration of time that a given count will have it's file cached for. Formatted via ms.
  • TALK_COMMENT_DETECT_COUNT_CACHE_DURATION (default 1h) - a string representing the detection script will have it's file cached for. Formatted via ms.

These will be manifested when the /static/embed/count.js file is served with the appropriate query parameters via the Cache-Control header.

Example

TALK_COMMENT_COUNT_CACHE_DURATION=1m
TALK_COMMENT_DETECT_COUNT_CACHE_DURATION=10m

GET /static/embed/count.js?id=123
Cache-Control: public, max-age=60

GET /static/embed/count.js
Cache-Control: public, max-age=600

Loading Strategies

In order to facilitate easy loading, the /static/embed/count.js script will try various strategies to determine which Asset is being referenced.

  1. If the id is specified, then return the count for the asset with that ID.
  2. If the url is specified, then return the count for the asset referenced by that URL.
  3. If the element targeted by the selector contains a data-talk-id= parameter, it will be used in step 1.
  4. If the element targeted by the selector contains a data-talk-url= parameter, it will be used in step 2.
  5. If the page contains a canonical url tag, the URL will be inferred from that, and will be used in step 2.
  6. The URL of the page will be inferred from the current page url, and will be used in step 2.

License

Released under the Apache License, v2.0.

Readme

Keywords

none

Package Sidebar

Install

npm i @washingtonpost/talk-plugin-comment-count

Weekly Downloads

6

Version

0.0.6-beta

License

Apache-2.0

Unpacked Size

171 kB

Total Files

11

Last publish

Collaborators

  • vladimirjv
  • catherine1234
  • mfernanda-sosa
  • dev-javu
  • vviswa
  • netolm-wp
  • yeswapo
  • harmanwapo
  • lpadillac4s
  • rjaya
  • granadoslopez
  • cashack
  • courtneybeesch
  • joshhoegen
  • thiago_srpt
  • alefkow
  • michelle_mark
  • ysmilde
  • shrddhawashpost
  • hanj.washpost
  • karenwang
  • carsonology
  • yuyanlei
  • dbnapp
  • colemanc4
  • vpenney
  • stevethedev
  • dkao
  • elenalacey
  • zhoyoyo
  • dwuandjune
  • fransandi
  • ashendruk
  • michaeldomine
  • mark-a-wapo
  • lenacohen
  • chris93007
  • sabrinamochi
  • jorgemhc-dev
  • carlyn
  • dgreen19
  • josephjames
  • niko_kom
  • nicrocs
  • avalbuena
  • sotojl
  • haileyhaymond
  • lukaskeelwapo
  • timborisenko
  • bantupallik
  • kt-prry
  • jesse.post.washpo
  • threeteaspoons
  • emilycsabens
  • luciovilla
  • tam.steph
  • agillespie
  • ani512
  • vonoehsene
  • emmakumer
  • aggyjlee
  • lavanderoi
  • emily.eng
  • lmelgar
  • sadbumblebee
  • janicekchen
  • jamelhendricks
  • ryanpicou
  • crunchwrap78
  • welchk
  • val-l-hosler
  • nick.mourtoupalas
  • benjaki
  • battand
  • jon.rosado
  • jacknugent27
  • asamireissa
  • courth
  • mahig
  • jchaskell
  • lorenzog
  • ln-washpost
  • stericson
  • talpert022
  • gengel
  • tuckabelle
  • nauticaharvin
  • aadittambe
  • natalievineberg
  • krbrooks
  • katty-huertas
  • mariaalconadabrooks
  • juniorh28
  • atomictangerine
  • emlorraine
  • helmsc
  • tritico
  • pranavganore
  • danacasidy
  • terrywp
  • ksemanur8
  • dreyvitser
  • mvonesh
  • chelseaconrad
  • arnolda-wp
  • hermionewy
  • wp-aberg
  • sheamus-hei
  • haysstephanie
  • broadwaterne
  • andrevinc
  • kat-alo
  • daniellersaul
  • stevefuenteswp
  • rekha26
  • marcnahed
  • amiemunoz
  • chloelangston
  • martinezy
  • seanwapo
  • ducroquet
  • jakekara
  • jtotoole
  • mjperales
  • arturgalocha
  • ebgranger
  • ramyalamati
  • adamsrobw
  • luke.connors
  • wrneff
  • mcdoh
  • floresa
  • taliatrackim
  • lennybronner
  • bitsoglass
  • it_procurement
  • davidchaiwapo
  • maddoxnelson
  • juliebacon
  • stephanie.clark
  • jasonvuong
  • jkoo87
  • kankelcr
  • gregoryauld2014
  • uncompiled
  • jbrown4
  • scarothers
  • khan.salauddin
  • rowhawn
  • subs-npm-builder
  • nealhumphreywapo
  • ashlynstill
  • ptnielsen
  • leslie-s
  • courtney-kan
  • kevin.schaul
  • jakecrump
  • macallah
  • jmuyskens
  • madisonwalls
  • brianaa
  • dsantamarina
  • artmsilva
  • ashtol
  • sberhanu
  • jjalcantara
  • alyssa.fowers
  • joemfox
  • reubenfb
  • calcantara
  • adrianblanco
  • chiquiesteban
  • iuraizee
  • bdgross
  • ulmonica
  • bmferrill
  • dankeating
  • emamd
  • timmeko
  • kevinuhrmacher
  • shellytan
  • harrystevens
  • chrisrukan
  • allisonnmann
  • aaronsteckelberg
  • shruthagandla
  • braforda
  • hannahmahon
  • adityajain15
  • linorabolini
  • anthonyjpesce
  • 1313davidlee
  • kate.rabinowitz
  • fontc
  • cecepascual
  • vsingarayar
  • aramzs
  • ruxk
  • nader_heidari
  • thompsond3
  • tylerremmel
  • tmac0201
  • joemoore-post
  • ealvarez79
  • hdormido
  • sgpotts
  • yutaochen
  • nwalker_wp
  • apbest
  • briannaschroer
  • shikha-sub
  • naema
  • chloemeister
  • julia.ledur
  • solomonsscott
  • betchavarria
  • eewright
  • nickkirkpatrick
  • trann_wapo
  • tobefrankhj
  • tierneyl
  • essiekim
  • sergio.pecanha
  • meganwalter
  • alyssabartuch
  • alexisbarnes
  • dmoriarty6
  • mokhtar.ali
  • dpham5
  • klimenkovd
  • davisshaver
  • aaronbrezel
  • moodypaige.e
  • kastningj