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 🙏

© 2026 – Pkg Stats / Ryan Hefner

egg-cms-data

v2.0.12

Published

CMS data plugin for egg

Downloads

19

Readme

egg-cms-data

NPM version build status Test coverage David deps Known Vulnerabilities npm download

获取内容管理平台静态数据

依赖说明

依赖的 egg 版本

egg-cms-data 版本 | egg 2.x --- | --- 2.x | 😁 1.x | 😁

开启插件

// config/plugin.js
exports.cmsData = {
  enable: true,
  package: 'egg-cms-data',
};

使用说明

config

exports.cmsData = {
  siteId: '5c78f07430ed58c413a517a1', // 站点ID
  redisKey: 'cmsData',  // redis cache key
  api: '/cms/api/module/get', // cms platform restful api
  // common modules
  common: [
    {
      id: '5c7cc3428541d9bc0bb8e4b1',
      name: 'header'
    }
  ]
}

获取数据

~~获取普通模块数据~~

以后将废弃,因为 mongodb ObjectID 保持各环境同步太麻烦,所以通过id获取的数据,请使用 getDataByIdentity

const data = await ctx.helper.cmsData.getData(moduleId, ctx)

通过自定义唯一ID获取模块数据

因为 ObjectID 是 mongodb 自增的标识,无法人为控制,一个新的模块从开发到发布,要保持 SIT、UAT、生产 环境的 ObjectID 同步过于麻烦,所以需要一个 自定义的唯一标识 来保证各环境获取的一致性,该 API 就是取代 getData

const data = await ctx.helper.cmsData.getDataByIdentity(identity, ctx)

通过页面ID获取页面数据

const data = await ctx.helper.cmsData.getPageData(pageId, ctx)

// response
{
  moduleName: {
    ...moduleData
  },
  moduleAname: {
    ...moduleAData
  }
}

获取公共模块数据(如全站统一头尾)

// 注意不是异步的
// 公共数据为了避免每个Controller都去读取,所以提供同步方法给模板helper获取
const data = ctx.helper.cmsData.getCommonData("header", ctx)

获取预览数据

添加preview=truesearch,开启预览模式

通过模块Name获取模块数据

该方法主要是开放给获取相同模块的数据列表 (比如公共列表)

const data = ctx.helper.cmsData.getDataByModuleName(moduleName)

// response
[
  {
    _id: moduleId,
    pageId: pageId
  }
]

数据获取规则

  • 应用初始化时,会获取模块和页面数据,缓存到redis (为了避免CMS平台的压力)
  • 生产数据从redis cache获取,预览数据直接读取CMS平台草稿数据
  • CMS 数据发布上线,会更新redis cache

详细配置

请到 config/config.default.js 查看详细配置项说明。

单元测试

提问交流

请到 egg issues 异步交流。

License

MIT