🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more
Socket
Book a DemoInstallSign in
Socket

pigfarm.js

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pigfarm.js

配置化页面输出

latest
npmnpm
Version
1.2.1
Version published
Maintainers
2
Created
Source

配置化页面输出

对于大部分渲染页面的需求,可以归结为以下模型:

  • 根据url参数向后台请求有关的数据
  • 将数据丢到模版引擎上得到html

pigfarm.js就是完成这种职责的的一个模块

var pigfarm = require('pigfarm.js');

var app = pigfarm({
    render: function(data) {
        console.log(data.index); // 腾讯视频首页内容;
        return `eat ${data.title.food}`
    },
    data: {
        title: {
            type: "static",
            value: {
                "food": "cabbage"
            }
        },
        index: {
            type: "request",
            action: {
                url: "http://v.qq.com",
                fixAfter: function (data) {
                    return data;
                }
            }
        }
    }
});

console.log(await app()) // 输出 'eat cabbage'

其中,type=request的数据源,action内的配置即pigfarm-fetcher的配置方式。这让你可以获取任意的数据。

事件

app.on('fetchstart', function(koacontext) {

})
  • fetchstart
  • fetchend
  • renderstart
  • renderend

修改完之后记得npm run test

FAQs

Package last updated on 01 Jul 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