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

hexo-renderer-njcks

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hexo-renderer-njcks

Nunjucks renderer for Hexo with extra utilities like customizing filters, etc.

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

hexo-renderer-njcks

Yet another Nunjucks renderer for Hexo.

Features 🎉

  • Nunjucks 3
  • Predefined filters
  • Full Nunjucks renderer customization via Hexo Filter API

Installation

npm install hexo-renderer-njcks

Configuration

You can customize the Nunjucks renderer via the 2 following ways.

Config files

All configs are passed directly to Nunjucks#configure(), available options can be found here.

The following list shows the descending precedence of config files. (The first one presented is used.)

  • Key nunjucks in <hexo_root>/_config.yml
  • Key theme_config.nunjucks in <hexo_root>/_config.yml
  • Key nunjucks in <hexo_root>/themes/<theme_name>/_config.yml
  • Inline default config

Hexo Filter API

You can extend the before_render:nunjucks filter whose first argument is an Nunjucks Environment object, which is used later to render templates.

Note that the filter should be synchronized.

For example, you can use the following code in your Hexo script to add a new Nunjucks filter named split to split strings into arrays of strings.

hexo.extend.filter.register('before_render:nunjucks', function SplitFilter (env) {
  env.addFilter('split', (str, del) => str.split(del))
})

In the template, use the Nunjucks filter as usual.

{% for i in "1 2 3 4 5"|split(' ') %}#{{ i }}{% endfor %}

Output should be

#1#2#3#4#5

Built-in Filters

typeof

Template

{{ "test" | typeof }}

Output

string

xmlattr

Hexo script

hexo.extend.filter.register('before_render:nunjucks', function GlobalStyleObj (env) {
  env.addGlobal('DEFAULT_STYLE', {
    someAttr: 'a',
    other: 'b'
  })
})

Template

<div {{ DEFAULT_STYLE | xmlattr }}></div>

Output

<div some-attr="a" other="b"></div>

Keywords

FAQs

Package last updated on 11 Feb 2019

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