Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hexo-related-popular-posts

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hexo-related-popular-posts

A hexo plugin that generates a list of links to related posts and popular posts.

  • 0.1.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

A hexo plugin that generates a list of links to related posts or popular posts.

Overview

  • Generate related list of posts (tag relevancy & contents relevancy)
  • Generate popular list of posts

A hexo plugin that generates a list of links to related posts based on tags , and plugin that generates a list of links to popular posts base on page view of Google Analytics. Popular posts is need Google Analytics API. Also , this plugin can generates a list of links to related posts based on contents.

DEMO & Documents

  • DEMO : My Posts has generated related posts like this.
  • Documents : read me (Japanese)

Installation

$ npm install hexo-related-popular-posts --save

Usage

1. Edit your theme

First, add the following helper tag in template file for article. Please edit themes/(your-theme)/layout/_partial/your_template.ejs.

  <%-
    popular_posts()
  %>

2. Run server

Starts a local server. By default, this is at http://localhost:4000/.

$ hexo server

A related article is displayed .

3. Customize more settings

This plugin can set the following options. Please see below for the details.

Options of hepler

popular_posts() helper can set the following options.

optiondescriptiondefault
maxCountMaximum count of a list5
ulClassClass name of element'popular-posts'
PPMixingRateMixing ratio of popular posts and related posts0.0(=Related posts only)
isDatevisible the datefalse
isImagevisible the imagefalse
isExcerptvisible the excerptfalse

Helper's Option Examples

  1. Related Articles will generate 5 posts. Also, Image of Articles generate .
  <%-
    popular_posts_json({ maxCount: 5 , ulClass: 'popular-posts' , PPMixingRate: 0.0 , isImage: true})
  %>
  1. Popular Articles will generate 10 posts . Popular posts is need Google Analytics API.
  <%-
    popular_posts_json({ maxCount: 10 , ulClass: 'popular-posts' , PPMixingRate: 1.0 })
  %>

Customize HTML

If you want customize html , please use popular_posts_json() helper and make 'htmlGenerator' register . Please edit themes/(your-theme)/scripts/your_scripts.js.

First , please edit themes/(your-theme)/layout/_partial/your_template.ejs .

<%-
    htmlGenerator( 
        popular_posts_json({ maxCount: 5 , ulClass: 'popular-posts' , PPMixingRate: 0.0 , isDate: true , isImage: true , isExcerpt: true})
    )
%>

Second , please edit themes/(your-theme)/scripts/your_scripts.js

// Examples of helper
hexo.extend.helper.register('htmlGenerator', function(args){
  if(!args || !args.json || args.json.length == 0)return "";
  
  var returnHTML = "";
  
  function generateHTML(list){
    
    var ret = "";
    ret += "<li class=\"" + args.class + "-item\">";
    
    if(list.date && list.date != ""){
        ret += '<div class="'+args.class+'-date">' + list.date + "</div>";
    }
    
    if(list.img && list.img != ""){
        ret += '<div class="'+args.class+'-img">' + '<img src="'+list.img+'" />' + "</div>";
    }
    ret += '<div class="'+args.class+'-title"><h3><a href="' + list.path + '" title="'+ list.title +'" rel="bookmark">'+ list.title + "</a></h3></div>";
    if(list.excerpt &&  list.excerpt != ""){
        ret += '<div class="'+args.class+'-excerpt"><p>' + list.excerpt + "</p></div>";
    }
    
    ret +=  "</li>";
    return ret;
  }
  
  for(var i=0; i<args.json.length; i++){
      returnHTML += generateHTML(args.json[i]);
  }
  
  if(returnHTML != "")returnHTML = "<ul class=\"" + args.class + "\">" + returnHTML + "</ul>";
  
  return returnHTML;
});

Popular posts base on page view of Google Analytics. Popular posts is need Google Analytics API. Please edit your config file _config.yml and set the following options.

Please see https://www.npmjs.com/package/ga-analytics

popularPosts:
  googleAnalyticsAPI:
    clientId: ******.apps.googleusercontent.com
    serviceEmail: *****@developer.gserviceaccount.com
    key: /hexo-project-root/path/to/google-services.pem
    viewId: 12345678
    dateRange: 60
    expiresDate: 10 # (optional) Expiration date of cache file. Default = 30
    # # This options is Deprecated > v0.1.3
    # cache:
    #  path: hexo-related-popular-posts-ga-cached.json
    #  expiresDate: 10

If you want to use the environment variable. Please set the following.

$ export GOOGLEAPI_CLIENTID="******.apps.googleusercontent.com"
$ export GOOGLEAPI_EMAIL="*****@developer.gserviceaccount.com"
$ export GOOGLEAPI_KEY="/path/to/google-services.pem"
$ export GOOGLEAPI_ANALYTICS_TABLE="ga:12345678"
popularPosts:
  googleAnalyticsAPI:
    # clientId: ******.apps.googleusercontent.com
    # serviceEmail: *****@developer.gserviceaccount.com
    # key: /hexo-project-root/path/to/google-services.pem
    # viewId: 12345678
    dateRange: 60
    expiresDate: 10

This plugin that can generates a list of links to related posts based on content's keywords.

Support language is as follow. Please cooperate with support of other languages.

  • ja
  • en

If you want to generates a list of links to related posts based on contents , please set the morphologicalAnalysis option.

popularPosts:
  morphologicalAnalysis: 

More detailed options can be set as follows.

popularPosts:
  morphologicalAnalysis: 
    negativeKeywordsList: hexo-rpp-negativewords.txt  # (optional) If you want to exclude the keywords for analytics , set the exclude file..
    limit: 300              # (optional) If you want to limit the number of keywords for analytics , set the number.
  weight:                   # (optional)
    tagRelevancy: 1.0       # (optional) Weight of tag relevancy. Default = 1.0
    contentsRelevancy: 1.0  # (optional) Weight of contents relevancy. Default = 1.0

For example, hexo-rpp-negativewords.txt can describe a regular expression as follows. Please enter the keywors of each data separated by newlines.

^.$
^[0-9]+$
^If you want to exclude the keywords$

Cache

This option improves the generation speed.

popularPosts:
  cache:
    path: hexo-popular-related-posts-ga-cached.json

License

MIT

Keywords

FAQs

Package last updated on 11 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc