项目须要研究了下DoraCMS这款开源CMS,真心作的不错:)。用的框架是经常使用的express 4 + mongoose,代码也很规范,值得学习。html
源码中一些涉及到的小知识点备注下:node
https://github.com/doramart/DoraCMSgit
一、Robots协议 github
1)当搜索引擎访问到网站目录时,会判断当前是否存在Robots.txt;
2)若存在则按照该文件的要求来限制访问;
3)规则:
User-agent: * 这里的*表明的全部的搜索引擎种类
Disallow: /ABC/ 这里定义是禁止爬寻ABC目录下面的目录
Disallow: /.jpg$ 禁止抓取网页全部的.jpg格式的图片
Disallow:/ab/adc.html 禁止爬取ab文件夹下面的adc.html文件
Sitemap: 网站地图 告诉爬虫这个页面是网站地图redis
二、CMS的实现数据库
1)利用ueditor及node下插件express
var ueditor = require('ueditor-nodejs'); app.use('/ueditor/ue', ueditor({//这里的/ueditor/ue是由于文件件重命名为了ueditor,若是没更名,那么应该是/ueditor版本号/ue configFile: '/ueditor/jsp/config.json',//若是下载的是jsp的,就填写/ueditor/jsp/config.json mode: 'local', //本地存储填写local accessKey: '',//本地存储不填写,bcs填写 secrectKey: '',//本地存储不填写,bcs填写 staticPath: path.join(__dirname, 'public'), //通常固定的写法,静态资源的目录,若是是bcs,能够不填 dynamicPath: '/upload/blogpicture' }));
2)ueditor 将编辑的信息以html格式传入后台并存储在数据库中,上述配置中的dynamicPath实现本地上传的图片,即保存一个本地的路径;json
三、利用res.locals 存储一些全局变量,模板中能够直接使用缓存
res.locals.logined = req.session.logined;
res.locals.userInfo = req.session.user;
四、站点地图session
1)、一般是sitemap.xml 存储整个网站的结构, 可方便网站管理员通知搜索引擎他们网站上有哪些可供抓取的网页;
2)、在DoraCMS中,sitemap.xml并非本地存储的文件,而是在用户访问时经过读取数据库生成,但利用redis缓存,缓存时间为1天;
即当天的文档不更新至缓存;
五、利用validator扩展实现校验
validator.extend('isEn', function (str) { return /^\S+[a-z A-Z]$/.test(str); });
六、使用Redis缓存
getContentsCount : function(req,res,cateParentId,cateQuery,callBack){ cache.get(settings.session_secret + '_' + cateParentId + '_contentCount',function(contentCount){ if(contentCount) { callBack(contentCount); }else{ Content.count(cateQuery,function(err,count){ if(err){ res.end(err); }else{ cache.set(settings.session_secret + '_' + cateParentId + '_contentCount', count, 1000 * 60 * 60 * 24); // 缓存一天 callBack(count) } }) } }); }