Pencilblue - Webservice获取所有呈现文章的列表

时间:2015-08-06 00:34:39

标签: node.js rendering pencilblue

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

我为此构建了一个控制器:

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
}

1 个答案:

答案 0 :(得分:0)

你需要&#34;渲染&#34;返回之前的媒体,否则你只获得图像ID。查看http://pencilblue.github.io/classes/MediaService.html#method_render(或http://pencilblue.github.io/classes/ImageMediaRenderer.html#method_render获取PB 0.6.0)。