Coder Social home page Coder Social logo

owiesnama / fire-comments-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from theakshaydhiman/fire-comments-js

1.0 0.0 0.0 55 KB

Fire Comments, a commenting system for static websites using Firebase Realtime Database

Home Page: https://theakshaydhiman.github.io/fire-comments/

License: MIT License

JavaScript 100.00%

fire-comments-js's Introduction

Fire Comments JS

Commenting system for static websites using Firebase Realtime Database.

Demo

Fire Comments JS Demo.

Features

Fire Comments JS is a server-less, PHP-less, SQL-less and Disqus-less way to add a commenting system to your static web pages. Some notable features are:

  • The biggest feature is the ability to reply to existing comments.
  • Uses Gravatar to show profile pictures.
  • Counts the number of comments.
  • Converts links to rel="nofollow" and adds target="_blank" rel="noopener" automatically.
  • Prevents harmful XSS code to be rendered.
  • You have full control over your data. Unlike any 3rd-party company such as Disqus.

Getting Started

Use this markup in your .html file:

<div class="comments">

    <!-- Title, with comment count -->
    <h2><span id="comments-count"></span> Comments</h2>

    <!-- Display comments here -->
    <ul id="comments-list"></ul>
  
    <!-- Reference to return comment form after this span, when the reply form is cancelled -->
    <span id="comment-container"></span>

    <!-- Comment form -->
    <form id="comment" style="display:block;">
      <h3 id="comment-form-title">Leave a comment</h3>
      <textarea id="message" type="text" placeholder="Comment (HTML supported)" required></textarea>
      <input id="name" type="text" placeholder="Name" required>
      <input id="email" type="email" placeholder="Email" required>
      <button class="btn" type="submit" name="action">Post Comment</button>
    </form>

    <!-- Reply form -->
    <form id="reply" style="display:none;">
      <h3 id="reply-form-title"></h3>
      <div id="cancel-reply"><a href="#!" class="cancel-reply-link">Cancel Reply</a></div>
      <textarea id="message" type="text" placeholder="Comment (HTML supported)" required></textarea>
      <input id="name" type="text" placeholder="Name" required>
      <input id="email" type="email" placeholder="Email" required>
      <button class="btn" type="submit" name="action">Post Comment</button>
    </form>

</div>

Dependencies

Fire Comments JS has four dependencies. Feel free to use their CDN links if you want.

  1. MD5 converts the email strings to MD5 hash, which is later used to display Gravatar profile pictures.
  2. Comment submission time is stored in Firebase using firebase.database.ServerValue.TIMESTAMP in the Unix format. Timeago converts the Unix format into human readable format.
  3. XSS-Filters is used to prevent harmful XSS attacks. For now, XSS code can be submitted to the database, but will later be filtered when rendered.
  4. Firebase. Of course.

IMPORTANT: Use your own Firebase credentials. Create a new Firebase project if you haven't yet, go to your project overview and click "Add Firebase to your web app." Paste the code here.

<script src="js/md5.js"></script>
<script src="js/timeago.js"></script>
<script src="js/xss-filters.js"></script>
<!-- Paste your Firebase code here !>

Download the fire-comments.min.js from here and include this in the end.

<script src="fire-comments.min.js"></script>

Configure Firebase Realtime Database Rules

Submitting the comments will show a "Permissions denied" error because the default rules of Realtime Databse are restricted to Auth only. For testing purposes only, set the .read and .write rules to true.

{
  "rules": {
    ".read": true,
    ".write": true
  }
}

Once you're done testing, you must change the .write permissions to false and add a $slug rule to allow comment submissions.

{
  "rules": {
    ".read": true,
    ".write": false,
    "$slug": {
          ".write": "!data.exists()",
          "$message": {
            ".write": "!data.exists() && newData.exists()"
          }
        }
  }
}

Testing

Submit some comments and check your Firebase Realtime Database path. It should look something like this [project-name]/comments/[path]/[key]

License

Fire Comments JS is licensed under the MIT license.

fire-comments-js's People

Contributors

theakshaydhiman avatar

Stargazers

owiesnama 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.