node.js - Pencilblue - 用于获取所有呈现文章的列表的 Web 服务

标签 node.js rendering pencilblue

我想知道是否有一种方法可以获取所有已呈现的文章 HTML 的列表。我希望媒体图像文件呈现为 <img>而不是 ^media_display_55aabd2ac89b5e44211ccf86/position:none^.

我为此构建了一个 Controller :

module.exports = function BookApiControllerModule(pb) {

  //PB dependencies
  var util = pb.util;
  var BaseApiController = pb.BaseApiController;
  var PluginService = pb.PluginService;
  var BaseObjectService = pb.BaseObjectService;
  var BookService = PluginService.getService('BookService', 'articles-api');
  var ArticleService = pb.ArticleService;
  var TYPE = 'article';

  //Creating an inline service.
  function DndService(context) {
    if (!util.isObject(context)) {
      context = {};
    }
    context.type = TYPE;
    DndService.super_.call(this, context);
  }

  util.inherits(DndService, BaseObjectService);

  DndService.getName = function () {
    return "DndService";
  };

  DndService.init = function (cb) {
    pb.log.debug("DndService: Initialized");
    cb(null, true);
  };

  DndService.beforeSave = function (context, cb) {
    cb(null);
  };

  DndService.afterSave = function (context, cb) {
    cb(null);
  };

  DndService.beforeDelete = function (context, cb) {
    cb(null);
  };

  DndService.afterDelete = function (context, cb) {
    cb(null);
  };

  DndService.validate = function (context, cb) {
    cb(null);
  };

  DndService.merge = function (context, cb) {
    cb(null);
  };

  DndService.format = function (context, cb) {
    cb(null);
  };

  DndService.getAll = function (ctx, cb) {
    ctx.data = [{message: "ASDF"}];
    cb(null);
  };

  BaseObjectService.on(TYPE + '.' + BaseObjectService.GET_ALL, DndService.getAll);
  //Done with the inline service

  function BookApiController() {
    this.service = new DndService();
  };
  util.inherits(BookApiController, pb.BaseApiController);

  BookApiController.getRoutes = function (cb) {
    var routes = [
      {
        method: 'get',
        path: "/api/articles",
        handler: "getAll",
        content_type: 'application/json'
      }
    ];
    cb(null, routes);
  };

  //exports
  return BookApiController;
};

它返回以下内容:

{
    "data": [
        {
            "_id": "55c2a7650668d47274859fc8",
            "author": "55aaa75a3bb0fbbd2056c76d",
            "publish_date": "2015-08-05T22:45:00.000Z",
            "meta_keywords": [
                ""
            ],
            "article_media": [
                "55aabd2ac89b5e44211ccf86",
                "55c2a86d0668d47274859fd1"
            ],
            "article_sections": [],
            "article_topics": [],
            "headline": "wefghj",
            "subheading": "khgvhjvgjvgh",
            "url": "blahhhhh",
            "draft": 0,
            "article_layout": "^media_display_55aabd2ac89b5e44211ccf86/position:none^^media_display_55c2a86d0668d47274859fd1/position:none^",
            "object_type": "article",
            "created": "2015-08-06T00:16:37.889Z",
            "last_modified": "2015-08-06T00:22:46.825Z",
            "id": "55c2a7650668d47274859fc8",
            "template": "pencilblue|index"
        }
    ],
    "total": 1,
    "count": 1,
    "offset": 0,
    "limit": 1000
}

最佳答案

您需要在返回媒体之前“渲染”媒体,否则您只能获得图像 ID。看看http://pencilblue.github.io/classes/MediaService.html#method_render (或 PB 0.6.0 的 http://pencilblue.github.io/classes/ImageMediaRenderer.html#method_render)。

关于node.js - Pencilblue - 用于获取所有呈现文章的列表的 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31844976/

相关文章:

javascript - 在 Underscore 模板中获取 Backbone 集合的前 3 项

javascript - 从 http 重定向到 https (Pencilblue Elastic Beanstalk)

node.js - PencilBlue - 自定义对象 ID

node.js - 带有标志 --legacy-watch 的 Nodemon 不适用于 docker Ubuntu/Linux

node.js - 如何最好地通过 meteor 来 'tail -f' mongo 中的大型集合?

java - 有纹理的三角形,仅渲染一种颜色

javascript - 如何使用discord.js 创建具有权限的discord 类别?

javascript - jQuery.ajax#get 之后出现意外的 token 冒号 JSON

google-chrome - PC 版 Chrome 中的 @font-face 渲染问题