分享一个开源博客-Jackblog
发布于 2 个月前 作者 winky 3910 次浏览 最后一次编辑是 6 天前 来自 分享

Jackblog 是使用 Node.js + MongoDB + 其它客户端框架开发的个人博客系统,前后端分离,仿简书模板,自适应布局.

服务端和客户端搭配使用.

服务端有:

express版 https://github.com/jackhutu/jackblog-api-express
koa版 https://github.com/jackhutu/jackblog-api-koa

web客户端有:

angular1.x版:https://github.com/jackhutu/jackblog-angular1 demo地址:angular1.jackhu.top
angular2.x版:https://github.com/jackhutu/jackblog-angular2 demo地址:angular2.jackhu.top
react redux 版: https://github.com/jackhutu/jackblog-react-redux demo地址:redux.jackhu.top
vue 版: https://github.com/jackhutu/jackblog-vue demo地址:vue.jackhu.top

移动端有:

react native 版: https://github.com/jackhutu/jackblog-react-native-redux

希望对新手有帮助,别忘了++star哦.

Snip20160118_4.png Snip20160118_5.png Snip20160108_1.png

100 回复

看起来,好好的

很像简书的布局

完全就是简书的ui 自豪地采用 CNodeJS ionic

@Alex-fun 有参考简书的CSS, 但是不是照抄哦.

大哥 我也正在模仿简书写个博客系统,,这回可以参考你的啦。。。。。。

@ipengyo 这么巧啊, 看来简书蛮多人喜欢的.

你好,文章内容存储是使用mongodb? 包括文章里面的图片和引用的代码都是用mongodb存储的? 最近在学习用node搭建自己的博客;但是不清楚mongo是否适合存储这些;谢谢~

@tongwangyuan 是用mongodb来存储的, 存的是markdown文档, 不管用哪个数据库存储都一样,mongodb作为nosql数据库的优秀代表,当然适合啦.

@winky 你好,前台把markdown数据读出来之后是怎么渲染成html的?我现在用的是handlebars;貌似原理和markdown是不一样的

@winky 如你所说,前后端分离的话,应该是前端进行渲染的

@tongwangyuan 能够将markdown解析成HTML的库有很多,比如markdown-it, 可以在发送到前端之前就解析成HTML,然后在前端渲染.

@winky 好的 ,谢谢了,去学习一下

我来无耻的打广告。。everblog.io

学习! 正在研究nodeBB 看来有可以看看这个了 @winky

@winky 您好,回去看了您的代码;不明白markdown-it是如何把一段String类型的markdown 转成多条html标签的; QQ图片20160120111228.png 如上,我想把“# markdown hirst h1 ! # second h1 sigin” 转换成

markdown hirst h1 !

second h1 sigin

两个标签,但是实际结果是一个标签

markdown hirst h1 ! # second h1 sigin

新手,问题有点多了,烦您不弃,谢谢~

@winky 是因为我看您article里面的 schema content类型是String的,最后接口读出来的时候也是用的md.render(result.content);就想知道这样能把一整段markdown都转换成各个语义化的html标签吗?

@tongwangyuan 是的, 可以將markdown转换成html标签. 至于你刚才的两个h1标签,需要换行才可以.

Android ios 也可以用吗? react native 已经支持了吗?

@wdragon1983 是的, 已经都支持了.

@winky 我在webstorm下面 npm install .下载了好多插件 还有好多错误

“C:\Program Files (x86)\JetBrains\WebStorm 11.0.3\bin\runnerw.exe” D:\nodejs\npm.cmd update npm WARN install Couldn’t install optional dependency: Unsupported npm WARN addRemoteGit Error: Command failed: git -c core.longpaths=true config --get remote.origin.url npm WARN addRemoteGit npm WARN addRemoteGit at ChildProcess.exithandler (child_process.js:213:12) npm WARN addRemoteGit at emitTwo (events.js:87:13) npm WARN addRemoteGit at ChildProcess.emit (events.js:172:7) npm WARN addRemoteGit at maybeClose (internal/child_process.js:818:16) npm WARN addRemoteGit at Socket.<anonymous> (internal/child_process.js:319:11) npm WARN addRemoteGit at emitOne (events.js:77:13) npm WARN addRemoteGit at Socket.emit (events.js:169:7) npm WARN addRemoteGit at Pipe._onclose (net.js:469:12) npm WARN addRemoteGit git+http://ikt.pm2.io/ikt.git#master resetting remote C:\Users\wangbin\AppData\Roaming\npm-cache_git-remotes\git-http-ikt-pm2-io-ikt-git-master-098735ff3c4481296d11bc2fc98a470a because of error: { [Error: Command failed: git -c core.longpaths=true config --get remote.origin.url npm WARN addRemoteGit ] npm WARN addRemoteGit killed: false, npm WARN addRemoteGit code: 1, npm WARN addRemoteGit signal: null, npm WARN addRemoteGit cmd: ‘git -c core.longpaths=true config --get remote.origin.url’ }

[email protected] preinstall E:\nodeworkspace\jackblog\node_modules.staging\ccap-d40a8ced8d860dc734abe5e4cf7091d3 node make.js

I’m glad you to select ccap, enjoy it!

ccap is a cross plat form and portable nodejs simple captcha module, simple api and lightweight.

starting compile ccap! good luck!

[email protected] install E:\nodeworkspace\jackblog\node_modules\ccap node-gyp rebuild

E:\nodeworkspace\jackblog\node_modules\ccap>if not defined npm_config_node_gyp (node “D:\nodejs\node_modules\npm\bin\node-gyp-bin\…\node_modules\node-gyp\bin\node-gyp.js” rebuild ) else (node rebuild ) gyp ERR! configure error gyp ERR! stack Error: Can’t find Python executable “python”, you can set the PYTHON env variable. gyp ERR! stack at failNoPython (D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:116:14) gyp ERR! stack at D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:71:11 gyp ERR! stack at FSReqWrap.oncomplete (fs.js:82:15) gyp ERR! System Windows_NT 6.1.7601 gyp ERR! command “D:\nodejs\node.exe” “D:\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js” "rebuild" gyp ERR! cwd E:\nodeworkspace\jackblog\node_modules\ccap gyp ERR! node -v v5.3.0 gyp ERR! node-gyp -v v3.0.3 gyp ERR! not ok npm WARN EPEERINVALID [email protected] requires a peer of kerberos@~0.0 but none was installed. [email protected] E:\nodeworkspace\jackblog npm WARN EPEERINVALID [email protected] requires a peer of kerberos@~0.0 but none was installed. └── [email protected] npm ERR! Windows_NT 6.1.7601

npm ERR! argv “D:\nodejs\node.exe” “D:\nodejs\node_modules\npm\bin\npm-cli.js” "update" npm ERR! node v5.3.0 npm ERR! npm v3.3.12 npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: node-gyp rebuild npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] install script ‘node-gyp rebuild’. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the ccap package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! node-gyp rebuild npm ERR! You can get their info via: npm ERR! npm owner ls ccap npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request: npm ERR! E:\nodeworkspace\jackblog\npm-debug.log

进程已结束,退出代码1

怎么还有Python?

前面 git的问题 已经解决,

后面gyp的错误 什么情况?一定要安装Python?

@wdragon1983 看样子是没有正确安装ccap模块, 先全局安装 npm i -g node-gyp 然后再 npm i ccap 试试. 你用的node.js哪个版本.

@winky node用的5.3

“C:\Program Files (x86)\JetBrains\WebStorm 11.0.3\bin\runnerw.exe” D:\nodejs\npm.cmd update npm WARN install Couldn’t install optional dependency: Unsupported

[email protected] preinstall E:\nodeworkspace\jackblog\node_modules.staging\ccap-d40a8ced8d860dc734abe5e4cf7091d3 node make.js

I’m glad you to select ccap, enjoy it!

ccap is a cross plat form and portable nodejs simple captcha module, simple api and lightweight.

starting compile ccap! good luck!

[email protected] install E:\nodeworkspace\jackblog\node_modules\ccap node-gyp rebuild

E:\nodeworkspace\jackblog\node_modules\ccap>if not defined npm_config_node_gyp (node “D:\nodejs\node_modules\npm\bin\node-gyp-bin\…\node_modules\node-gyp\bin\node-gyp.js” rebuild ) else (node rebuild ) Building the projects in this solution one at a time. To enable parallel build, please add the “/m” switch. MSBUILD : error MSB3428: δ�ܼ��� Visual C++ �����VCBuild.exe����Ҫ��������⣬1) ��װ .NET Framework 2.0 SDK��2) ��װ Microsoft Visual Studio 2005���� 3) ������������װ��������λ�ã��뽫��λ����ӵ�ϵͳ·���С� [E:\nodeworkspace\jackblog\node_modules\ccap\build\binding.sln] gyp ERR! build error gyp ERR! stack Error: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe failed with exit code: 1 gyp ERR! stack at ChildProcess.onExit (D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:270:23) gyp ERR! stack at emitTwo (events.js:87:13) gyp ERR! stack at ChildProcess.emit (events.js:172:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12) gyp ERR! System Windows_NT 6.1.7601 gyp ERR! command “D:\nodejs\node.exe” “D:\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js” "rebuild" gyp ERR! cwd E:\nodeworkspace\jackblog\node_modules\ccap gyp ERR! node -v v5.3.0 gyp ERR! node-gyp -v v3.0.3 gyp ERR! not ok npm WARN EPEERINVALID [email protected] requires a peer of kerberos@~0.0 but none was installed. npm WARN EPEERINVALID [email protected] requires a peer of kerberos@~0.0 but none was installed. npm ERR! Windows_NT 6.1.7601 npm ERR! argv “D:\nodejs\node.exe” “D:\nodejs\node_modules\npm\bin\npm-cli.js” "update" npm ERR! node v5.3.0 npm ERR! npm v3.3.12 npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: node-gyp rebuild npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] install script ‘node-gyp rebuild’. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the ccap package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! node-gyp rebuild npm ERR! You can get their info via: npm ERR! npm owner ls ccap npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request: npm ERR! E:\nodeworkspace\jackblog\npm-debug.log

进程已结束,退出代码1

感谢大神提供源码,我等新手膜拜参考

@winky 貌似 安装Microsoft Visual Studio Express 2013 for Windows Desktop 了。 运行在端口9000. 然后 你这个程序和 angular1.x版 react redux 版是什么关系 ,运行express版本 ,不能再浏览器直接运行吗?

@wdragon1983 express版本只提供API,做服务端, 而其它的是客户端, 相互配合运行.

@winky Listening on port 8200. Open up http://localhost:8200/ in your browser. Error: ENOENT: no such file or directory, stat 'e:\nodeworkspace\jackblog-angular1\dist\index.html’
怎么运行你的样例呀。我看你的index 放在src 下面了。

@wdragon1983 8200端口的, 要先运行gulp build

@winky "C:\Program Files (x86)\JetBrains\WebStorm 11.0.3\bin\runnerw.exe" D:\nodejs\node.exe C:\Users\wangbin\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js --color --gulpfile e:\nodeworkspace\jackblog-angular1\gulpfile.js build [13:21:46] Using gulpfile e:\nodeworkspace\jackblog-angular1\gulpfile.js [13:21:46] Starting ‘build’… [13:21:46] Starting ‘prod-config’… [13:21:46] Finished ‘prod-config’ after 58 ms [13:21:46] Starting ‘scripts’… [13:21:49] Starting ‘inject_sass’… [13:21:49] Starting ‘partials’… [13:21:51] gulp-inject 6 files into index.scss. stream.js:74 throw er; // Unhandled stream error in pipe. ^

Error: Error: angular is not installed. Try running bower install. at e:\nodeworkspace\jackblog-angular1\node_modules\wiredep\wiredep.js:30:56 at e:\nodeworkspace\jackblog-angular1\node_modules\wiredep\lib\detect-dependencies.js:145:29 at forOwn (e:\nodeworkspace\jackblog-angular1\node_modules\wiredep\node_modules\lodash\dist\lodash.js:2106:15) at Function.forEach (e:\nodeworkspace\jackblog-angular1\node_modules\wiredep\node_modules\lodash\dist\lodash.js:3303:9) at detectDependencies (e:\nodeworkspace\jackblog-angular1\node_modules\wiredep\lib\detect-dependencies.js:34:7) at wiredep (e:\nodeworkspace\jackblog-angular1\node_modules\wiredep\wiredep.js:70:39) at DestroyableTransform._transform (e:\nodeworkspace\jackblog-angular1\node_modules\wiredep\wiredep.js:135:34) at DestroyableTransform.Transform._read (e:\nodeworkspace\jackblog-angular1\node_modules\wiredep\node_modules\readable-stream\lib_stream_transform.js:184:10) at DestroyableTransform.Transform._write (e:\nodeworkspace\jackblog-angular1\node_modules\wiredep\node_modules\readable-stream\lib_stream_transform.js:172:12) at doWrite (e:\nodeworkspace\jackblog-angular1\node_modules\wiredep\node_modules\readable-stream\lib_stream_writable.js:237:10) at writeOrBuffer (e:\nodeworkspace\jackblog-angular1\node_modules\wiredep\node_modules\readable-stream\lib_stream_writable.js:227:5) at DestroyableTransform.Writable.write (e:\nodeworkspace\jackblog-angular1\node_modules\wiredep\node_modules\readable-stream\lib_stream_writable.js:194:11) at Stream.ondata (stream.js:31:26) at emitOne (events.js:77:13) at Stream.emit (events.js:169:7) at queueData (e:\nodeworkspace\jackblog-angular1\node_modules\map-stream\index.js:43:21) at next (e:\nodeworkspace\jackblog-angular1\node_modules\map-stream\index.js:71:7) at e:\nodeworkspace\jackblog-angular1\node_modules\map-stream\index.js:85:7 at e:\nodeworkspace\jackblog-angular1\node_modules\gulp-inject\src\inject\index.js:87:7 at Immediate._onImmediate (e:\nodeworkspace\jackblog-angular1\node_modules\gulp-inject\src\inject\index.js:115:7) at processImmediate [as _immediateCallback] (timers.js:383:17)

@wdragon1983 jackblog-angular1要先运行 bower install,我忘了说明了.已经改了.

[09:45:27] Error in plugin 'gulp-compass’ Message: You need to have Ruby and Compass installed and in your system PATH for this task to work.

不是吧 。还要ruby?node开发一个东东,要 c++  Python ruby ?  

@wdragon1983 需要安装sass和compass 这些都依赖ruby,所以要先安装哦.

[14:11:10] Finished ‘scripts’ after 1.25 s error src/app/index.scss (Line 2: Invalid GBK character “\xE5”)

Compilation failed in 1 files.

[14:11:11] Error in plugin 'gulp-compass’ Message: error src/app/index.scss (Line 2: Invalid GBK character “\xE5”) Compilation failed in 1 files.

这个 错误不断呀

@winky 你这个博客用到的第三方东西太多。依赖的 东西 包括 c++ ruby Python 。。。 还有很多node的依赖库。。。导致我这样的想来看看 node 写web怎么样的,不熟悉node的人 很困难。 没时间去一个个研究这些东西。 希望能提供一个文档说明呀,安装步骤 依赖什么东西。。。 上面的错误怎么解决,怎么还有字符集的错误。。。。

@wdragon1983 这个错误我没有遇到过, 唯一用到的工具就是sass,compass. 其它没什么特别的. 你先确定gulp-compass插件安装好了没, 以及 compass是否能正常编译.

@winky 上个问题解决了 又有新问题了

[17:48:07] Finished ‘scripts’ after 2.42 s unchanged src/assets/images/sort-s0f57be200a.png

write .tmp/serve/app/index.css

write .tmp/serve/app/index.css.map

[17:48:17] Finished ‘styles:compass’ after 12 s [17:48:17] Starting ‘inject’… [17:48:18] gulp-inject 33 files into index.html. [17:48:18] Finished ‘inject’ after 828 ms [17:48:18] Starting ‘html’… [17:48:23] gulp-inject 1 files into index.html. [17:48:46] dist\ styles\app-7295cf39ad.css 139.75 kB [17:48:46] dist\ styles\vendor-4e7c68a81d.css 89.04 kB [17:48:46] dist\ scripts\app-f7f9379358.js 30.11 kB [17:48:46] dist\ scripts\vendor-b92c80fd1b.js 619.31 kB [17:48:46] dist\ index.html 995 B [17:48:46] dist\ all files 879.21 kB [17:48:46] Finished ‘html’ after 28 s [17:48:46] Starting ‘fonts’… [17:48:46] Starting ‘images’…

events.js:141 throw er; // Unhandled ‘error’ event ^ Error: spawn e:\nodeworkspace\jackblog-angular1\node_modules\optipng-bin\vendor\optipng.exe ENOENT at exports._errnoException (util.js:855:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32) at onErrorNT (internal/child_process.js:344:16) at nextTickCallbackWith2Args (node.js:455:9) at process._tickCallback (node.js:369:17)

进程已结束,退出代码1

要不要这么全,大赞!

@wdragon1983 哦,少了一个png图片生成库, 安装方法:gem install oily_png 我在github上已经更新了安装方法. 谢谢你的提醒.

@winky 搞了这么多天还是不行,看来只有放弃了。这oily_png 玩意 还不是一般的安装,还要装什么devkit,装了之后还是报错。。。楼主你这个开发一个东西,用的东西太多。不是我这种 尝鲜用户能玩的了。 装了 c++ python ruby…一堆环境 还是不行。。。

@winky 使用bootstrap那个markdown编辑器只能添加图片地址;如果添加本地图片的话是需要在markdown编辑器外面在上传本地图片;上传成功后返回图片url,最后在markdown编辑器里面写入图片链接?

@wdragon1983 windows 系统确实有些坑. 不过oily_png装不上可以在sass文件中去掉几行你码就可以了,没什么影响.

@tongwangyuan 你说的没错, 要想给那个markdown编辑器增加上传本地图片功能, 还要对那个编辑器改改代码才行,我也偷了个懒, 没时间去弄. 你有好的编辑器推荐吗?

@winky 嗯,暂时还没有,嘿嘿~~,看你把图片传到七牛了,周末在研究七牛用法

终于在Windows环境把你的Blog给部署起来了。 部署jackblog-api-es5服务器端代码会出现如下错误: ‘node-gyp rebuild’的问题,跟楼上同学遇到的问题一样,我把user.controller.js中把此处代码注释掉 //var ccap = require(‘ccap’)();同样也需要删除package.jason中ccap引用。 部署jackblog-angular1也遇到如下错误: error src/app/index.scss (Line 26 of src/app/!base.scss: Invalid GBK character “\xE5”) 需修改%rubygems%gems\sass-3.4.9\lib\sass目录下的修改 engine.rb 文件 在require 最下面 加入以下代码 即可解决 Encoding.default_external = Encoding.find(‘utf-8’) 由于后代把ccap功能注释掉,前台还需要对应的把验证码功能给注释掉。代码省略不表。 Anyway,楼主的代码写得非常清晰,很值得学习!

@HelloJasonZhang 辛苦了, 我没在windows上试过,没想到有这些问题.

@winky 使用jQuery.fileupload.js上传图片,后台显示req.files为undfined; body-parse和connect-multiparty都引入了,不知道啥原因

@winky 搞定了~~ 上传七牛的时候返回 401;bad token;356E.tmp.jpg

@tongwangyuan req.files为undfined,应该是multer版本问题. 看看版本号是否一致. 七牛的config文件配置都改好了吗.

@winky 嗯 搞定了,还想请教一个问题哈,是不使用 passport-qq和passport-weibo就不需要再前端配置访问授权地址了?而是直接跳转自己的路由;我看了passport-qq的API然后又去看腾讯开放平台的author授权机制,看混了。。。;谢谢哈

@tongwangyuan 前端不用再配置,直接跳转路由, 都在后端处理.

@winky jsonwebtoken 那个secret有要求吗? 普通的字符串可以不?用jsonwebtoken生成的token然后用express-jwt去解码;老是报invalid token错误;但是对比发出的token和获取到的token是一模一样的

@winky 搞定了~~ 太粗心导致的

弱弱的问一句,怎么进后台

谁知道怎么进入后台?

怎么写博文?

@winky 老大,问您几个问题,数据库的配置在哪个地方?

@shimaomao 数据库配置在服务端config文件. 我之前做的第一版 jackblog-express-angular是集成了后台管理的, 可以参考一下. 后来在做其它版本的客户端时, 我就没有做后台管理的功能了.我自己也是用的第一版来管理后台的. 以后我会将后台单独提出来放到jackblog-admin中.

@winky 我已经部署了,没看仔细代码呢,哈哈,多谢您

楼主,有QQ么,加我 2585441871 加个交流群吧。 这个项目好大,要一点一点吃过去,谢谢楼主好作品

@shimaomao 帮我部署一下,我搞了express版本,出来的台湾是我们的领土。。

[06:46:18] Starting ‘serve’… [06:46:18] [webpack-dev-server] ==> � http://localhost:5000 events.js:141 throw er; // Unhandled ‘error’ event ^

Error: write EPIPE at exports._errnoException (util.js:874:11) at Socket._writeGeneric (net.js:675:26) at Socket._write (net.js:694:8) at doWrite (_stream_writable.js:292:12) at writeOrBuffer (_stream_writable.js:278:5) at Socket.Writable.write (_stream_writable.js:207:11) at Socket.write (net.js:618:40) at Socket.Writable.end (_stream_writable.js:433:10) at Socket.end (net.js:400:31) at Through2._transform (D:\nodejs\jackblog-react-redux-master\node_modules\i mage-webpack-loader\node_modules\imagemin-pngquant\index.js:92:12) at Through2.Transform._read (D:\nodejs\jackblog-react-redux-master\node_modu les\image-webpack-loader\node_modules\imagemin-pngquant\node_modules\through2\no de_modules\readable-stream\lib_stream_transform.js:172:10) at Through2.Transform._write (D:\nodejs\jackblog-react-redux-master\node_mod ules\image-webpack-loader\node_modules\imagemin-pngquant\node_modules\through2\n ode_modules\readable-stream\lib_stream_transform.js:160:12) at doWrite (D:\nodejs\jackblog-react-redux-master\node_modules\image-webpack -loader\node_modules\imagemin-pngquant\node_modules\through2\node_modules\readab le-stream\lib_stream_writable.js:335:12) at writeOrBuffer (D:\nodejs\jackblog-react-redux-master\node_modules\image-w ebpack-loader\node_modules\imagemin-pngquant\node_modules\through2\node_modules
readable-stream\lib_stream_writable.js:321:5) at Through2.Writable.write (D:\nodejs\jackblog-react-redux-master\node_modul es\image-webpack-loader\node_modules\imagemin-pngquant\node_modules\through2\nod e_modules\readable-stream\lib_stream_writable.js:248:11) at Through2.ondata (D:\nodejs\jackblog-react-redux-master\node_modules\image -webpack-loader\node_modules\imagemin\node_modules\readable-stream\lib_stream_r eadable.js:583:20)

瞎搞一下终于可以了。

不容易啊,不容易,楼主一定要加我QQ啊。

@chengnuo 搞定了吗?qq我加了.

坚持搞这么多版本,厉害!

@wangchi 哈, 坚持学习才能涨姿势.

@chengnuo 我下了个koa版本的 也出来“台湾是中国不可分割的一部分”, 你是怎么解决的?

@prebra server端只提供API, 需要配合客户端运行的. 你还需要下一个其它的客户端版本才能跑起来, 前后分离的.

@prebra 忘记了,把用户名,还是什么文件删除就可以了,数据库的账号密码原因好像。

@winky 跑起来了 非常感谢分享,接下来好好看代码

为什么每次wiredep注入bower_components中的文件总是少了ngprogress.js  导致 Module ‘ngProgress’ is not available! 求大家解答下啊 @winky

@gaoyangxiaozhu bower.json里面有没有ngProgress?

有呢 而且在bower_components里面也生成了ngprogress文件夹 但就是 每次wriedep不会导入ngprogress.js到index.html ngprogress.js在bower_components/ngprogress/build/里面 前辈知道什么原因嘛  gulp文件我没改动过呢 @winky

对了bower.json里面是"ngprogress": “~1.1.1”

@gaoyangxiaozhu 它主要是有两个判断条件,一个是bower.json文件里面有, 再一个就是ngprogress的package.json里面的mian项有js入口文件 . 你看一下是不是第二个条件不满足.

前辈 最近在看你的博客源码其中在user.model.js文件中的这句UserSchema.set(‘toObject’, { virtuals: true });是用做什么的呀 @winky

@gaoyangxiaozhu 这是mongoose在调用toObject方法时返回虚拟字段, 可以看看mongoose文档 .

恩恩 谢谢前辈啊 其他问题还能请教不啊? @winky 嘿嘿

在blog.controller.js中不是有一段链式查询获取博客列表的函数嘛

Blog.find(condition)
		.select('title content images visit_count comment_count like_count publish_time')
		.skip(startRow)
		.limit(itemsPerPage)
		.sort(sort)
		.exec().then(function(list){
		//函数体
		list.forEach(function(item){
			//增加一些新的操作 比如delete item.images
			delete item.images; //返回true了
			console.log(item.images); //仍旧输出images内容
			item.abstract = 'hah'; //增加abstract属性
			console.log(item); //不显示abstract属性
			
		})
		console.log(list);
		//list中元素没有改变
		
		}

如上,我在promise执行成功的函数内部对获取的list进行forEach操作,对每一个item进行一定的更改,删除一些属性(或增加一些属性),但是不论怎样的操作,最终显示的list的每一个对象元素还是没有更改。 从昨天纠结到今天了 ,不知道怎么回事。我在其他地方测试(比如文件读取成功的promise回调中执行响应操作)就可以额 @winky

难道是查询出来的数据不能直接进行操作?

好像是要通过toObject方法转为js Object, 但是ref部分怎么处理呢 比如Article document中的author_id指向User , 那么怎么获取实际的author的nickname怎么获取呢,我将代码改为

Blog.find(condition)
		.populate('author_id')
		.select('author_id title content images visit_count comment_count like_count publish_time')
		.skip(startRow)
		.limit(itemsPerPage)
		.sort(sort)
		.exec().then(function(list){
		//函数体
		list.forEach(function(item){
		item = item.toObject(); //转换为toObject;
			//增加一些新的操作 比如delete item.images
			item.author_id; //输出author相关信息
			item.author_id.nickname; //出错, 访问不了
			)}

将article转换为plain Object, 但是还是无法通过item.author_id.nickename获取author的name

不知道我说清楚没呢@winky

前端用什么写的 好漂亮 @winky

@gaoyangxiaozhu 针对数组,你可以采用Promise.map方法来处理, 这是bluebird的一个方法, 在我的博客中也有使用.

@Herrengit 谢谢, css部分是用的sass+compass

我准备学node.js跟你一样写一个博客,请指导 谢谢 @winky

@Herrengit 好啊, 先学习基础知识, 慢慢来.

回到顶部