使用bat脚本部署hexo到coding和github

因项目的不同适当的改造吧,本文以hexo为例。

拉取coding.net的代码和github的代码到本地

  1. 确保代码能够正常的运行,commit,push
  2. 在项目的目录外新建一个push.bat文件

快速预览

如何一步到位提交到仓库

脚本中的变量说明

  • artsPath 新增文章的目录
  • codingPath coding的目录
  • githubPath github的目录

复制文章然后自动执行命令进行部署

修改脚本中对应的路径后执行push

1
2
3
4
5
6
7
8
xcopy F:\CodingRepos\ymhexo\arts F:\CodingRepos\ymhexo\yimocoding\source\_posts /Y
cd F:\CodingRepos\ymhexo\yimocoding
call git pull
call hexo clean
call hexo d -g
call git add *
call git commit -m AddArticle
call git push

windows下使用bat脚本部署hexo到coding和github

拉取coding.net的代码和github的代码到本地

确保代码能够正常的运行,commit,push
新建一个push.bat文件
然后copy下面的代码再改改路径,将文章放到arts目录后运行push即可

  • artsPath 新增文章的目录
  • codingPath coding的目录
  • githubPath github的目录

如何一步到位提交到仓库

复制文章然后自动执行命令进行部署

修改脚本中对应的路径后执行push

1
2
3
4
5
6
7
8
xcopy F:\CodingRepos\ymhexo\arts F:\CodingRepos\ymhexo\yimocoding\source\_posts /Y
cd F:\CodingRepos\ymhexo\yimocoding
call git pull
call hexo clean
call hexo d -g
call git add *
call git commit -m AddArticle
call git push

js实用方法记录-指不定哪天就会用到的js方法

js实用方法记录-指不定哪天就会用到的js方法

常用或者不常用都有

判断是否在微信浏览器中

测试代码:isWeiXin()==false

1
2
3
4
5
6
7
8
9
10
11
/**
* 是否在微信中
*/
function isWeixin() {
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
return true;
} else {
return false;
}
}
js

js实用方法记录-简单cookie操作

js实用方法记录-简单cookie操作

设置cookie:setCookie(名称,值,保存时间,保存域);
获取cookie:setCookie(名称);
移除cookie:setCookie(名称,值,-1,保存域);

设置cookie

测试代码:setCookie('test','hello') //保存session级的cookie到根域
测试代码:setCookie('test','hello',30,false) //保存30天且保存到当前全域名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* 设置cookie
* @param {string} name cookie名称
* @param {string} value cookie值
* @param {number}[expiredays=null] 过期时间 默认session级别 <=0移除cookie
* @param {bool}[saveRoot=true] 保存的域 默认根域
*/
function setCookie(name, value, expiredays=null,saveRoot=false) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays)
var cookie = name + "=" + value + ';path=/' + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
if(saveRoot){
//适用于一级,二级,本地域名
var domain =((location.host.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/g) || location.hostname=='localhost')? location.hostname:('.' + (location.host.split('.')[2]!=undefined?(location.host.split('.')[1]+'.'+location.host.split('.')[2]):location.host)));
cookie+=(';domain='+domain);
}
document.cookie = cookie;
}
js

js实用方法记录-动态加载css、js

js实用方法记录-动态加载css、js

附送一个加载iframe,h5打开app代码

1. 动态加载js文件到head标签并执行回调

方法调用:dynamicLoadJs('http://www.yimo.link/static/js/main.min.js',function(){alert('加载成功')});

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
* 动态加载JS
* @param {string} url 脚本地址
* @param {function} callback 回调函数
*/
function dynamicLoadJs(url, callback) {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
if(typeof(callback)=='function'){
script.onload = script.onreadystatechange = function () {
if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete"){
callback();
script.onload = script.onreadystatechange = null;
}
};
}
head.appendChild(script);
}
js