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

fis3-preprocessor-html-inline

v0.1.1

Published

简易html资源动态引入,支持参数替换变量,支持自定义模板渲染引擎

Downloads

5

Readme

介绍

简易html资源动态引入处理,支持引入参数替换变量,支持自定义模板渲染引擎

使用

npm install fis3-preprocessor-html-inline
fis.match('*.html', {
	preprocessor: fis.plugin('html-inline')
})

参数说明

  • compile: null 自定义模板渲染引擎,为null则使用简易变量替换,配合下方参数使用
  • ld: {{ 语法标签(左)
  • rd: }} 语法标签(右)
  • removeEmpty: true 是否删除无数据变量

自定义模板渲染引擎

art-template为例:

const template = require('art-template');
fis.match('*.html', {
	preprocessor: fis.plugin('html-inline', {
		compile(target, tpl, data) {
			const id = target.moduleId
			if(!template.cache[id] || !target.useCache || template.cache[id + '.cache']!= target.cache.timestamp) {
				template.compile(tpl, {
					filename: id
				})
				template.cache[id + '.cache'] = target.useCache ? target.cache.timestamp : +new Date()
			}

			return template(id, data)
		}
	})
})

暂不支持 art-template的include语法

参数数据载入规则

query载入变量

index.html

<link rel="import" href="test.html?__inline&test=123&user[0]=东东&user[1]=丽丽">

test.html

test: {{test}}
user: {{user}}
user0: {{user[0]}}

结果

test: 123
user: 东东,丽丽
user0: 东东

参数支持如下(由loader-utils修改而来):

                             -> Error
?                            -> {}
?flag                        -> { flag: "" }
?+flag                       -> { flag: true }
?-flag                       -> { flag: false }
?xyz=test                    -> { xyz: "test" }
?xyz=1                       -> { xyz: "1" } // numbers are NOT parsed
?flag1&flag2                 -> { flag1: "", flag2: "" }
?+flag1&-flag2               -> { flag1: true, flag2: false }
?flag1=true&flag2=false      -> { flag1: true, flag2: false }
?xyz[]=a                     -> { xyz: ["a"] }
?xyz[]=a&xyz[]=b             -> { xyz: ["a", "b"] }
?xyz[]=a&xyz[]=b&xyz[3]=d    -> { xyz: ["a", "b", , "d"] }
?a%2C%26b=c%2C%26d           -> { "a,&b": "c,&d" }
?{data:{a:1},isJSON5:true}   -> { data: { a: 1 }, isJSON5: true }

__inline载入变量

index.html

<link rel="import" href="user.html?__inline={name: '丽丽', age: 18}">

user.html

<p>你好 {{name}},你今年<em>{{age}}</em>岁咯!加油!</p>

结果

<p>你好 丽丽,你今年<em>18</em>岁咯!加油!</p>

__inline载入json

<link rel="import" href="user.html?__inline=user.json">

user.html

<p>你好 {{name}},你今年<em>{{age}}</em>岁咯!加油!</p>

user.json

{
    "name": "丽丽",
    "age": 18
}

结果

<p>你好 丽丽,你今年<em>18</em>岁咯!加油!</p>

json文件路径查找顺序:当前文件、模板文件

无参数编译

默认无任何参数的情况下,本插件是不介入编译的,但是部分引入的页面不需要变量,而且引入的页面模板上又设置了变量,此时__inline=true就能启动本插件进行编译

<link rel="import" href="user.html?__inline=true">