load categories from settings

This commit is contained in:
Sacha Greif 2016-02-21 14:33:02 +09:00
parent 931b2e90c6
commit 89e8bd66fd
3 changed files with 32 additions and 3 deletions

View file

@ -108,7 +108,7 @@ The current default “theme” is `base-components`.
- ~~Comment threads~~
- ~~Flesh out the `base-components` theme with components for the most common elements.~~
- Add simple stylesheet to make base theme a little less ugly.
- ~~Add simple stylesheet to make base theme a little less ugly.~~
- Make base theme class names compatible with Vanilla Telescope?
#### Forms & Methods
@ -121,6 +121,7 @@ The current default “theme” is `base-components`.
#### Other Stuff
- ~~Create categories from code.~~
- Newsletter.
- Email & notifications (keep Spacebars for templates?).
- Refactor scheduled posts to use cron job (do in `master`?)
@ -128,7 +129,6 @@ The current default “theme” is `base-components`.
- Autoform.
- Votes.
- Nested categories.
- Create categories from code.
- Embedly.
- Search.
- Meta tags.

View file

@ -0,0 +1,28 @@
// Load categories from settings, if there are any
Meteor.startup(()=>{
let count = 0;
if (Meteor.settings && Meteor.settings.categories) {
Meteor.settings.categories.forEach(category => {
// look for existing category with same slug
const existingCategory = Categories.findOne({slug: category.slug});
if (existingCategory) {
// if category exists, update it with settings data
Categories.update(existingCategory._id, {$set: category});
} else {
// if not, create it
Categories.insert(category);
count ++;
}
});
}
if (count) {
console.log(`// Created ${count} new categories`);
}
});

View file

@ -27,7 +27,8 @@ Package.onUse(function (api) {
], ['client', 'server']);
api.addFiles([
'lib/server/publications.js'
'lib/server/publications.js',
'lib/server/load_categories.js'
], ['server']);
// var languages = ["ar", "bg", "cs", "da", "de", "el", "en", "es", "et", "fr", "hu", "id", "it", "ja", "kk", "ko", "nl", "pl", "pt-BR", "ro", "ru", "sl", "sv", "th", "tr", "vi", "zh-CN"];