minbaowang / SSeffects

some small effects in my code's history
1 stars 0 forks source link

keystone.js简单教程(持续学习中) #8

Open minbaowang opened 5 years ago

minbaowang commented 5 years ago

1.安装

1、请注意:安装之前需要Node.js和MongoDB,最好的安装方式是借助yeoman的generator,运行命令:


$ npm install -g yeoman
$ npm install -g generator-keystone

$ mkdir myproject

$ cd myproject

$ yo keystone

在回答所有generator问题以后,运行下面命令:

node keystone (或 npm start)

现在你可登录管理界面: http://localhost:3000/keystone 能够快速创建一篇帖子,,就会在/blog路由目录下发表,它是高度可配置的。管理也方便。

#2.增强定制

>1、缺省的bootstrap模板是非常简单的,推荐使用一些基于bootstrap的高阶模板,可使用 jade, handlebars 等其他模板引擎,这些在前面产生应用时是可选的。

>2、Keystone.js默认是不会为每个页面定制<title> 和 <meta description>的,但是这对于搜索引擎抓取以及SEO等却非常重要。

>3、在Post模型中增加两个字段:name和description
```js
Post.add({
    title: { type: String, required: true },
    state: { type: Types.Select, options: 'draft, published, archived', default: 'draft', index: true },
    author: { type: Types.Relationship, ref: 'User', index: true },
    publishedDate: { type: Types.Date, index: true, dependsOn: { state: 'published' } },
    image: { type: Types.CloudinaryImage },
    //新增加meta
    meta:{
        name:{type:String},
        description:{type:String}
    },
    content: {
        brief: { type: Types.Html, wysiwyg: true, height: 150 },
        extended: { type: Types.Html, wysiwyg: true, height: 400 },
    },
    categories: { type: Types.Relationship, ref: 'PostCategory', many: true },
});