2013-09-21 42 views
1

如何在使用JavaScript時配置DocPad集合?如何使用JavaScript配置DocPad集合? 「警告:自定義集合XYZ不是有效的集合實例」

網站啓動過程中顯示以下消息:「警告:自定義集合MyCollection的是不是一個有效的集合實例」

配置:

var docpadConfig = { 
    collections: { 
    // The collection causing problems. 
    myCollection: function() { 
     return []; 
    } 
    }, 

    templateData: { 
    site: { 
     url: "http://site-url.com", 
     oldUrls: [], 
     title: "Site title", 
     description: "Site description", 
     keywords: "DocPad", 
     styles: ["/vendor/normalize.css", "/vendor/h5bp.css", "/styles/style.css"], 
     scripts: ["/vendor/log.js", "/vendor/modernizr.js", "/scripts/script.js"] 
    }, 

    getPreparedTitle: function() { 
     if (this.document.title) { 
     return this.document.title + " | " + this.site.title; 
     } else { 
     return this.site.title; 
     } 
    }, 

    getPreparedDescription: function() { 
     return this.document.description || this.site.description; 
    }, 

    getPreparedKeywords: function() { 
     return this.site.keywords.concat(this.document.keywords || []).join(", "); 
    } 
    } 
}; 

module.exports = docpadConfig; 

從看本傑明普頓我的一些YouTube視頻收集DocPad使用Backbone.js - 我應該以某種方式導入Backbone並在配置中使用Backbone.Collection實例嗎?如果是的話,我該怎麼做?我發現了很多Coffee腳本示例,但我似乎無法弄清楚如何將它們應用於純JavaScript。

任何冗長的JavaScript配置的例子將不勝感激,因爲我敢肯定,我會想捏捏配置一些早晚:)

回答

3

得到它的工作使用下列內容:

var docpadConfig = { 
    collections: { 
    journalEntries: function() { 
     var documents = this.getCollection("documents"); 
     var sortByDescendingDate = [{ date: -1 }]; 
     // I've added "type" to the meta section of some documents. 
     var typeEqualsJournal = { type: { $eq: "journal" } }; 
     var journals = documents.findAllLive(typeEqualsJournal, sortByDescendingDate); 
     journals.on("add", function (model) { 
     model.setMetaDefaults({ layout: "journal" }); 
     }); 
     return journals; 
    } 
    }, 

... 
相關問題