npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hexo-renderer-etpl

v0.0.2

Published

ETPL renderer plugin for Hexo

Downloads

5

Readme

hexo-renderer-etpl

Hexo开发的etpl渲染插件。(ETPL是一个强复用、灵活、高性能的JavaScript模板引擎。)

安装

使用如下命令进行安装:

$ npm install cxy930123/hexo-renderer-etpl --save

配置

对于文章和页面的渲染,以及主题中模板文件的渲染,此插件用了两个不同的渲染引擎实例。因此,博客使用者和主题开发者可以在不同的位置对插件进行配置。

渲染文章和页面

对于文章和页面的渲染,博客使用者可以在_config.yml文件中配置引擎的参数。

etpl_config:
  variableOpen: <%
  variableClose: %>

想了解更多的配置参数请看这里

注意: _config.yml文件中的这些配置只在渲染文章和页面时生效。

渲染主题文件夹中的文件

对于主题文件夹中文件的渲染,主题开发者可以在主题的脚本文件中进行配置。

let config = {
  variableOpen: '<%',
  variableClose: '%>'
};

let commands = {
  'dump': {
    init: function () {
      var match = this.value.match(/^\s*([a-z0-9_]+)\s*$/i);
      if (!match) {
        throw new Error('Invalid ' + this.type + ' syntax: ' + this.value);
      }

      this.name = match[1];
      this.cloneProps = ['name'];
    },

    open: function (context) {
      context.stack.top().addChild(this);
    },

    getRendererBody: function () {
      var util = etpl.util;
      var options = this.engine.options;
      return util.stringFormat(
        'console.log({0});',
        util.compileVariable(options.variableOpen + this.name + options.variableClose, this.engine)
      );
    }
  }
};

let filters = {
  'fn': (fn, ...args) => typeof fn == "function" ? fn(...args) : fn
};

hexo.theme.config.etpl_renderer = {
  config: config,
  commands: commands,
  filters: filters
};

有三个属性可以用于配置:

  • config - Object类型,配置引擎参数,更多参数请看这里
  • commands - Object类型,用于添加自定义标签。其中键名为命令标签名称,值为命令对象。关于命令的详细信息请看这里
  • filters - Object类型,用于添加过滤器。其中键名为过滤器名称,值为过滤函数。关于过滤器的更多信息请看这里

这三个属性是在hexo.theme.config.etpl_renderer上的。实际上,直接在主题文件夹的_config.yml文件中也可以配置引擎参数。只是由于无法在_config.yml文件中定义函数,因此无法配置其余两项。

注意: 这些主题脚本中的配置只对渲染themes文件夹中的模板有效。

提示

使用辅助函数

你可以向下面这样使用辅助函数。

<!-- var: header = ${partial}('header') -->
${header|raw}