0

我在服务器上运行撇号博客,在 lib/modules/apostrophe-blog-pages/views 文件夹下我有两个模板 index.html 和 show.html。我添加了一个新的模板popular.html。希望我尝试为第三个模板执行此操作,我想将值限制为 10 篇博客文章或文章。在所有其他情况下在哪里显示所有文章。我能够将代码追溯到第 42 行的撇号页面文件,如果没有传递任何值,则默认值为 10。 https://github.com/punkave/apostrophe/blob/master/lib/modules/apostrophe -pieces-pages/index.js

现在取决于页面,我想将该值从 10 更改为 100 或返回 10。我在 ./lib/modules/apostrophe-blog-pages/index.js 下的代码是

module.exports = {
    construct: function (self, options) {
        self.pageBeforeSend = function (req, callback) {
            function setPerPageValue() {
                return new Promise(function (resolve, reject) {
                    if(req.originalUrl.indexOf("popular") !== -1) {
                        self.options.perPage = 10;
                    } else {
                        self.options.perPage = 100;
                    }
                    console.log("after",self.options.perPage);
                    resolve(req);
                });
            }

            Promise.all([setPerPageValue()]).then(function (results) {
                // All promises were resolved
                return callback(null);
            })
            .catch(function (error) {
                // One or more promises was rejected
                return callback(error);
            });
        };
    },
}

但价值始终保持不变。由于某种原因,一旦设置传递的值没有改变?任何帮助将不胜感激。

4

0 回答 0