Giter Site home page Giter Site logo

hexo-filter-post-identifier's Introduction

Build Status Coverage Status npm version

NPM

hexo-filter-post-identifier

Hexo plugin for adding a permanent link identifier.

Installation

Install the npm package in the root of your site.

npm install --save hexo-filter-post-identifier

By default the filter builds the identifierr from title and date. You may optionally configure your site to use a different set of properties:

post_identifier_properties:
  - publishedDate
  - slug

Usage

Include in your template

In your template simply access the identifier property of your post.

pug:

!= page.content

p My id is #{post.identifier}

Feed it posts

---
title: Hello World
---
# My Content

See what happens

Output:

<h1>My Content</h1>

<p>My id is 'Ck1VqNd45QIvq3AZd8XYQLvEhtA='</p>

If the identifier property is set in front matter then it will not be overridden. This is handy if a change to a file would generate a new identifier and you want to preserve the previous value, such as migrating the site or fixing a typo in the title.

---
title: Hello World
identifier: post-1
---
# My Content

Output:

<h1>My Content</h1>

<p>My id is 'post-1'</p>

Method of Generation

This plugin looks at the title and date properties--ignoring any that are null--and generates a SHA1 hash of those values then encodes the result as base64. This creates an id that lookes something like 29YRA5pQIXVoU5U8yz+oTxj+gmU=, perfect for Disqus.

You can override the default properties in your site config by setting the post_identifier_properties. This is a list of strings representing the properties on a post to use. As expected, if any of these properties are missing on the post then they are ignored.

Author

Written by Joe Wasson and licensed under the MIT License.

hexo-filter-post-identifier's People

Contributors

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