作者: admin

  • easynode.js博客系统koa2+mongodb

    前沿:在接触node.js一段时间后想使用node.js开发自己一个博客网站,网上搜索过相关基于node.js环境开发的类似wordpress这样优秀的博客系统,但是并没有找到相关程序,最多的是node.js爱好者提供的及简陋的开发测试版本,功能上无法得到需求。于此有种种原因下就开发出属于自己的后台系统,以便提供给刚刚入门的开发者学习。

    easynode.js博客系统,基于node.js环境下开发,使用了koa2框架结合mongodb数据库开发的及简易cms系统。后台ui界面使用AdminLTE设计风格,后台功能布局参考了wordpress。

    程序包:https://pan.baidu.com/s/1eSmx7jk

    环境配置:

    1,操作系统环境centos 6.x    安装node.js v8.1.0    数据库mongodb v3.4.0

    nginx:https://sdeno.com/?p=5731

    node.js:https://sdeno.com/?p=5790

    mongodb:https://sdeno.com/?p=5791

     

    2,解压后进入./data/data.js ,如果端口和数据库名称不变可以忽略此步骤

    3,下载mongodb数据库,数据库名称为xgllseo, 下载地址,将数据库还原.

    数据库还原教程:https://sdeno.com/?p=5397

     

    4,进入已经解压好的根目录下运行node ./bin/run

    5,koa2 笔记 https://sdeno.com/?p=5633

    网站效果:https://www.easynode.cn/

     

  • mac键盘符号+快捷键功能

    Command-Z 撤销 
    Command-X 剪切  
    Command-C 拷贝(Copy)  
    Command-V 粘贴 (粘贴文本也包括了文本样式)
    Command+shift+V 粘贴(粘贴纯文本)
    Command+option+V 将文件剪切走
    Command-A 全选(All)  
    Command-S 保存(Save)  
    Command-F 查找(Find)

     

    截图:

    Command-Shift-4 截取所选屏幕区域到一个文件,自动保存桌面  
    Command-Shift-3 截取全部屏幕到文件,自动保存桌面   
    Command-Shift-Control-3 截取全部屏幕到剪贴板   
    Command-Shift-Control-4 截取所选屏幕区域到剪贴板,或按空格键仅捕捉一个窗

     

    文本处理:

    fn-Delete 逐个删除光标后面的文本
    fn-上箭头 向上滚动一页(Page Up)  
    fn-下箭头 向下滚动一页(Page Down)  
    fn-左箭头 滚动至文稿开头(Home)  
    fn-右箭头 滚动至文稿末尾(End)  
    Command-右箭头 将光标移至当前行的行尾  
    Command-左箭头 将光标移至当前行的行首  
    Command-下箭头 将光标移至文稿末尾  
    Command-上箭头 将光标移至文稿开头  
    Option-右箭头 将光标移至下一个单词的末尾  
    Option-左箭头 将光标移至上一个单词的开头  
    Control-A 移至行或段落的开头

     

    在Finder中:

    Command-Option-V 剪切文件  
    Command-Shift-N 新建文件夹(New)  
    Command-Shift-G 调出窗口,可输入绝对路径直达文件夹(Go)  
    return 这个其实不算快捷键,点击文件,按下可重命名文件  
    Command-O 打开所选项。在Mac里打开文件不像Windows里直接按Enter  
    Command-Option-V 作用相当于Windows里的文件剪切。在其它位置上对文件复制(Command-C),在目的位置按下这个快捷键,文件将被剪切到此位置  
    Command-上箭头 打开包含当前文件夹的文件夹,相当于Windows里的“向上”  
    Command-Delete 将文件移至废纸篓  
    Command-Shift-Delete 清倒废纸篓  
    空格键 快速查看选中的文件,也就是预览功能

     

    在浏览器中:

    Control-Tab 转向下一个标签页  
    Command-L 光标直接跳至地址栏  
    Control-Tab 转向下一个标签页  
    Control-Shift-Tab 转向上一个标签页  
    Command-加号或等号 放大页面  
    Command-减号 缩小页面

     

    http://jingyan.baidu.com/article/08b6a591aac09614a909224f.html

     

  • 解决:Cannot find module ‘../lib/completion’

    一般遇到这种问题,用百度是搜索不到相关答案的,用谷歌我也是从众多零散的回答中找到答案。

    遇到这种情况是我使用gulp的时候遇到,对于我们一开始安装好的所有依赖模块包,不想下次在使用npm install进行安装干脆就连项目和依赖包也一次性打包。

    那么问题来了,一旦我们解压再次运行用类似的以下命令运行时:

    gulp
    或者
    npm run gulp

    就会出现Cannot find module ‘../lib/completion’错误

    其实解决办法很简单要么重新安装npm install,要么修改package.json的内容为以下:

    "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1",
      "gulp": "node ./node_modules/gulp/bin/gulp"
    },

    (修改为红色字体部分)再次使用以下命令

    npm run gulp

    问题即可解决

  • gulp+webpack 3 结合搭建前端自动化工具

    gulp webpack 组合 打包

    在gulp的环境里调用webpack3(当前是3.5.6)这里nodejs环境是v8.1.0;npm是5.0.3,在这里我让webpack主要负责把js统一打包成模块并且es6转es5,兼容ie8浏览器。

    这里来看一下重要的配置文件:

    //package.json
    {
      "name": "gulp_es6",
      "version": "1.0.0",
      "description": "",
      "main": "gulpfile.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "gulp": "gulp"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "devDependencies": {
        "autoprefixer-core": "^6.0.1",
        "babel-core": "^6.26.0",
        "babel-loader": "^7.1.2",
        "babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
        "babel-preset-env": "^2.0.0-beta.1",
        "babel-preset-react": "^6.24.1",
        "css-loader": "^0.28.7",
        "del": "^3.0.0",
        "expose-loader": "^0.7.3",
        "file-loader": "^0.11.2",
        "gulp": "^3.9.1",
        "gulp-babel": "^7.0.0",
        "gulp-base64": "^0.1.3",
        "gulp-cheerio": "^0.6.2",
        "gulp-concat": "^2.6.1",
        "gulp-file-include": "^1.2.0",
        "gulp-htmlmin": "^3.0.0",
        "gulp-if": "^2.0.2",
        "gulp-imagemin": "^3.3.0",
        "gulp-make-css-url-version": "0.0.13",
        "gulp-minify-css": "^1.2.4",
        "gulp-notify": "^3.0.0",
        "gulp-postcss": "^7.0.0",
        "gulp-rename": "^1.2.2",
        "gulp-rev-append": "^0.1.8",
        "gulp-uglify": "^3.0.0",
        "gulp-useref": "^3.1.2",
        "jquery": "^1.11.0",
        "style-loader": "^0.18.2",
        "uglifyjs-webpack-plugin": "^1.0.0-rc.0",
        "vue": "^2.4.4",
        "webpack-stream": "^4.0.0"
      },
      "dependencies": {
        "vinyl-named": "^1.1.0"
      }
    }

    *注意:解压后修改为  “gulp”: “node ./node_modules/gulp/bin/gulp”

     

    //gulpfile.js
    var gulp = require('gulp');
    var cssmin = require('gulp-minify-css'); //压缩,删除注释、换行,合并选择器
    var cssver = require('gulp-make-css-url-version'); //为css的url背景图片添加mdb5,防止缓存
    var concat = require('gulp-concat');//合并css、js
    var uglify = require('gulp-uglify'); //js压缩
    var notify = require('gulp-notify'); //任务执行成功提示
    var htmlmin = require('gulp-htmlmin');//对html页面压缩处理
    var postcss = require('gulp-postcss'); //自动添加css前缀
    var autoprefixer = require('autoprefixer-core');//自动添加css前缀
    var rev = require('gulp-rev-append'); //为html的js、css添加版本号
    var cheerio = require('gulp-cheerio'); //操作html的dom,目的合并多个js或者css链接
    var useref = require('gulp-useref');  //将html中多个link和script各自合并成一个
    var del = require('del');  //删除文件
    var gulpif = require('gulp-if');
    var imageMin = require('gulp-imagemin');  //图片压缩
    var babel = require("gulp-babel");
    var fileinclude  = require('gulp-file-include');
    var base64 = require('gulp-base64');  //将css里面的小图片转化为base64
    var webpack = require('webpack-stream');
    var webpack2 = require('./node_modules/webpack');
    var rename = require("gulp-rename");
    var UglifyJSPlugin = require('uglifyjs-webpack-plugin');
    var named = require('vinyl-named');
    
    gulp.task('fileinclude', function() {
        // 适配page中所有文件夹下的所有html,排除page下的include文件夹中html
        gulp.src(['src/**/*.html'])
            .pipe(fileinclude({
                prefix: '@@',
                basepath: '@file'
            }))
            .pipe(gulp.dest('dist'))
        .on('end', function () {
            gulp.src('src/*.html')
    
                .pipe(useref())
                //.pipe(gulpif('*.js', babel())) //转化es6为es5,但是ie8用不了,ie9可以
                // .pipe(gulpif('*.js', uglify({
                //     mangle:false,//类型:Boolean 默认:true 是否修改变量名
                //     compress:false,//类型:Boolean 默认:true 是否完全压缩
                //     // preserveComments:'all'//保留所有注释
                // })))
                .pipe(gulpif('*.css', cssmin({
                    advanced: false,//类型:Boolean 默认:true [是否开启高级优化(合并选择器等)]
                    compatibility: 'ie7',//保留ie7及以下兼容写法 类型:String 默认:''or'*' [启用兼容模式; 'ie7':IE7兼容模式,'ie8':IE8兼容模式,'*':IE9+兼容模式]
                    keepBreaks: false,//类型:Boolean 默认:false [是否保留换行]
                    keepSpecialComments: '*'//保留所有特殊前缀 当你用autoprefixer生成的浏览器前缀,如果不加这个参数,有可能将会删除你的部分前缀
                })))
                .pipe(gulpif('*.css',postcss([ autoprefixer({ browsers: ["> 0%"] }) ])))
                .pipe(gulpif('*.css',cssver()))
                .pipe( gulpif('*.css',base64({
                    // baseDir: 'public',
                    // extensions: ['svg', 'png', /\.jpg#datauri$/i],
                    // exclude:    [/\.server\.(com|net)\/dynamic\//, '--live.jpg'],
                    maxImageSize: 5*1024 // 小于5KB的图片就会被转化为base64
                    // debug: true
                })))
                .pipe(gulpif('*.html',htmlmin({
                    removeComments: true,//清除HTML注释
                    collapseWhitespace: true,//压缩HTML
                    collapseBooleanAttributes: true,//省略布尔属性的值 <input checked="true"/> ==> <input />
                    removeEmptyAttributes: true,//删除所有空格作属性值 <input id="" /> ==> <input />
                    removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
                    removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
                    minifyJS: true,//压缩页面JS
                    minifyCSS: true//压缩页面CSS
                })))
                .pipe(gulpif('*.html',rev()))
                //.pipe(gulpif('*.html',cheerio(function ($, file) {
                //    $('link').eq(0).remove();
                //    $('head').append('<link rel="stylesheet" href="css/css.min.css?rev='+Math.random()+'">');
                //    $('script').eq(0).remove();
                //    $('head').append('<script src="js/all.min.js?rev='+Math.random()+'"></script>');
                //})))
                .pipe(gulp.dest('dist'))
    
        });
    });
    
    
    
    
    
    
    
    
    //把独立的js复制到dist/js的根目录下
    gulp.task('copy',  function() {
        gulp.src('src/js/*.*')
            .pipe(gulp.dest('dist/js'))
    });
    
    
    
    
    
    //图片压缩
    gulp.task('img', function () {
        gulp.src('src/images/*.*')
            .pipe(imageMin({progressive: true}))
            .pipe(gulp.dest('dist/images'));
    });
    
    
    
    //为此任务命名为watch
    // gulp.task('watch',function(){
    //     gulp.watch('src/**/*.css',['sync']); //在css目录下的所有文件夹的后缀是css的文件,一旦修改就自动执行testCssmin任务
    //     gulp.watch('src/**/*.js',['sync']);
    // });
    
    //监听 src目录下的css 和 js  还有view目录下的html一旦有变化就更新
    gulp.task('watch',function(){
        gulp.watch(['src/**/*.css','src/**/*.js','src/**/*.html'],function () {
                gulp.src(['view/**/*.html'])
                    .pipe(fileinclude({
                        prefix: '@@',
                        basepath: '@file'
                    }))
                    .pipe(gulp.dest('src'))
                    .on('end', function () {
                        gulp.src('src/*.html')
    
                            .pipe(useref())
                            // .pipe(gulpif('*.js', uglify({
                            //     mangle:false,//类型:Boolean 默认:true 是否修改变量名
                            //     compress:false,//类型:Boolean 默认:true 是否完全压缩
                            //     // preserveComments:'all'//保留所有注释
                            // })))
                            .pipe(gulpif('*.css', cssmin({
                                advanced: false,//类型:Boolean 默认:true [是否开启高级优化(合并选择器等)]
                                compatibility: 'ie7',//保留ie7及以下兼容写法 类型:String 默认:''or'*' [启用兼容模式; 'ie7':IE7兼容模式,'ie8':IE8兼容模式,'*':IE9+兼容模式]
                                keepBreaks: false,//类型:Boolean 默认:false [是否保留换行]
                                keepSpecialComments: '*'//保留所有特殊前缀 当你用autoprefixer生成的浏览器前缀,如果不加这个参数,有可能将会删除你的部分前缀
                            })))
                            .pipe(gulpif('*.css',postcss([ autoprefixer({ browsers: ["> 0%"] }) ])))
                            .pipe(gulpif('*.css',cssver()))
                            .pipe( gulpif('*.css',base64({
                                maxImageSize: 5*1024 // 小于5KB的图片就会被转化为base64
                            })))
                            .pipe(gulpif('*.html',htmlmin({
                                removeComments: true,//清除HTML注释
                                collapseWhitespace: true,//压缩HTML
                                collapseBooleanAttributes: true,//省略布尔属性的值 <input checked="true"/> ==> <input />
                                removeEmptyAttributes: true,//删除所有空格作属性值 <input id="" /> ==> <input />
                                removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
                                removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
                                minifyJS: true,//压缩页面JS
                                minifyCSS: true//压缩页面CSS
                            })))
                            .pipe(gulpif('*.html',rev()))
                            .pipe(gulp.dest('dist'))
    
                    });
        });
    });
    
    
    //修改view目录下的html就自动在src根目录下生成html
    // gulp.task('watch_html',function(){
    //     gulp.watch('src/**/*.html',['fileinclude']); //在css目录下的所有文件夹的后缀是css的文件,一旦修改就自动执行testCssmin任务
    // });
    
    
    
    //gulp的默认执行的任务就是watch任务
    //gulp.task('default',['testCssmin','js','html','watch'], function() {
    //    // 将你的默认的任务代码放在这
    //});
    
    
    gulp.task('default',['fileinclude','img','copy','watch'], function() {
       // 将你的默认的任务代码放在这
        return gulp.src(['src/js/a.js','src/js/b.js','src/js/css.js'])
            .pipe(named())  //可以将多个js ['src/js/a.js','src/js/b.js','src/js/css.js'] 分开打包
            .pipe(webpack({
                watch: true,
                module: {
                    loaders: [
                        { test: /\.css$/, loader: 'style-loader!css-loader' },
                        { test: /\.(png|jpg|jpeg|gif|woff)$/, loader: 'file-loader',query: {name: 'images/[name].[ext]'} },
                        {
                            test: /\.js|jsx$/, //是一个正则,代表js或者jsx后缀的文件要使用下面的loader   npm install --save-dev babel-core babel-loader babel-preset-es2015 babel-preset-react
                            exclude: /node_modules/,
                            loader: "babel-loader"
                        },
                    ],
                },
                plugins: [ //扩展webpack额外的功能,要使用webpack自带插件就引入webpack,其他功能的话就额外安装其他插件
                    new webpack2.BannerPlugin('这个插件功能是头部提示功能'),
                    // new UglifyJSPlugin({uglifyOptions:{
                    //     ie8: true
                    // }})
    
                    // new webpack2.ProvidePlugin({  //使用sudo npm install jquery@1.11.0,来调用jq,并将jq暴露打包文件全局中,相当于给window加了jquery
                    //     $:"jquery",
                    //     jQuery:"jquery",
                    //     "window.jQuery":"jquery",
                    //     'window.$': 'jquery'
                    // }),
                ]
            }))
    
           // .pipe(rename("webpack_2.js"))
            .pipe(gulp.dest('dist/js'));  //   ./dist/js/webpack_.js
    });

     

    为了以后方便使用,可以直接下在:下载地址

    百度地址:https://pan.baidu.com/s/1slJoTvZ

    使用步骤:(此包在mac下测试通过)

    1,下载解压后不需要npm install,全部依赖包已经在里面了,

    修改package.json,修改内容为”gulp”: “node ./node_modules/gulp/bin/gulp”,并让整个目录有执行权限chmod -R 777 /xxx/xxx

    2,直接在shell命令里面执行npm run gulp即可

    3,(1)编辑html,切换到目录./src中

    (2)编辑css、js和添加图片,切换到目录./src中

    4,浏览查看未编译的页面就浏览./src里面的html

    浏览已经编译好的页面查看./dist里面的html

    ———————-babel一些坑——————————-

    babel并不能把所有的es6功能都能完美转换为es5;

    babel转化过的js压缩后ie8有问题

     

    下次本人测试可以使用

    //class方法声明 面向对象

    //箭头函数

    //模板

    //默认参数

     

    ————————————————————————————————————–

    gulp负责:
    html压缩、css和js的链接分别合并、css代码压缩

     

    webpack负责(主要处理js):
    将es6转化成es5,js压缩、合并(合并后ie8不兼容)

     

    推荐:
    如果坚持使用es6转es5的功能,就不能压缩否则ie8无法工作,除非不考虑兼容ie8。
    不是有特殊需求放弃使用webpack,js的压缩合并都是用gulp来处理。

     

    需要合并链接,并将多个js打包压缩在一起就把js统一放在./src/js/public/里面,链接最前面最先被加载

    <!-- build:js js/public/public.min.js -->
     <script src="./js/public/jquery.js"></script>
     <script src="./js/public/a.js"></script>
    <!-- endbuild -->

    打包后成为

    <script src="js/public/public.min.js"></script>

     

    需要合并链接,并将多个css打包压缩在一起就把css统一放在./src/css/里面,链接最前面最先被加载,效果跟js一样

     

  • mac在当前窗口打开shell——Go2Shell

    以前使用过ubuntu默认右键都自带一个“打开终端”的操作,当打开shell的时候也会默认切换到当前目录然后在mac没有这功能,这里推荐下载Go2Shell

    设置默认iterm

    而Go2Shell默认没有设置界面,需要用命令行打开(隐藏得真深啊!)
    在Shell中输入:

    open -a Go2Shell --args config

    会打开设置界面

     

     

    配合Finder

    打开Finder,按住command键,拖动Go2Shell的图标到Finder菜单
    就可以在Finder快捷打开Go2Shell了

    http://www.jianshu.com/p/88c6e68645c4