diff --git a/_config.yml b/_config.yml index 439cca80566..efb1fb10ad5 100644 --- a/_config.yml +++ b/_config.yml @@ -6,24 +6,24 @@ # 'jekyll serve'. If you change this file, please restart the server process. # Site settings -title: 徐代龙的技术专栏 -brief-intro: Android and Python Coder +title: 空被的柳 +brief-intro: 打算写点什么,代码或小说~~ baseurl: "" # the subpath of your site, e.g. /blog -url: "https://643435675.github.io" # the base hostname & protocol for your site +url: "https://wangwenying.github.io" # the base hostname & protocol for your site permalink: /:year/:month/:day/:title/ # other links -twitter_username: #gaohaoyang126 -facebook_username: #gaohaoyang.water -github_username: 643435675 -email: 643435675@QQ.com -weibo_username: 3115521wh -zhihu_username: hll643435675 -linkedIn_username: gaohaoyang +twitter_username: #t_andrewnow +facebook_username: # +github_username: wangwenying +email: andrewnow@QQ.com +weibo_username: wangwenying +zhihu_username: +linkedIn_username: dribbble_username: -description_footer: 来自徐代龙的个人专栏! +description_footer: “不过人不是为失败而生的,”他说,“一个人可以被毁灭,但不能被打败。” # comments # two ways to comment, only choose one, and use your own short name @@ -58,4 +58,5 @@ excerpt_separator: "\n\n\n\n" # paginate plugins: [jekyll-paginate] paginate: 6 -port: 4001 \ No newline at end of file +port: 4001 +theme: jekyll-theme-slate diff --git a/_posts/2015-02-10-welcome-to-jekyll.markdown b/_posts/2015-02-10-welcome-to-jekyll.markdown deleted file mode 100644 index 783692c48d3..00000000000 --- a/_posts/2015-02-10-welcome-to-jekyll.markdown +++ /dev/null @@ -1,38 +0,0 @@ ---- -layout: post -title: "hello jekyll!" -date: 2015-02-10 15:14:54 -categories: jekyll -tags: jekyll -excerpt: 当年创建 jekyll 时默认的一篇文章,没什么意义,我也一直没删除,留个纪念吧。 -mathjax: true ---- - -You’ll find this post in your `_posts` directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run `jekyll serve`, which launches a web server and auto-regenerates your site when a file is updated. - -To add new posts, simply add a file in the `_posts` directory that follows the convention `YYYY-MM-DD-name-of-post.ext` and includes the necessary front matter. Take a look at the source for this post to get an idea about how it works. - -Jekyll also offers powerful support for code snippets: - -```ruby -def print_hi(name) - puts "Hi, #{name}" -end -print_hi('Tom') -#=> prints 'Hi, Tom' to STDOUT. -``` - -Check out the [Jekyll docs][jekyll] for more info on how to get the most out of Jekyll. File all bugs/feature requests at [Jekyll’s GitHub repo][jekyll-gh]. If you have questions, you can ask them on [Jekyll’s dedicated Help repository][jekyll-help]. - -[jekyll]: http://jekyllrb.com -[jekyll-gh]: https://github.com/jekyll/jekyll -[jekyll-help]: https://github.com/jekyll/jekyll-help - -Block Mathjax - -$$ -f(x) = ax + b -$$ - -Inline Mathjax $a \neq b$ - diff --git a/_posts/2015-02-12-create-my-blog-with-jekyll.md b/_posts/2015-02-12-create-my-blog-with-jekyll.md deleted file mode 100644 index ef555311f89..00000000000 --- a/_posts/2015-02-12-create-my-blog-with-jekyll.md +++ /dev/null @@ -1,156 +0,0 @@ ---- -layout: post -title: "Jekyll 搭建静态博客" -date: 2015-02-15 22:14:54 -categories: jekyll -tags: jekyll RubyGems ---- - -* content -{:toc} - -一直以来都想搭建一个自己的博客,但是近半年做项目太忙,再加上教研室的网络很坑爹,所以也一直没顾得上。之前用过 WordPress 托管在免费的京东云擎上,但是速度太慢。在知乎上看到一些相关的内容,于是选择了在github上用jekyll搭建博客。 - - - - - -## 搭建过程 - -在jekyll的官网上 [http://jekyllrb.com/](http://jekyllrb.com/) 其实已经说得比较明白了,我在这里还是简单的说一下吧。我用的是Windows系统。 -主要环节有:安装Ruby,安装RubyGems,安装jekyll,安装代码高亮插件,安装node.js - -### 安装Ruby - -ruby官网下载安装:[https://www.ruby-lang.org/en/downloads/](https://www.ruby-lang.org/en/downloads/) - -安装完成后配置环境变量 - -在命令提示符中,得到ruby版本号,如下图,即安装成功 - -![](http://ww4.sinaimg.cn/large/7011d6cfjw1f2ue0e393vj20cu00t748.jpg) - -### 安装RubyGems - -官网下载 [http://rubygems.org/pages/download](http://rubygems.org/pages/download) rubygems-2.4.5.zip - -cd到RubyGems目录 - -![](http://ww1.sinaimg.cn/large/7011d6cfjw1f2ue1l2yscj20gk02amxj.jpg) - -执行安装 - -![](http://ww1.sinaimg.cn/large/7011d6cfjw1f2ue1w8eqnj20bx00hglg.jpg) - -### 用RubyGems安装Jekyll - -执行下面的语句安装 - -![](http://ww4.sinaimg.cn/large/7011d6cfjw1f2ue2g2p3uj207x00ft8j.jpg) - -安装结束画面 - -![](http://ww4.sinaimg.cn/large/7011d6cfjw1f2ue32drwhj20hv09xq5m.jpg) - -至此jekyll就已经安装完毕了,后续就是个性化的自己设定了。 - -### 创建博客 - -在d盘新建一个工作区jekyllWorkspace - -cd到jekyllWorkspace - -执行jekyll new name创建新的工作区 - -![](http://ww3.sinaimg.cn/large/7011d6cfjw1f2ue3lt31nj20cj02nt8u.jpg) - -文件结构如下: - -![](http://ww1.sinaimg.cn/large/7011d6cfjw1f2ue3ujsybj20ek06wabh.jpg) - -cd到博客文件夹,开启服务器 - -![](http://ww1.sinaimg.cn/large/7011d6cfjw1f2ue47y9lgj20ao00f0sl.jpg) - -watch为了检测文件夹内的变化,即修改后不需要重新启动jekyll - -我的环境下启动报错(你的可能没有),再安装yajl-ruby和rouge - -![](http://ww4.sinaimg.cn/large/7011d6cfjw1f2ue4nelnxj20dd077q49.jpg) - -再次启动服务器成功 - -![](http://ww4.sinaimg.cn/large/7011d6cfjw1f2ue4v42koj20g505bdgy.jpg) - -访问 http://localhost:4000/ - -![](http://ww1.sinaimg.cn/large/7011d6cfjw1f2ue56ckwoj20je0eumz3.jpg) - -详细文章页面 - -![](http://ww2.sinaimg.cn/large/7011d6cfjw1f2ue5f3j9cj20je0gyq7a.jpg) - -## 后续 - -* 整个安装过程参考了jekyll官网,注意jekyll还有一个简体中文官网,不过比较坑(我就被坑了),有些内容没有翻译过来,有可能会走弯路,建议如果想看中文的相关资料,也要中英对照着阅读。[jekyll中文网 http://jekyllcn.com](http://jekyllcn.com), [jekyll英文网 http://jekyllrb.com](http://jekyllrb.com) -* jekyll中的css是用sass写的,当然直接在`_sass/_layout.scss`中添加css也是可以的。 -* 本文是用Markdown格式来写的,相关语法可参考: [Markdown 语法说明 (简体中文版) http://wowubuntu.com/markdown/](http://wowubuntu.com/markdown/) -* 按照本文的说明搭建完博客后,用`github Pages`托管就可以看到了。注意,在github上面好像不支持rouge,所以要push到github上时,我将配置文件_config.yml中的代码高亮改变为`highlighter: pygments`就可以了 -* 博客默认是没有评论系统的,本文的评论系统使用了多说,详细安装办法可访问[多说官网 http://duoshuo.com/](http://duoshuo.com/),当然也可以使用[搜狐畅言 http://changyan.sohu.com/](http://changyan.sohu.com/)作为评论系统。 -* 也可以绑定自己的域名,如果没有域名,可以在[godaddy http://www.godaddy.com/](http://www.godaddy.com/)上将域名放入购物车等待降价,买之。 -* 祝各位新年快乐! - ---- - -## 可能出现的问题 - -### `hitimes/hitimes (LoadError)` - -**错误代码:** - -``` -C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- hitimes/hitimes (LoadError) -``` - -**解决方法:** - -在stackoverflow上又一个很好的解决方法。[hitimes require error when running jekyll serve on windows 8.1](http://stackoverflow.com/questions/28985481/hitimes-require-error-when-running-jekyll-serve-on-windows-8-1) 虽然上面的题主问的是 win 8.1 系统下的情况,但是同样适用于 win7。下面我简单翻译一下错误原因和解决方法。 - -> 可能是 Ruby 2.2 和 hitimes-1.2.2-x86-mingw32 中有一些 ABI 变化,少了一些相关的类库。 -> -> 所以卸载 hitimes 并通过 `--platform ruby` 重装即可。代码如下: - -``` -gem uni hitimes -**Remove ALL versions** -gem ins hitimes -v 1.2.1 --platform ruby -``` - -> 然后将自动重新编译 hitimes 并适用于 Ruby 2.2 - -下面是我自己的卸载和安装过程: - -``` -E:\GitWorkSpace\gaohaoyang.github.io>gem uni hitimes - -You have requested to uninstall the gem: - hitimes-1.2.2-x86-mingw32 - -timers-4.0.1 depends on hitimes (>= 0) -If you remove this gem, these dependencies will not be met. -Continue with Uninstall? [yN] y -Successfully uninstalled hitimes-1.2.2-x86-mingw32 - -E:\GitWorkSpace\gaohaoyang.github.io>gem ins hitimes -v 1.2.1 --platform ruby -Fetching: hitimes-1.2.1.gem (100%) -Temporarily enhancing PATH to include DevKit... -Building native extensions. This could take a while... -Successfully installed hitimes-1.2.1 -Parsing documentation for hitimes-1.2.1 -Installing ri documentation for hitimes-1.2.1 -Done installing documentation for hitimes after 1 seconds -1 gem installed -``` - - -关于,[hitimes](https://rubygems.org/gems/hitimes/versions/1.2.2) 是一个快速的高效的定时器解决方案库,详情可以去官网查看。 diff --git a/_posts/2015-03-21-teach-girlfriend-html-css.md b/_posts/2015-03-21-teach-girlfriend-html-css.md deleted file mode 100644 index 662eeb6c8a4..00000000000 --- a/_posts/2015-03-21-teach-girlfriend-html-css.md +++ /dev/null @@ -1,39 +0,0 @@ ---- -layout: post -title: "Teach Girlfriend to make a Web Pages like Zhihu" -date: 2015-03-21 15:14:54 -categories: Bootstrap -tags: BootStrap HTML CSS Zhihu ---- - -* content -{:toc} - -My girlfriend is learning html and css recently. I told her to follow the video. Here, I recommend a video in Chinese that suite for fresh learners. The name of course is Getting HTML web pages dev in 8 hours ( 8小时学会HTML网页开发 ) . I watched this video at very first time. The teacher named Eighteen Swallows ( 燕十八 ) . He teached very clear even himself being on screen to show what is float or box-model. - - - - - - -Here is the site of the free online video. -[http://study.163.com/course/courseMain.htm?courseId=432008](http://study.163.com/course/courseMain.htm?courseId=432008) - -I did the detailed note about this course. You can read here: [http://wenku.baidu.com/view/aa136099f90f76c660371a35](http://wenku.baidu.com/view/aa136099f90f76c660371a35) - -Now I'll tell something happend today. She has watched the video above, and knows a little on BootStrap. So she wants to do some pages with BootStrap. - -We determined to copy the pages on [Zhihu](http://zhihu.com) -Like this: -![知乎zhihu](http://7q5cdt.com1.z0.glb.clouddn.com/teach-girlfriend-html-zhihu.jpg) - -I teached her [Boostrap](http://www.bootcss.com/) this afternoon. She has already got to read the docs and can code simple statics pages. - -She seems to enjoy Web Pages Design. Though she used to be a Graphic Designer. And now, she really works hard. - -At last I'll show the works that we did together in 2 hours. It's unfinished. I guess she will do it later. It's a nice weekend, isn't it? - -[to see Copy Zhihu, click here](http://gaohaoyang.github.io/test/bootstrap-zhihu/) - -screenshot of copy Zhihu: -![Copy Zhihu](http://7q5cdt.com1.z0.glb.clouddn.com/teach-girlfriend-html-CopyZhihu.jpg) diff --git a/_posts/2015-03-26-sublimeLinter.md b/_posts/2015-03-26-sublimeLinter.md deleted file mode 100644 index 64f46d818d2..00000000000 --- a/_posts/2015-03-26-sublimeLinter.md +++ /dev/null @@ -1,208 +0,0 @@ ---- -layout: post -title: "代码校验工具 SublimeLinter 的安装与使用" -date: 2015-03-26 15:14:54 -categories: Sublime -tags: Sublime jshint csslint ---- - -* content -{:toc} - -本文我将讲述一下 SublimeLinter 的安装过程。其组件 jshint 的安装与使用。其组件 csslint 的安装与使用。我将基于 [Sublime Text 3](http://sublimetext.com/3) 来安装。使用 Sublime Text 2 的用户阅读本文是没有帮助的。 - -SublimeLinter 是 Sublime 的插件,它的作用是检查代码语法是否有错误,并提示。习惯了 IDE 下写代码的人一定需要一款在 Sublime 上类似的语法检查工具。下面我们开始。 - - - - - -## 安装 SublimeLinter - -如同其他插件一样使用 Package Control 来安装。 - -1. 按下 `Ctrl+Shift+p` 进入 Command Palette -2. 输入`install`进入 Package Control: Install Package -3. 输入`SublimeLinter`。进行安装. - -![SublimeLinter](http://7q5cdt.com1.z0.glb.clouddn.com/SublimeLinter-sublimeLinter.jpg) - -安装完成后可以看到这样一段话: - -``` -Welcome to SublimeLinter, a linter framework for Sublime Text 3. - - * * * IMPORTANT! * * * - - SublimeLinter 3 is NOT a drop-in replacement for - earlier versions. - - Linters *NOT* included with SublimeLinter 3, - they must be installed separately. - - The settings are different. - - * * * READ THE DOCS! * * * - - Otherwise you will never know how to install linters, nor will - you know about all of the great new features in SublimeLinter 3. - - For complete documentation on how to install and use SublimeLinter, - please see: - - http://www.sublimelinter.com -``` - -可以看到具体的 Linters 组件**不**被包含在 SublimeLinter 3 中,所以我们要额外独立安装组件。 -可以针对不同的语言安装不同的组件。 - -## JavaScript 语法检查 - -SublimeLinter-jshint 是基于 nodeJS 下的 jshint 的插件,实际上 SublimeLinter-jshint 调用了 nodeJS 中 jshint 的接口来进行语法检查的。 - ---- - -### 安装 SublimeLinter-jshint - -为了让 JavaScript 代码有语法检查,我们安装 SublimeLinter-jshint -同样的方法,我们安装 SublimeLinter-jshint - -1. 按下 `Ctrl+Shift+p` 进入 Command Palette -2. 输入`install`进入 Package Control: Install Package -3. 输入`SublimeLinter-jshint`。进行安装. - -如下图 - -![SublimeLinter-jshint](http://7q5cdt.com1.z0.glb.clouddn.com/SublimeLinter-jshint.jpg) - -安装完成后我们可以看到下面的一段话 - -``` -SublimeLinter-jshint - ------------------------------- - This linter plugin for SublimeLinter provides an interface to jshint. - - ** IMPORTANT! ** - - Before this plugin will activate, you *must* - follow the installation instructions here: - - https://github.com/SublimeLinter/SublimeLinter-jshint -``` - -### 安装 nodeJS 和 jshint - -在插件开始工作之前,我们必须再看一下上述插件的[安装说明](https://github.com/SublimeLinter/SublimeLinter-jshint) -通过 [SublimeLinter-jshint 的说明](https://github.com/SublimeLinter/SublimeLinter-jshint) 我们可以看到,这个组件依赖于 nodeJS 下的 jshint,所以我们安装 nodeJS 环境和 nodeJS 下的 jshint。 - -1. 安装 [Node.js](https://nodejs.org/) -2. 通过 npm 安装`jshint` - -在命令行下输入如下代码,完成安装 - - npm install -g jshint - -安装完成后命令行中出现如下的信息 - -``` -C:\Users\Administrator\AppData\Roaming\npm\jshint -> C:\Users\Administrator\AppData\Roaming\npm\node_modules\jshint\bin\jshint -jshint@2.6.3 C:\Users\Administrator\AppData\Roaming\npm\node_modules\jshint -├── strip-json-comments@1.0.2 -├── underscore@1.6.0 -├── exit@0.1.2 -├── shelljs@0.3.0 -├── console-browserify@1.1.0 (date-now@0.1.4) -├── htmlparser2@3.8.2 (domelementtype@1.3.0, entities@1.0.0, domhandler@2.3.0, readable-stream@1.1.13, domutils@1.5.1) -├── minimatch@1.0.0 (sigmund@1.0.0, lru-cache@2.5.0) -└── cli@0.6.6 (glob@3.2.11) -``` - -可以查看 jshint 版本,已确认安装完成。 - -``` -C:\Users\Administrator>jshint -v -jshint v2.6.3 -``` - -现在,恭喜你,我们使用 Sublime 编辑 JavaScript 文件,就会有语法检查了! - -在编辑过程中,会有如下提示 - -![SublimeLinter-jshint-test](http://7q5cdt.com1.z0.glb.clouddn.com/SublimeLinter-jshint-test.jpg) - -点击提示点后,Sublime 状态栏也会有相应的说明 - -![SublimeLinter-jshint-test2](http://7q5cdt.com1.z0.glb.clouddn.com/SublimeLinter-jshint-test2.jpg) - -## css 语法检查 - -与 jshint 同理,SublimeLinter-csslint 也是基于 nodeJS 下的 csslint 的插件,实际上 SublimeLinter-csslint 调用了 nodeJS 中 csslint 的接口来进行语法检查的。 - ---- - -### 安装 SublimeLinter-csslint - -同样的方法。 - -1. 按下 `Ctrl+Shift+p` 进入 Command Palette -2. 输入`install`进入 Package Control: Install Package -3. 输入`SublimeLinter-csslint`。进行安装. - -如下图 - -![SublimeLinter-csslint](http://7q5cdt.com1.z0.glb.clouddn.com/SublimeLinter-csslint.jpg) - -安装完成后我们可以看到下面的一段话 - -``` -SublimeLinter-csslint -------------------------------- -This linter plugin for SublimeLinter provides an interface to csslint. - -** IMPORTANT! ** - -Before this plugin will activate, you *must* -follow the installation instructions here: - -https://github.com/SublimeLinter/SublimeLinter-csslint -``` - -在使用插件之前,必须遵循上述网址中的[安装说明](https://github.com/SublimeLinter/SublimeLinter-csslint) - -### 在 nodeJS 下安装 csslint - -进入上述的 GitHub 地址,csslint 的说明页。我们知道了和 jshint 一样,csslint 也是基于 nodeJS 下的 csslint 来使用的。 - -这里安装 nodeJS 过程省略。 -只需用 npm 安装 csslint 即可。 - -在命令行中输入 - -``` -npm install -g csslint -``` - -安装完成后命令行中出现如下的信息 - -``` -C:\Users\Administrator\AppData\Roaming\npm\csslint -> C:\Users\Administrator\AppData\Roaming\npm\node_modules\csslint\cli.js -csslint@0.10.0 C:\Users\Administrator\AppData\Roaming\npm\node_modules\csslint -└── parserlib@0.2.5 -``` - -可以查看 csslint 版本,已确认安装完成。 - -``` -C:\Users\Administrator>csslint --version -v0.10.0 -``` - -现在,恭喜你,我们使用 Sublime 编辑 css 文件,就会有语法检查了! - -在编辑过程中,会有如下提示 - -![SublimeLinter-csslint-test](http://7q5cdt.com1.z0.glb.clouddn.com/SublimeLinter-csslint-test.jpg) - -点击提示点后,Sublime 状态栏也会有相应的说明 - -![SublimeLinter-csslint-test2](http://7q5cdt.com1.z0.glb.clouddn.com/SublimeLinter-csslint-test2.jpg) diff --git a/_posts/2015-04-06-arrays-similar.md b/_posts/2015-04-06-arrays-similar.md deleted file mode 100644 index dd1757199f5..00000000000 --- a/_posts/2015-04-06-arrays-similar.md +++ /dev/null @@ -1,287 +0,0 @@ ---- -layout: post -title: "判断两个数组是否相似 (arraysSimilar)" -date: 2015-04-06 15:14:54 -categories: JavaScript -tags: JavaScript Array 算法 慕课网 ---- - -* content -{:toc} - -## 题目 - -题目来自 [慕课网 JavaScript 深入浅出 1-6 编程练习](http://imooc.com/code/5760) - -请在 index.html 文件中,编写 arraysSimilar 函数,实现判断传入的两个数组是否相似。具体需求: - -1. 数组中的成员类型相同,顺序可以不同。例如 [1, true] 与 [false, 2] 是相似的。 -2. 数组的长度一致。 -3. 类型的判断范围,需要区分: String, Boolean, Number, undefined, null, 函数, 日期, window. - - - - - -当以上全部满足,则返回**"判定结果:通过"**,否则返回**"判定结果:不通过"**。 - -题目给出了 index.html 如下: - -```html - - - - - Untitled Document - - - - - - - -``` - -其中 testData.js 是测试用例,代码如下 - -```js -var result = function() { - //以下为多组测试数据 - var cases = [{ - arr1: [1, true, null], - arr2: [null, false, 100], - expect: true - }, { - arr1: [ - function() {}, - 100 - ], - arr2: [100, {}], - expect: false - }, { - arr1: [null, 999], - arr2: [{}, - 444 - ], - expect: false - }, { - arr1: [window, 1, true, new Date(), "hahaha", (function() {}), undefined], - arr2: [undefined, (function() {}), "okokok", new Date(), false, 2, window], - expect: true - }, { - arr1: [new Date()], - arr2: [{}], - expect: false - }, { - arr1: [window], - arr2: [{}], - expect: false - }, { - arr1: [undefined, 1], - arr2: [null, 2], - expect: false - }, { - arr1: [new Object, new Object, new Object], - arr2: [{}, {}, - null - ], - expect: false - }, { - arr1: null, - arr2: null, - expect: false - }, { - arr1: [], - arr2: undefined, - expect: false - }, { - arr1: "abc", - arr2: "cba", - expect: false - }]; - - //使用for循环, 通过arraysSimilar函数验证以上数据是否相似,如相似显示“通过”,否则"不通过",所以大家要完成arraysSimilar函数,具体要求,详见任务要求。 - for (var i = 0; i < cases.length; i++) { - if (arraysSimilar(cases[i].arr1, cases[i].arr2) !== cases[i].expect) { - document.write("不通过!case" + (i + 1) + "不正确!arr1=" + JSON.stringify(cases[i].arr1) + ", arr2=" + JSON.stringify(cases[i].arr2) + " 的判断结果不是" + cases[i].expect); - return false; - } - } - return true; - -}(); -document.write("判定结果:" + (result ? "通过" : "不通过")); -``` - ---- - -## 解答 - -各位读者在看解答前也可以自己考虑一下,看看咱们的想法是否一致,期待您在本文的留言。 - ---- - -### 思路 - -通过观察测试用例,可以发现,最后三个用例有不是数组的。所以我们可以先判断传入的参数是否是数组。 -又因为题目中要求数组长度必须一致,这也是第二个限制条件。 -最后再区分具体的类型。 - -理清思路我们可以分为以下步骤: - -1. 判断传入的参数是否为数组 (使用 `instanceof` 方法) -2. 检查两个数组长度是否一致 -3. 分别判断数组内元素的基本数据类型 (使用 `typeof` 方法) -4. 因为 `typeof` 只能检查基本数据类型,对于 `null`, `Date`, `window` 返回的都是 `object`,所以使用 `Object.prototype.toString.apply()` 来检查这些对象类型,其返回值为:`'[object Null]'`, `'[object Date]'`, `'[object global]'` -5. 分别比较每个数组内元素的各种类型的个数,如果都相等,那么这两个数组是相似的。 - -### 具体实现代码 - -JavaScript代码如下 - -```js -/** - * ===================================================== - * 请在index.html文件中,编写arraysSimilar函数,实现判断传入的两个数组是否相似。具体需求: - * 1. 数组中的成员类型相同,顺序可以不同。例如[1, true] 与 [false, 2]是相似的。 - * 2. 数组的长度一致。 - * 3. 类型的判断范围,需要区分:String, Boolean, Number, undefined, null, 函数,日期, window. - * - * 当以上全部满足,则返回"判定结果:通过",否则返回"判定结果:不通过"。 - * ===================================================== - */ - -/* -* param1 Array -* param2 Array -* return true or false -*/ -function arraysSimilar(arr1, arr2){ - if (arr1 instanceof Array && arr2 instanceof Array ) { //先判断传入的是否是数组 - if (arr1.length == arr2.length) { //判断数组长度 - console.log("same-length"); - console.log(arr1); - console.log(arr2); - //开始判断数组内部是否相似 - return sameLengthArraysSimilar(arr1, arr2); - } else{ - //两个数组长度不同返回false - return false; - } - } else { - //传入的参数不是数组返回false - return false; - } -} - -/** - * 判断两个等长的数组内部是否相似 - * 遍历数组 - * arr1中元素各种类型出现的个数是否和arr2中元素各种类型出现的个数相同 - * @param {Array} arr1 数组1 - * @param {Array} arr2 数组2 - * @return {true,false} - */ -function sameLengthArraysSimilar(arr1,arr2) { - var numInArr1 = 0; - var numInArr2 = 0; - var booleanInArr1 = 0; - var booleanInArr2 = 0; - var funInArr1 = 0; - var funInArr2 = 0; - var undefinedInArr1 = 0; - var undefinedInArr2 = 0; - var stringInArr1 = 0; - var stringInArr2 = 0; - var nullInArr1 = 0; - var nullInArr2 = 0; - var dateInArr1 = 0; - var dateInArr2 = 0; - var windowInArr1 = 0; - var windowInArr2 = 0; - - for (var i = 0; i < arr1.length; i++) { - if(typeof arr1[i] === 'number' ){ - numInArr1 ++; - } else if(typeof arr1[i] === 'boolean'){ - booleanInArr1 ++; - } else if(typeof arr1[i] === 'function'){ - funInArr1 ++; - } else if(typeof arr1[i] === 'undefined'){ - undefinedInArr1 ++; - } else if(typeof arr1[i] === 'string'){ - stringInArr1 ++; - } else if(typeof arr1[i] ==='object'){ - if(Object.prototype.toString.apply(arr1[i]) === '[object Null]'){ - nullInArr1 ++; - } else if(Object.prototype.toString.apply(arr1[i]) === '[object Date]'){ - dateInArr1 ++; - } else if(Object.prototype.toString.apply(arr1[i]) === '[object global]'){ - windowInArr1 ++; - } - } - - if(typeof arr2[i] === 'number'){ - numInArr2 ++; - } else if(typeof arr2[i] === 'boolean'){ - booleanInArr2 ++; - } else if(typeof arr2[i] === 'function'){ - funInArr2 ++; - } else if(typeof arr2[i] === 'undefined'){ - undefinedInArr2 ++; - } else if(typeof arr2[i] === 'string'){ - stringInArr2 ++; - } else if(typeof arr2[i] ==='object'){ - if(Object.prototype.toString.apply(arr2[i]) === '[object Null]'){ - nullInArr2 ++; - } else if(Object.prototype.toString.apply(arr2[i]) === '[object Date]'){ - dateInArr2 ++; - } else if(Object.prototype.toString.apply(arr2[i]) === '[object global]'){ - windowInArr2 ++; - } - } - } - - console.log("num---"+numInArr1); - console.log("num---"+numInArr2); - console.log("boo---"+booleanInArr1); - console.log("boo---"+booleanInArr2); - console.log("null---"+nullInArr1); - console.log("null---"+nullInArr2); - console.log("window---"+windowInArr1); - console.log("window---"+windowInArr2); - console.log("date---"+dateInArr1); - console.log("date---"+dateInArr2); - console.log("string---"+stringInArr1); - console.log("string---"+stringInArr2); - console.log("fun---"+funInArr1); - console.log("fun---"+funInArr2); - console.log("undefined---"+undefinedInArr1); - console.log("undefined---"+undefinedInArr2); - - if(numInArr1 == numInArr2 && booleanInArr1==booleanInArr2 && funInArr1==funInArr2 && undefinedInArr1==undefinedInArr2 && stringInArr1==stringInArr2 && nullInArr1==nullInArr2 && dateInArr1==dateInArr2 && windowInArr1==windowInArr2){ - console.log('================================true'); - return true; - }else{ - console.log('================================false'); - return false; - } -} -``` - -## 总结 - -* 上述代码完美的跑完所有的测试用例,读者 [点击这里查看结果](http://gaohaoyang.github.io/javascript-test/arraysSimilar/),并且可以按 `f12` 看 Console 信息, 里面有代码的执行过程。 -* 当然你也可以复制本文的 JavaScript 代码,在 [慕课网的习题](http://imooc.com/code/5760) 下跑一下,也可以看到 `判定结果:通过` 的结果 -* 完整源代码在我的 GitHub [javascript-test/arraysSimilar/](https://github.com/Gaohaoyang/javascript-test/tree/master/arraysSimilar) 仓库中 -* 其实我的代码逻辑并不复杂,有点**空间换时间**的感觉,执行效率应该是较高的。没有用 JavaScript 封装的任何函数,完全是自己写的。其实代码除去 `console.log()` 也并没有多少行。 -* 各位读者有什么好的想法欢迎留言交流! diff --git a/_posts/2015-04-12-Syncing-a-fork.md b/_posts/2015-04-12-Syncing-a-fork.md deleted file mode 100644 index b202d64ed35..00000000000 --- a/_posts/2015-04-12-Syncing-a-fork.md +++ /dev/null @@ -1,94 +0,0 @@ ---- -layout: post -title: "同步一个 fork" -date: 2015-04-12 15:14:54 -categories: GitHub -tags: GitHub 同步 fork ---- - -* content -{:toc} - -fork 了别人的仓库后,原作者又更新了仓库,如何将自己的代码和原仓库保持一致?本文将给你解答。 - - - - - -## 如何使用搜索引擎 - -其实这个问题并不难,我又被坑了。百度搜的东西不靠谱啊,以后这种问题一定要用**英文**在 [Google](http://www.google.com) 或者 [Bing](http://cn.bing.com/) 上搜索,这样才能搜到原汁原味的答案。就当是一个教训吧。 - -搜索 fork sync,就可以看到 GitHub 自己的帮助文档 [Syncing a fork](https://help.github.com/articles/syncing-a-fork/) 点进去看这篇的时候,注意到有一个 Tip: Before you can sync your fork with an upstream repository, you must [configure a remote that points to the upstream repository](https://help.github.com/articles/configuring-a-remote-for-a-fork/) in Git. - -根据这两篇文章,问题迎刃而解! - -## 具体方法 - -### Configuring a remote for a fork - -* 给 fork 配置一个 remote - -* 主要使用 `git remote -v` 查看远程状态。 - -``` -git remote -v -# origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch) -# origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push) -``` - -* 添加一个将被同步给 fork 远程的上游仓库 - -``` -git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git -``` - - -* 再次查看状态确认是否配置成功。 - -``` -git remote -v -# origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch) -# origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push) -# upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch) -# upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push) -``` - -### Syncing a fork - -* 从上游仓库 fetch 分支和提交点,传送到本地,并会被存储在一个本地分支 upstream/master -`git fetch upstream` - -``` -git fetch upstream -# remote: Counting objects: 75, done. -# remote: Compressing objects: 100% (53/53), done. -# remote: Total 62 (delta 27), reused 44 (delta 9) -# Unpacking objects: 100% (62/62), done. -# From https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY -# * [new branch] master -> upstream/master -``` - -* 切换到本地主分支(如果不在的话) -`git checkout master` - -``` -git checkout master -# Switched to branch 'master' -``` - -* 把 upstream/master 分支合并到本地 master 上,这样就完成了同步,并且不会丢掉本地修改的内容。 -`git merge upstream/master` - -``` -git merge upstream/master -# Updating a422352..5fdff0f -# Fast-forward -# README | 9 ------- -# README.md | 7 ++++++ -# 2 files changed, 7 insertions(+), 9 deletions(-) -# delete mode 100644 README -# create mode 100644 README.md -``` - -* 如果想更新到 GitHub 的 fork 上,直接 `git push origin master` 就好了。 diff --git a/_posts/2015-04-15-baidu-ife-1.md b/_posts/2015-04-15-baidu-ife-1.md deleted file mode 100644 index c16211b13da..00000000000 --- a/_posts/2015-04-15-baidu-ife-1.md +++ /dev/null @@ -1,847 +0,0 @@ ---- -layout: post -title: "百度Web前端技术学院(1)-HTML, CSS基础" -date: 2015-04-15 19:06:05 -categories: HTML CSS -tags: Baidu ife HTML CSS task ---- - -* content -{:toc} - -百度前端学院的第一次任务笔记,HTML、CSS 基础。主要有 CSS 工作原理,选择器的使用,常用属性,行高属性,盒模型与定位,最后根据设计图实现4个页面。 - - - - -## 任务 - -**任务:** [HTML、CSS基础](https://github.com/Gaohaoyang/ife/tree/master/task/task0001) - -有人问到提交作业 fork 同步的问题,真心觉得官方 GitHub 的帮助文档讲的很好,我上一篇博客 [同步一个 fork](http://gaohaoyang.github.io/2015/04/12/Syncing-a-fork/) 就是翻译的这个官方文档,如果懒得看英文可以参考我的博客。 - - -写点东西记录一下我的做题过程吧。 - - -## CSS 如何工作 - -[CSS 如何工作](https://developer.mozilla.org/zh-CN/docs/Web/Guide/CSS/Getting_started/How_CSS_works) Mozilla 的开发者文档讲的很好。 - -> 浏览器在展现一个文档的时候,必须要把文档内容和相应的样式信息结合起来展示。 这个处理过程一般分两个阶段: -> -> 1. 浏览器先将标记语言和 CSS 转换成 DOM (文档对象模型)结构。 这时 DOM 就代表了电脑内存中的相应文档,因为它已经融合了文档内容和相应的样式表。 -> 2. 最后浏览器把 DOM 的内容展示出来。 - - -## 层叠和继承 - -[参考资料: 层叠和继承](https://developer.mozilla.org/zh-CN/docs/Web/Guide/CSS/Getting_started/Cascading_and_inheritance) - -> 对于层叠来说,共有三种主要的样式来源: -> -> * 浏览器对HTML定义的默认样式。 -> * 用户定义的样式。 -> * 开发者定义的样式,可以有三种形式: -> -> * 定义在外部文件(外链样式):本教程中案例主要是通过这种形式定义样式。 -> * 在页面的头部定义(内联样式):通过这种形式定义的样式只在本页面内生效。 -> * 定义在特定的元素身上(行内样式):这种形式多用于测试,可维护性较差。 -> -> 用户定义的样式表会覆盖浏览器定义的默认样式,然后网页开发者定义的样式又会覆盖用户样式。 -> -> 再来看看优先级,从高到低依次为:网页开发者定义的样式、网页阅读者定义的样式、浏览器的默认样式。 -> -> 对继承的元素来说,子元素自身的样式优先级高于从父级继承来的样式。 -> -> > 更多细节 -> > CSS 另外提供了一个 !important 关键字,用户可以通过使用这个关键字使自己定义的样式覆盖掉开发者定义的样式。 -> > 这就意味着,作为开发者,你很难准确的预知页面最终在用户电脑上的显示效果。 - - -## 选择器 - -[参考资料:选择器(Selectors)](https://developer.mozilla.org/zh-CN/docs/Web/Guide/CSS/Getting_Started/Selectors) - - -### 标签选择器 - - -### 类选择器(Class selectors) - -> 通过设置元素的 class 属性,可以为元素指定类名。类名由开发者自己指定。 文档中的多个元素可以拥有同一个类名。 -> -> 在写样式表时,类选择器是以英文句号(.)开头的。 - - -### ID选择器(ID selectors) - -> 通过设置元素的 id 属性为该元素制定ID。ID名由开发者指定。每个ID在文档中必须是唯一的。 -> -> 在写样式表时,ID选择器是以#开头的。 - - -### 优先级 - -> * 如果多余一个规则指定了相同的属性值都应用到一个元素上,CSS规定拥有更高确定度的选择器优先级更高。ID选择器比类选择器更具确定度, 而类选择器比标签选择器(tag selector)更具确定度。 -> * 如果样式中包含冲突的规则,且它们具有相同的确定度。那么,后出现的规则优先级高。 -> * 如果你遇到规则冲突,你可以增加其中一条的确定度或将之移到后面以使它具有更高优先级。 - - -### 伪类选择器(Pseudo-classes selectors) - - -### 基于关系的选择器 - -选择器 |选择的元素 -A E |任何是元素A的后代元素E (后代节点指A的子节点,子节点的子节点,以此类推) -A > E |任何元素A的子元素 -E:first-child |任何元素的第一个子元素E -B + E |任何元素B的下一个兄弟元素E - - -## 其他属性 - -### `text-indent` - -**定义和用法** -text-indent 属性规定文本块中首行文本的缩进。 -注释:允许使用负值。如果使用负值,那么首行会被缩进到左边。 - -**可能的值** - -值 |描述 -length |定义固定的缩进。默认值:0。 -% |定义基于父元素宽度的百分比的缩进。 -inherit |规定应该从父元素继承 text-indent 属性的值。 - - -### `text-transform` - -**定义和用法** -text-transform 属性控制文本的大小写。 - -**说明** -这个属性会改变元素中的字母大小写,而不论源文档中文本的大小写。如果值为 capitalize,则要对某些字母大写,但是并没有明确定义如何确定哪些字母要大写,这取决于用户代理如何识别出各个“词”。 - -**可能的值** - -值 |描述 -none |默认。定义带有小写字母和大写字母的标准的文本。 -capitalize |文本中的每个单词以大写字母开头。 -uppercase |定义仅有大写字母。 -lowercase |定义无大写字母,仅有小写字母。 -inherit |规定应该从父元素继承 text-transform 属性的值。 - - -### `text-decoration` - -**定义和用法** -text-decoration 属性规定添加到文本的修饰。 -注释:修饰的颜色由 "color" 属性设置。 -注释:IE、Chrome 或 Safari 不支持 "blink" 属性值。 - -**说明** -这个属性允许对文本设置某种效果,如加下划线。如果后代元素没有自己的装饰,祖先元素上设置的装饰会“延伸”到后代元素中。不要求用户代理支持 blink。 - - -### `text-align` - -**定义和用法** -text-align 属性规定元素中的文本的水平对齐方式。 -该属性通过指定行框与哪个点对齐,从而设置块级元素内文本的水平对齐方式。通过允许用户代理调整行内容中字母和字之间的间隔,可以支持值 justify;不同用户代理可能会得到不同的结果。 - -**可能的值** - -值 |描述 -left |把文本排列到左边。默认值:由浏览器决定。 -right |把文本排列到右边。 -center |把文本排列到中间。 -justify |实现两端对齐文本效果。 -inherit |规定应该从父元素继承 text-align 属性的值。 - - -### `word-spacing` - -**定义** -word-spacing 属性增加或减少单词间的空白(即字间隔)。 -该属性定义元素中字之间插入多少空白符。针对这个属性,“字” 定义为由空白符包围的一个字符串。如果指定为长度值,会调整字之间的通常间隔;所以,normal 就等同于设置为 0。允许指定负长度值,这会让字之间挤得更紧。 -注释:允许使用负值。 - - -### `white-space` - -**定义和用法** -white-space 属性设置如何处理元素内的空白。 -这个属性声明建立布局过程中如何处理元素中的空白符。值 pre-wrap 和 pre-line 是 CSS 2.1 中新增的。 - -**可能的值** - -值 |描述 -normal |默认。空白会被浏览器忽略。 -pre |空白会被浏览器保留。其行为方式类似 HTML 中的 `
` 标签。
-nowrap    |文本不会换行,文本会在在同一行上继续,直到遇到 `
` 标签为止。 -pre-wrap |保留空白符序列,但是正常地进行换行。 -pre-line |合并空白符序列,但是保留换行符。 -inherit |规定应该从父元素继承 white-space 属性的值。 - - -### `@font-face` - -**CSS3 @font-face 规则** -在 CSS3 之前,web 设计师必须使用已在用户计算机上安装好的字体。 -通过 CSS3,web 设计师可以使用他们喜欢的任意字体。 -当您您找到或购买到希望使用的字体时,可将该字体文件存放到 web 服务器上,它会在需要时被自动下载到用户的计算机上。 -您“自己的”的字体是在 CSS3 @font-face 规则中定义的。 - -注释:Internet Explorer 8 以及更早的版本不支持新的 @font-face 规则。Internet Explorer 9+ 支持新的 @font-face 规则,但是仅支持 .eot 类型的字体 (Embedded OpenType)。 - -**使用您需要的字体** -在新的 @font-face 规则中,您必须首先定义字体的名称(比如 myFirstFont),然后指向该字体文件。 -如需为 HTML 元素使用字体,请通过 font-family 属性来引用字体的名称 (myFirstFont): - -**实例** - -```css -@font-face { - font-family: myFirstFont; - src: url('Sansation_Light.ttf'), - url('Sansation_Light.eot'); /* IE9+ */ -} -div { - font-family: myFirstFont; -} -``` - -**CSS3 字体描述符** - -下面的表格列出了能够在 @font-face 规则中定义的所有字体描述符: - -描述符 |值 |描述 -font-family |name |必需。规定字体的名称。 -src |URL |必需。定义字体文件的 URL。 -font-stretch |normal
condensed
ultra-condensed
extra-condensed
semi-condensed
expanded
semi-expanded
extra-expanded
ultra-expanded|可选。定义如何拉伸字体。默认是 "normal"。 -font-style|ormal
italic
oblique|可选。定义字体的样式。默认是 "normal"。 -font-weight|normal
bold
100
200
300
400
500
600
700
800
900|选。定义字体的粗细。默认是 "normal"。 -unicode-range |unicode-range |可选。定义字体支持的 UNICODE 字符范围。默认是 "U+0-10FFFF"。 - - -## 深入了解行高属性 - -[参考:深入了解css的行高Line Height属性](http://www.cnblogs.com/fengzheng126/archive/2012/05/18/2507632.html) - -一般来说,设置行高为`值:纯数字`是最理想的方式,因为其会随着对应的 `font-size` 而缩放。 - - -## 盒模型及定位 - -### 已知宽度的div居中 - -* 用两种方法来实现一个背景色为红色、宽度为960px的
在浏览器中居中 - -我的方法一: - -使用 `margin:0 auto;` - -html文件 - -```html - - - - - Document - - - -
aaa
- - -``` - -css文件 - -```css -.center { - width: 960px; - margin: 0 auto; - background-color: red; -} -``` - -方法二: - -绝对定位,左边距离 body 50%,`margin-left: -480px` - -```css -.center { - width: 960px; - background-color: red; - position: absolute; - left: 50%; - margin-left: -480px; -} -``` - -[Demo](http://gaohaoyang.github.io/baidu-ife-practice/task0001/task0001-2.html) - -#### 对于居中的补充 - -参考自 [学习CSS布局](http://zh.learnlayout.com/)。 - -像下面这样写css代码,使用 `max-width` 替代 `width` 可以使浏览器更好地处理小窗口的情况。这点在移动设备上显得尤为重要。 - -有效的避免了如下问题: -当浏览器窗口比元素的宽度还要窄时,浏览器会显示一个水平滚动条来容纳页面。 - -```css -#main { - max-width: 600px; - margin: 0 auto; -} -``` - -* [CSS布局奇淫技巧之--各种居中](http://www.cnblogs.com/2050/p/3392803.html) - - -### 早期css滑动门 - -* 有的圆角矩形是复杂图案,无法直接用border-radius,请在不使用 border-radius 的情况下实现一个可复用的高度和宽度都自适应的圆角矩形 -示例 ![圆角矩形](http://7q5cdt.com1.z0.glb.clouddn.com/Baidu-Front-end-task0001_7.png) - -这道题我一开始不会做,查阅了资料,发现这就是所谓的 css 滑动门的应用。[妙味云课堂之css:滑动门、圆角、css精灵](http://www.bkjia.com/webzh/759711.html) -使用三层嵌套,或者四层嵌套的 `div`,通过背景图定位等方式可以实现。 - - -### 左侧固定右侧自适应宽度的两列布局 - -* 用两种不同的方法来实现一个两列布局,其中左侧部分宽度固定、右侧部分宽度随浏览器宽度的变化而自适应变化 ![pic](http://7q5cdt.com1.z0.glb.clouddn.com/Baidu-Front-end-task0001_3.jpg) - -我的方法一: - -不使用浮动,使用绝对定位,将左上角的块放好位置,右边的块设置`margin-left` - -html 文件: - -```html - - - - - layout - - - -
-
DIV-A
-
DIV-B
-
-
DIV-C
- - -``` - -css 文件: - -```css -.row { - position: relative; -} -.left { - width: 100px; - height: 100px; - background-color: red; - position: absolute; - top: 0; - left: 0; -} -.right { - height: 100px; - background-color: blue; - margin-left: 100px; -} -.bottom { - height: 100px; - background-color: yellow; -} -``` - -方法二: - -使用浮动,左边的块使用浮动,右边的块使用`margin-left` - -```css -.left { - width: 100px; - height: 100px; - background-color: red; - float: left; -} -.right { - height: 100px; - background-color: blue; - margin-left: 100px; -} -.bottom { - height: 100px; - background-color: yellow; -} -``` - -[Demo](http://gaohaoyang.github.io/baidu-ife-practice/task0001/task0001-6-3.html) - - -**补充:** - -看完了后面的 BFC 之后,本题和下一题都可以用另一种方法了 -总之我已经震惊了!太爽了!有没有! - -html - -```html - - - - - 使用 BFC 进行两列布局 - - - -
DIV-A
-
DIV-B
-
DIV-C
- - -``` - -css - -```css -.left{ - width: 100px; - height: 100px; - background-color: blue; - float: left; -} -.right{ - height: 100px; - background-color: yellow; - overflow: hidden; -} -.bottom{ - height: 100px; - background-color: red; -} -``` - -[Demo](http://gaohaoyang.github.io/baidu-ife-practice/task0001/two-col-layout-with-BFC.html) - - -### 双飞翼布局 - -* 用两种不同的方式来实现一个三列布局,其中左侧和右侧的部分宽度固定,中间部分宽度随浏览器宽度的变化而自适应变化 - -原题中参考资料 [双飞翼布局](http://www.imooc.com/wenda/detail/254035) - -```html - - - - - Flying Swing Layout - - - -
-
-
-

Flying Swing Layout

-
-
-
-

Flying Swing Layout

- left -
-
-

Flying Swing Layout

- right -
-
- - -``` - -css - -```css -.bd { - - /*padding: 0 190px;*/ -} -.main { - float: left; - width: 100%; - background-color: #aaa; -} -.main-wrap { - margin: 0 190px; -} -.sub { - float: left; - width: 190px; - margin-left: -100%; - background-color: blue; - /*position: relative; - left: -190px;*/ -} -.extra { - float: left; - width: 190px; - margin-left: -190px; - background-color: yellow; - /*position: relative; - right: -190px;*/ -} -``` - -[Demo](http://gaohaoyang.github.io/baidu-ife-practice/task0001/task0001-6-4.html) - - -**补充:** - -使用 BFC 的另一种方法,我再一次震惊! - -代码超级简单! - -html - -```html - - - - - flying-Swing-BFC - - - -
left
-
right
-
- flying-Swing-BFC.htmlflying-Swing-BFC.htmlflying-Swing-BFC.htmlflying-Swing-BFC.htmlflying-Swing-BFC.htmlflying-Swing-BFC.htmlflying-Swing-BFC.htmlflying-Swing-BFC.htmlflying-Swing-BFC.htmlflying-Swing-BFC.htmlflying-Swing-BFC.html -
- - - -``` - -css - -```css -.left{ - width: 100px; - background-color: red; - float: left; -} -.right{ - width: 200px; - background-color: blue; - float: right; -} -.main{ - background-color: #eee; - overflow: hidden; -} -``` -[Demo](http://gaohaoyang.github.io/baidu-ife-practice/task0001/flying-Swing-BFC.html) - - -### 浮动布局 - -* 实现一个浮动布局,红色容器中每一行的蓝色容器数量随着浏览器宽度的变化而变化 ![pic](http://7q5cdt.com1.z0.glb.clouddn.com/Baidu-Front-end-task0001_4.jpg)![pic](http://7q5cdt.com1.z0.glb.clouddn.com/Baidu-Front-end-task0001_5.jpg) - -这个题我觉的直接将每一个块浮动起来就好了,不知我理解的对不对。 - -html文件 - -```html - - - - - Document - - - -
-
-
-
-
-
-
-
-
- - -``` - -css文件 - -```css -body { - background-color: red; -} -div { - width: 150px; - height: 100px; - margin: 10px; - float: left; - background-color: blue; -} -``` - -[Demo](file:///E:/GitWorkSpace/baidu-ife-practice/task0001/task0001-6-5.html) - - -### 清除浮动/闭合浮动 - -参考自 [那些年我们一起清除过的浮动 by 一丝冰凉](http://www.iyunlu.com/view/css-xhtml/55.html) - -1. 清除浮动:清除对应的单词是 clear,对应CSS中的属性是 clear:left \| right \| both \| none; -2. 闭合浮动:更确切的含义是使浮动元素闭合,从而减少浮动带来的影响。 - -我们想要达到的效果更确切地说是闭合浮动,而不是单纯的清除浮动,设置clear:both清除浮动并不能解决warp高度塌陷的问题。 - -正是因为浮动的这种特性,导致本属于普通流中的元素浮动之后,包含框内部由于不存在其他普通流元素了,也就表现出高度为0(**高度塌陷**)。在实际布局中,往往这并不是我们所希望的,所以需要闭合浮动元素,使其包含框表现出正常的高度。 - -最后一丝姐给了两个精益求精方案,我觉得方案一更易于理解,这里实践一下: - -[闭合浮动的Demo](http://gaohaoyang.github.io/baidu-ife-practice/task0001/close-float.html) - -下面是源码 - -html - -```html - - - - - Document - - - -
-
-

left

-
Content or Something
-
-
right
-
-
Row2
- - -``` - -css - -```css -.row { - border: 1px solid red; -} -.clearfix:after { - content: "\200B"; - display: block; - height: 0; - clear: both; -} -.clearfix { - *zoom: 1; -} -.left { - width: 200px; - float: left; - background-color: #eee; -} -.right { - width: 200px; - float: right; - background-color: #eee; -} -.row2 { - width: 600px; - height: 50px; - background-color: #aaa; -} -``` - -其中`*zoom: 1`是为了触发`hasLayout` - - -还有另一种解决方案! - -参考自:[清除浮动(clearfix hack)](http://zh.learnlayout.com/clearfix.html) - -直接使用,如下代码即可 - -```css -.clearfix{ - overflow: auto; - zoom: 1; -} -``` - -[Demo](http://gaohaoyang.github.io/baidu-ife-practice/task0001/close-float-2.html) - -(实际上,我看完后面的资料,再翻到这里就明白了!正是使用了BFC原理!!!!!!!) - - -**但是今天遇到一个坑!** - -如果使用了 `over-flow`,在后面如果有元素要绝对布局在父元素的外面的,意思就是出现 `top`, `bottom`, `left`, `right` 的值为负值时,就会出现看不到,或者滚动条的问题! - -若是有这种要求,我觉得还是用一丝姐姐的解决方案比较好。 - -**参考** - -* [清除浮动的几种方法](http://zfengqi.me/?p=87) - - -### `box-sizing` - -当你设置一个元素为 `box-sizing: border-box;` 时,此元素的内边距和边框不再会增加它的宽度。 - -他们的内边距和边框都是向内的挤压的。支持IE8+,需要加浏览器内核。 - -```css -.simple { - width: 500px; - margin: 20px auto; - -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; - box-sizing: border-box; -} -``` - - -### 响应式布局 - -媒体查询 - -* [MDN CSS媒体查询](https://developer.mozilla.org/zh-CN/docs/Web/Guide/CSS/Media_queries) -* [媒体查询-学习CSS布局](http://zh.learnlayout.com/media-queries.html) - - `@media screen and (min-width: 500px) and (max-width: 800px) { ... }` - -* [An Introduction to Meta Viewport and @viewport](https://dev.opera.com/articles/an-introduction-to-meta-viewport-and-viewport/) - - -### 多列布局 - -* [column](http://zh.learnlayout.com/column.html) - - -### BFC 和 IE 的 hasLayout - -* [BFC和IE的hasLayout](http://www.cnblogs.com/pigtail/archive/2013/01/23/2871627.html) -* [Block Formatting Context 的几大用处](http://outofmemory.cn/wr/?u=http%3A%2F%2Fkkeys.me%2Fpost%2F68547473290) - -看完这个资料后我震惊了!竟然可以这么玩儿! -我将本文之前提到的两列布局,双飞翼布局又重新写了一遍!太爽了!代码超级简洁! - -**Block Formatting Context 的几大用处:** - -1. 防止 margin 折叠 -1. 清除float -1. 不会环绕float元素 - -相关资料 - -* [视觉格式化模型(visual formatting model)](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Visual_formatting_model) -* [块格式化上下文(block formatting context)](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Block_formatting_context) - - -### `div` 三列等高 - -[纯CSS实现三列DIV等高布局](http://show.sysu.edu.cn/?action-blogdetail-uid-2383-id-5040) - -最关键的地方有3句: - -最外层div设置一个溢出隐藏 - -```css -#wrap { - overflow:hidden; -} -``` - -每一个子块设置 padding 和 margin - -```css -#left,#center,#right{ - margin-bottom:-10000px; - padding-bottom:10000px; -} -``` - -overflow:hidden; '隐藏溢出。如果内容溢出wrap层,则不显示。 - -margin-bottom:-10000px; '底部边距-10000px。 -padding-bottom:10000px; '底部填充10000px。 -上面这两句能够实现的效果就是,产生10000px的填充,然后用负的边距把它给抵销掉。 - - -### 去除inline-block元素间间距 - -一开始我不知道是因为使用了 `display: inline-block` 会有间距。后来查找资料找到了相关的方案。 - -* [去除inline-block元素间间距的N种方法](http://www.zhangxinxu.com/wordpress/2012/04/inline-block-space-remove-%E5%8E%BB%E9%99%A4%E9%97%B4%E8%B7%9D/) -* [Fighting the Space Between Inline Block Elements](https://css-tricks.com/fighting-the-space-between-inline-block-elements/) - -真正意义上的inline-block水平呈现的元素间,换行显示或空格分隔的情况下会有间距。 -这种表现是符合规范的应该有的表现。 - -解决方法有很多,上述博文中提到的有: - -1. 移除空格 -2. 使用 `margin` 负值 -3. 取消闭合标签 -4. 使用 `font-size: 0` -5. 使用 `letter-spacing` -6. 使用 `word-spacing` -7. 其他 - -我觉得使用 4 `font-size: 0` 比较好,对别的元素影响最小。代码如下:在 `a` 的外层将字体尺寸设为 0,载对内层的 `a` 重新设置字体大小,即可。 - -```css -nav { - font-size: 0; -} -nav a { - font-size: 16px; -} -``` - - -## 最终作品 - -* [在线Demo](http://gaohaoyang.github.io/ife/task/task0001/work/Gaohaoyang/index.html) -* [源代码](https://github.com/Gaohaoyang/ife/tree/master/task/task0001/work/Gaohaoyang) - - -## 参考资料 - -* [HTML、CSS的代码规范](https://github.com/ecomfe/spec) 自己要试着改变一些代码风格了,规范化! -* [顾轶灵:Web语义化](http://www.zhihu.com/question/20455165) -我看他回答最后的举例的Sildes做的非常好,可以经常看看。[Semantic HTML](http://justineo.github.io/slideshows/semantic-html/)。他的其他Slides也做的非常好,很喜欢这种风格! -* [CSS命名规范@W3C Funs](http://www.w3cfuns.com/blog-5445898-5398950.html) 起名不再困难! -* [点击阅读: CSS浏览器兼容性列表-维基百科](点击阅读: CSS浏览器兼容性列表) 类似的我想到了 [Can I Use](http://caniuse.com/),Can I Use 包含的更多,包括 HTML5, CSS SVG, JS API 等。 - - -* [学习CSS布局](http://zh.learnlayout.com/) -* [Media Queries](http://mediaqueri.es/) -* [使用CSS渐变](https://developer.mozilla.org/zh-CN/docs/Web/Guide/CSS/Using_CSS_gradients) -* [CSS3 Gradient](http://www.w3cplus.com/content/css3-gradient) -* [CSS渐变生成器](http://www.colorzilla.com/gradient-editor/) diff --git a/_posts/2015-04-22-baidu-ife-2-javascript.md b/_posts/2015-04-22-baidu-ife-2-javascript.md deleted file mode 100644 index 5f50a9826eb..00000000000 --- a/_posts/2015-04-22-baidu-ife-2-javascript.md +++ /dev/null @@ -1,1586 +0,0 @@ ---- -layout: post -title: "百度Web前端技术学院(2)-JavaScript 基础" -date: 2015-04-22 19:06:05 -categories: JavaScript -tags: Baidu ife JavaScript 正则 Regular ---- - -* content -{:toc} - -百度前端学院的第二次任务笔记,JavaScript 基础。主要有JavaScript的定义,数据类型,对象,数组,字符串,正则表达式,DOM,事件,BOM,Ajax 等知识。 - - - - - -## 任务 - -掌握JavaScript基础知识,能够使用JavaScript编写一些复杂度不大的交互功能。 - -**任务:** [JavaScript基础](https://github.com/Gaohaoyang/ife/tree/master/task/task0002) - -做完任务一的时候深深地感觉到自己的基础非常的薄弱,在这里再次感谢一下百度前端技术学院,做任务的时候深刻理解了自己平时掌握不牢固的内容,比如浮动、BFC、等高布局等。继续加油吧! - - -像上一篇文章一样,写些东西记录一下。 - - -## 第一个页面交互 - -按照任务中的代码,在IE8下提示:`对象不支持“addEventListener”属性或方法` -我猜是IE8浏览器没有这个方法吧。 - -参考资料:[JavaScript 指南-MDN](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide) - -### 了解JavaScript是什么 - -[来自MDN的解释](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/JavaScript_Overview#What_is_JavaScript.3F) - -> JavaScript 是一种跨平台,面向对象的脚本语言。作为一种小巧且轻量级的语言,JavaScript 无意于独立运行,而是被设计为可以轻易嵌入到其它的产品和应用中,比如 Web 浏览器。在宿主环境中,JavaScript 可以被连接到环境中的对象之上,以提供对其的编程控制。 -> -> 核心的 JavaScript 中包含有一组核心的对象,包括 Array,Date 和 Math,以及一组核心的语言要素,包括操作符,控制结构和语句。出于多种目的,可以通过为其增补附加的对象,对核心 JavaScript 加以扩展;例如: -> -> * 客户端 JavaScript 提供了用于控制浏览器(Navigator 或者其它浏览器)以及其中的文档对象模型(DOM)的对象,从而扩展了核心 JavaScript。例如,客户端扩展允许应用程序在 HTML 的表单中加入元素,以便响应用户事件,比如鼠标点击,表单输入和页面导航。 -> * 服务器端 JavaScript 提供了服务于在服务器上运行 JavaScript 的对象,从而扩展了核心 JavaScript。例如,服务器端扩展可以允许应用程序访问关系型数据库,在应用程序的不同调用间提供信息的连续性,甚至于处理服务器之上的文件。 -> ->借由 JavaScript 的 LiveConnect 功能,您可以让 Java 和 JavaScript 间实现通讯。从 JavaScript 中,您可以创建 Java 对象并访问它们的公共方法和域。从 Java 中,也可以访问 JavaScript 的对象,属性和方法。 -> ->Netscape 发明了 JavaScript 并将 JavaScript 首先用于 Netscape 浏览器中。 - - -### 如何在 HTML 页面加载 JavaScript 代码 - -使用 ` - - - - -``` - -在支持 defer 属性的浏览器上,弹出的顺序则是:"script"、"defer"、"load"。请注意,带有 defer 属性的 ` - - 这里要说明一下,要把上面的 localhost 换为本机的 ip 地址。 - - 我们可以在命令行中 使用 `ipconfig` 得到 ip 地址,如下(当然你的可能和我的不一样): - - IPv4 地址 . . . . . . . . . . . . : 192.168.1.107 - - 即插入如下代码: - - - -4. 进入调试页面 - - PC 端访问这个地址: - - debug client user interface: http://localhost:8081/client/#anonymous - - 此时 target 为 none,如下图: - - ![target-none](http://7q5cdt.com1.z0.glb.clouddn.com/blog-target-none.png) - - 现在我们要用手机访问同一个局域网下的这个目标页面。我们可以把要调试的页面放到这个路径下: - - C:\Users\haoyang\AppData\Roaming\npm\node_modules\weinre\web - - 通过 http://192.168.1.107:8081/FILE_NAME 在手机上访问,就可以看到了。当然前提是同一个局域网。 - - 但是这样可能不太灵活,每次都要把目标页面放到指定的目录下。所以我们可以另外开一个服务器。 - - 我使用了基于 node.js 的 http-server 工具。将要调试的页面发布。这样我就能通过 ip 地址加端口号在手机上访问到了。 - - 我在手机上访问 http://192.168.1.107:8080 打开要调试的页面,此时 debug client user interface 中自动检测到 target。就可以进行调试了! - - 如下图: - - ![target](http://7q5cdt.com1.z0.glb.clouddn.com/blog-target.png) - - ![phone](http://7q5cdt.com1.z0.glb.clouddn.com/blog-1954958440_meitu_2.jpg) - ---- - -## 参考 - -* [Web移动应用调试工具——Weinre](http://blog.csdn.net/dojotoolkit/article/details/6280924) -* [weinre - WEb INspector REmote](http://muellerware.org/papers/weinre/manual.html) -* [webapp开发调试环境--weinre配置](http://blog.csdn.net/smy_yu/article/details/38922315) diff --git a/_posts/2015-07-09-JavaScript-Net.md b/_posts/2015-07-09-JavaScript-Net.md deleted file mode 100644 index 02a72c71bb0..00000000000 --- a/_posts/2015-07-09-JavaScript-Net.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -layout: post -title: "JavaScript 阶段总结" -date: 2015-07-09 00:06:05 -categories: JavaScript -tags: JavaScript HTML CSS 思维导图 技能树 ---- - -做了一张思维导图。总结这几个月对 JavaScript 的学习吧,也是一个复习。也是我目前的技能树。 - - - - -![JavaScriptNet](http://7q5cdt.com1.z0.glb.clouddn.com/blog-JavaScriptNet2.png) diff --git a/_posts/2015-07-24-low-IE-click-empty-block-bug.md b/_posts/2015-07-24-low-IE-click-empty-block-bug.md deleted file mode 100644 index cc5cd8abdba..00000000000 --- a/_posts/2015-07-24-low-IE-click-empty-block-bug.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -layout: post -title: "在低版本 IE 中点击空 block 元素的问题" -date: 2015-07-24 00:06:05 -categories: CSS -tags: IE CSS 兼容性 HTML ---- - -* content -{:toc} - -## 问题描述 - -当我们点击一个空的、没有任何内容的 div 或者其他块级元素时。在 IE11 以下,是没有反应的。 - - - - - -## 使用场景 - -这类问题使用场景还是很普遍的。比如 UI 给了一张大图,要点击图上的某一块位置的时候。可以用一个空的 div 定位到相应的位置,然后对它进行绑定事件。 - ---- - -## 解决办法 - -解决方法很简单,即给这个块级元素填充任意颜色,然后将其透明度设置为0。代码如下: - - background-color: #fff; - opacity: 0; - filter:alpha(opacity=0); diff --git a/_posts/2015-12-31-History-API.md b/_posts/2015-12-31-History-API.md deleted file mode 100644 index 308f11b8a00..00000000000 --- a/_posts/2015-12-31-History-API.md +++ /dev/null @@ -1,167 +0,0 @@ ---- -layout: post -title: "前端处理动态 url 和 pushStatus 的使用" -date: 2015-12-31 23:06:05 -categories: JavaScript -tags: JavaScript Ajax URL HistoryApi pushState pjax ---- - -* content -{:toc} - -## 起因 - -起因是这样的,在尝试前后端分离的这条道路上,我自己也在不断摸索,感觉要把大部分的坑都踩踩了。目前我用的技术是: - -* webpack 自动构建 -* AMD 模块化 js -* Sass 预处理 CSS -* 使用前端模板引擎 handlebars 解决动态操作将 html 拼接在 js 中的问题 - -但最近写了一个项目类似知乎这样的多页网站。前端 url 的处理让我觉得不够优雅。我使用的是 hash 的方式处理动态 url 的,为此我专门在知乎上提了一个问题:[前端如何处理动态url?](https://www.zhihu.com/question/38802932) - - - - -这里我将问题描述如下: - -> 前后端彻底分离的情况下,页面跳转页全部由前端控制。那么如何更好的处理动态url地址? -> 例如本问题的url为 -> https://www.zhihu.com/question/38802932 -> 这肯定是用后台路由处理的url -> -> 纯前端怎么处理?用hash吗,如下: -> https://www.zhihu.com/question#38802932 -> 那如果本页跳转,只改变hash的话,页面不会刷新。 -> 使用`location.reload()`倒是可以解决。 -> -> **但总觉得这样处理不够优雅。大家在工作中是如何处理此类场景的?还是用传统的后台路由来提供动态url?** - - -感谢郑海波和剧中人的热心回答。都提到了`history`对象中的`pushState`,这是我第一次接触到这方面的内容(顿时觉得自己真是才疏学浅)。 - -同时也有人提到了`pjax`,这个就是`pushState`+`Ajax`的封装,也很有意思。 - -下面就来研究和实践一下吧。 - -## History - -`window`对象通过`history`对象提供对浏览器历史记录的访问能力。它暴露了一些非常有用的方法和属性,让你在历史记录中自由前进和后退,而在 HTML5 中,更可以操纵历史记录中的数据。 - -### `back()`, `forward()`, `go()`, `length` - -浏览器的历史记录就好像一个栈,最新的在最上面,较早之前看过的在下面。 - -如下图,Chrome的历史记录: - -![chrome history](http://ww2.sinaimg.cn/large/7011d6cfjw1ezb16fn2bfj20k008htan.jpg) - -下面介绍怎么在这些历史记录中跳转,但要**注意**,上图中的浏览器历史记录和本文说的 history 还不太同。 - -* `back()` - - 在历史记录中后退 - - history.back(); - -* `forward()` - - 在历史记录中前进 - - history.forward(); - -* `go()` - - 移动到指定的历史记录点 - - history.go(-1); - - 通过指定一个相对于当前页面位置的数值,你可以使用go()方法从当前会话的历史记录中加载页面(当前页面位置索引值为0,上一页就是-1,下一页为1)。 - - **go()不填参数或参数为go(0)时,页面会刷新,即`history.go()`或`history.go(0)`相当于`location.reload()`** - -* `length` - - `length`为history的属性,显示history长度。 - -本节在线demo见:[History & pjax demo](http://gaohaoyang.github.io/history-pjax-demo/) 源代码:[]() - -**经过亲自测试,`history`对象只记录同一个 tab 页内的历史。如果是在新窗口打开的,则无效。如:在a标签中添加`target="_blank"`,或按住`ctrl`点击,这类场景下,在新的tab页中,`history`对象也是新的。** - -**且`history`对象记录的信息与是否同源也无关,所以唯一要满足的就是同一个标签页。** - -### `pushState()`, `replaceState()` - -HTML5 引进了`history.pushState()`方法和`history.replaceState()`方法,它们允许你逐条地添加和修改历史记录条目,能够在不加载新页面的情况下没改变浏览器的URL。这些方法可以协同`window.onpopstate`事件一起工作。 - -使用`history.pushState()`会改变`referrer`的值,而在你调用方法后创建的 XMLHttpRequest 对象会在 HTTP 请求头中使用这个值。`referrer的`值则是创建 XMLHttpRequest 对象时所处的窗口的 URL。 - -* `pushState(any data, string title, [string url])` - - 第一个参数为`history`对象的`state`属性值,可以放任意数据,记录历史状态。第二个参数是新状态的标题,目前浏览器基本不支持。第三个参数为可选的相对url。 - - 执行`pushState`后,可以在不加载新页面的情况下,更改url。同时`history`栈中新增一条数据。 - - 例如,我们有这样一段代码: - - - - document.querySelector('#push1').addEventListener('click', function() { - history.pushState('abc','pushStatePageTitle','pushState.html'); - document.querySelector('#length').innerHTML = history.length;//重新读取历史长度 - }); - - 当点击按钮的时候,页面不会刷新,但`url`地址的最后已经变为`pushState.html`。这一点非常像`hash`的作用,但比`hash`更优雅。 - - -* `replaceState(any data, string title, [string url])` - - 与`pushState()`类似,只是在`history`栈中不是新增记录,而是替换一条记录。 - -**需要注意的是:**`pushState()`和`replaceState()`方法存在安全方面的限制,本地测试是无效的,会报错,可以简单放到任何服务端测试,或者使用`http-server`开启简单服务器,通过访问`localhost`来查看效果。 - -本节demo见:[History & pjax demo - pushState](http://gaohaoyang.github.io/history-pjax-demo/index.html) - -## pjax - -现在再看本文一开始提出的问题,如何让前端优雅的控制 url,这里就可以考虑 pjax 技术了。我们把 pushState + ajax 进行封装,合起来简称为 pjax。虽然不是什么新的技术,但概念已然不同。 - -如果不使用 pjax。我们依然可以使用`hash`来实现文本开始的需求。但会不利于 SEO,看着也不够优雅。 - -Pjax的原理十分简单。 - -1. 拦截 a 标签的默认跳转动作或某些按钮的点击事件。 -2. 使用 Ajax 请求新页面。 -3. 将返回的 Html 替换到页面中。 -4. 使用 HTML5 的`pushState()`修改Url。 - -个人理解3中也可以仅仅请求数据,再由浏览器渲染。 - -每当同一个文档的浏览历史(即history对象)出现变化时,会触发`window.onpopstate`事件。 - - window.onpopstate = function(event) { - console.log(event.state); - console.log(location); - }; - -这样在用户点击前进后退时也可以很好的监听url,来做相应的页面渲染。 - -若用户刷新了页面,但没有相应的页面资源,这时页面就会显示不存在。所以我认为较好的方法是在写`pushState()`第三个参数的时候,写为`?a=1`这样的参数形式。[History.js](https://github.com/browserstate/history.js) 也是这么写的。但是这样应该会多一次请求。也许使用 nodeJS 作为中间层会好一些吧。 - -对于上述的探索,不知道是不是我还不够深入,总觉得还是不够完美。 - -## 参考 - -* [MDN History](https://developer.mozilla.org/en-US/docs/Web/API/History) -* [MDN 操纵浏览器的历史记录](https://developer.mozilla.org/zh-CN/docs/DOM/Manipulating_the_browser_history) -* [pjax 是如何工作的? 知乎](https://www.zhihu.com/question/20289254) -* [PJAX的实现与应用 小胡子哥](http://www.cnblogs.com/hustskyking/p/history-api-in-html5.html) -* [URL的井号-阮一峰](http://www.ruanyifeng.com/blog/2011/03/url_hash.html) -* [history对象 JavaScript 标准参考教程(alpha) 阮一峰](http://javascript.ruanyifeng.com/bom/history.html) -* [Pjax(pushState and Ajax) 黯羽轻扬](http://www.ayqy.net/blog/pjaxpushstate-and-ajax/) -* [操纵历史,利用HTML5 History API实现无刷新跳转 蓝飞](http://www.clanfei.com/2012/09/1646.html) -* [前端:将网站打造成单页面应用SPA(一) Coffce](http://segmentfault.com/a/1190000002920768) -* [coffce-pjax](https://github.com/Coffcer/coffce-pjax) -* [History.js](https://github.com/browserstate/history.js) -* [defunkt/jquery-pjax GitHub](https://github.com/defunkt/jquery-pjax) -* [welefen/pjax](https://github.com/welefen/pjax) diff --git a/_posts/2016-03-12-jekyll-theme-version-2.0.md b/_posts/2016-03-12-jekyll-theme-version-2.0.md deleted file mode 100644 index e0ab5b0ffbd..00000000000 --- a/_posts/2016-03-12-jekyll-theme-version-2.0.md +++ /dev/null @@ -1,222 +0,0 @@ ---- -layout: post -title: "对这个 jekyll 博客主题的改版和重构" -date: 2016-03-12 11:40:18 +0800 -categories: jekyll -tags: jekyll 端口 markdown Foxit RubyGems HTML CSS -author: Haoyang Gao ---- - -* content -{:toc} - -本文主要说明对这个博客主题的改版和代码重构的过程。这个简洁高雅的博客主题受到了很多朋友的喜欢。在写第一版界面时,我对前端并不是很熟悉,对`Jekyll`也不熟悉。现在距离当时也一年了,对自己当时写的代码也不太满意了,同时`Jekyll`如今也已经升级了,目前最新版为3.1.2。因此我在临近毕业尚未入职前做一下博客主题的代码重构和改版吧。 - -主要想做这些事情有:添加归档,添加标签,添加分类页面,主页显示文章摘要,代码去除 jQuery 和 BootStrap,优化移动端显示,将所有变量写入配置文件`_config.yml`中等。再优化一些细节吧。希望更多人会喜欢。 - - - - - - -## 改版重构说明 - -* **使用 GitHub 风格的代码块 Markdown 写法 (Fenced code blocks)。** - - 即 GFM(github flavored markdown) 的方式。 - - Jekyll 已经升级至 3.1.2(2016-03),其中有一些新的要注意的地方,比如官网上说使用了 `Rouge` 去做代码高亮而不是默认的 `Pygments`,因为 `Jekyll` 本身是基于 Ruby 的,因此我看到官方说希望不再使用基于 Python 的 `Pygments` 了,而是都使用基于 Ruby 的代码。详情见官网升级说明 [syntax-highlighter-changed](https://jekyllrb.com/docs/upgrading/2-to-3/#syntax-highlighter-changed)。 -* **首页中添加摘要** - - 摘要可以在每一篇 md 文件头中使用 excerpt 属性写出来。也可以在正文中,4个换行符来分割,这个设置见配置文件`_config.yml`。 -* **添加归档** - - 上一版中没有归档,现在专门做了一个归档页面,当文章很多时方便根据年份快速查阅。 -* **添加标签** - - 标签还是很有必要添加的,上一版中也没有这个功能。现在也可以根据标签查找文章了。同时标签还有一个重要的作用是,用来获取相似文章的。 -* **添加分类页** - - 之前的分类就是在首页中直接完成的,现在和标签和归档类似,我将分类单独制作为一页,方便查阅。 -* **去掉 jQuery 和 BootStrap** - - 我觉得太重了,没必要使用这两个库,使用原生 JavaScript 和 CSS就可以做到一样的效果,代码量大大减轻,载入速度略有提高。 - -* **重写了demo页的瀑布流布局** - - 改变数据写死的方式,将数据用 json 格式录入,由 JavaScript 拼接为 HTML 代码。同时,使用 [Masonry](http://masonry.desandro.com/),重写了瀑布流布局。 - -* **简化评论配置,支持 多说 和 disqus** - - 在`_config.yml`中评论配置直接添加自己的`short_name`,评论就能正常使用了。 - -下面列举一些可能遇到的问题,至少我是遇到了: - -## RubyGems 无法访问,SSL 证书问题 - -以前我使用的是 RubyGems 的淘宝镜像[https://ruby.taobao.org/](https://ruby.taobao.org/)。现在这个镜像已经不再维护了,作者 [huacnlee (李华顺)](https://ruby-china.org/huacnlee) 转到 [Ruby China](https://ruby-china.org/) 中继续维护了,详情见 [RubyGems 镜像- Ruby China](https://gems.ruby-china.org/)。 - -### 错误呈现 - -在执行任何`gem`命令的时候出现以下错误: - -``` -ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://gems.ruby-china.org/specs.4.8.gz) -``` - -### 解决方法 - -根据 [https://gems.ruby-china.org/](https://gems.ruby-china.org/) 页面最下方提供的 GitHub Issue 地址。 - -可以进入这个 issue:[https://github.com/ruby-china/rubygems-mirror/issues/3](https://github.com/ruby-china/rubygems-mirror/issues/3) - -其中 sanlengjingvv 给出了一个链接地址 [https://gist.github.com/fnichol/867550](https://gist.github.com/fnichol/867550) 里面提供了方法。我就是采用这里面的方法解决的。 - -我使用的是 [The Manual Way](https://gist.github.com/fnichol/867550#the-manual-way-boring),因为 [The Ruby Way](https://gist.github.com/fnichol/867550#the-ruby-way-fun) 我没有成功,不知道什么原因,有兴趣的朋友可以试试。下面说说我的具体操作吧。 - -首先从 [https://curl.haxx.se/ca/cacert.pem](https://curl.haxx.se/ca/cacert.pem) 将文件`cacert.pem`下载至 `C:\RailsInstaller\cacert.pem` - -然后执行 - -``` -set SSL_CERT_FILE=C:\RailsInstaller\cacert.pem -``` - -就成功了,不会再出现 SSL 错误了。 - -最后原文中说,为了长久设置,将这个目录存入控制面板中。我没理解是什么意思,是指环境变量吗?有朋友知道的话,欢迎留言告知我。 - -我存入环境变量后,还是会出现 SSL 错误,这时再次执行上面那条命令即可。 - -## jekyll-paginate 依赖缺失 - -因为 jekyll 3 中默认安装已经没有这个分页组件了,官方把这个分页组件插件化了,因此要独立安装。详情见 [https://jekyllrb.com/docs/pagination/](https://jekyllrb.com/docs/pagination/)。 - -### 错误呈现 - -在启动 jekyll 服务的时候出现以下错误: - -``` -jekyll serve -Configuration file: c:/gitWorkSpace/blog-based-on-jekyll-3/_config.yml - Dependency Error: Yikes! It looks like you don't have jekyll-paginate or one of its dependencies installed. In order to use Jekyll as currently configured, you'll need to install this gem. The full error message from Ruby is: 'cannot load such file -- jekyll-paginate' If you run into trouble, you can find helpful resources at http://jekyllrb.com/help/! -jekyll 3.1.2 | Error: jekyll-paginate -``` - -### 解决方法 - -我们安装这个插件到本地即可。 - -``` -gem install jekyll-paginate -Fetching: jekyll-paginate-1.1.0.gem (100%) -Successfully installed jekyll-paginate-1.1.0 -Parsing documentation for jekyll-paginate-1.1.0 -Installing ri documentation for jekyll-paginate-1.1.0 -Done installing documentation for jekyll-paginate after 3 seconds -1 gem installed -``` - -## 被 Foxit pdf reader 占用4000端口 - -### 错误呈现 - -在本地使用命令 - -``` -jekyll serve -``` - -出现错误,如下 - -``` -jekyll serve -Configuration file: E:/GitWorkSpace/blog/_config.yml - Source: E:/GitWorkSpace/blog - Destination: E:/GitWorkSpace/blog/_site -Incremental build: disabled. Enable with --incremental - Generating... - done in 0.547 seconds. - Please add the following to your Gemfile to avoid polling for changes: - gem 'wdm', '>= 0.1.0' if Gem.win_platform? -Auto-regeneration: enabled for 'E:/GitWorkSpace/blog' -Configuration file: E:/GitWorkSpace/blog/_config.yml -jekyll 3.1.1 | Error: Permission denied - bind(2) for 127.0.0.1:4000 -``` - -网上查阅后,这篇博文解决了我的问题。[谁占了我的端口 for Windows --By Liu Xia, ThoughtWorks Senior Consultant. .NET Expert](http://lxconan.github.io/2016/01/07/who-is-using-my-port/) - -上述报错主要原因是,jekyll 启动使用的4000端口被福昕pdf阅读器的自动更新进程占用了,关掉这个进程,jekyll在本地调试启动服务时就没有问题了。 - -### 解决方法 - -简单的解决方法是: - -输入命令,查看各端口被占用情况 - -``` -netstat -ano -``` - -找到4000端口被占用的`PID` - -我的结果如下: - -``` -协议 本地地址 外部地址 状态 PID -TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 4 -TCP 0.0.0.0:135 0.0.0.0:0 LISTENING 836 -TCP 0.0.0.0:445 0.0.0.0:0 LISTENING 4 -TCP 0.0.0.0:1801 0.0.0.0:0 LISTENING 2312 -TCP 0.0.0.0:2103 0.0.0.0:0 LISTENING 2312 -TCP 0.0.0.0:2105 0.0.0.0:0 LISTENING 2312 -TCP 0.0.0.0:2107 0.0.0.0:0 LISTENING 2312 -TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING 2404 -TCP 0.0.0.0:3389 0.0.0.0:0 LISTENING 1172 -TCP 0.0.0.0:49664 0.0.0.0:0 LISTENING 584 -TCP 0.0.0.0:49665 0.0.0.0:0 LISTENING 1072 -TCP 0.0.0.0:49666 0.0.0.0:0 LISTENING 460 -TCP 0.0.0.0:49667 0.0.0.0:0 LISTENING 1000 -TCP 0.0.0.0:49670 0.0.0.0:0 LISTENING 696 -TCP 0.0.0.0:49678 0.0.0.0:0 LISTENING 2312 -TCP 0.0.0.0:49692 0.0.0.0:0 LISTENING 688 -TCP 127.0.0.1:4000 0.0.0.0:0 LISTENING 2476 -TCP 127.0.0.1:4000 127.0.0.1:55160 ESTABLISHED 2476 -TCP 127.0.0.1:4012 0.0.0.0:0 LISTENING 12724 -``` - -可以看到4000端口的PID是2476。下面查看是什么进程,命令行中输入: - -``` -tasklist /svc /FI "PID eq 2476" -``` - -得到结果: - -``` -映像名称 PID 服务 -========================= ======== ============================================ -FoxitProtect.exe 2476 FxService -``` - -可以看到正是福昕阅读器。下面关掉这个服务就好了。在 win10 中进入任务管理器,选择服务选项卡,关闭这个服务就好了,如下图: - -![](http://ww4.sinaimg.cn/large/7011d6cfjw1f1ty28wwj4j20g00aiju7.jpg) - -当然也可以在启动jekyll服务的时候指定端口号,如下: - -``` -jekyll serve --port 3000 -``` - -这样在浏览器中输入 http://localhost:3000/ 就可以访问了。 - -还可以在配置文件`_config.yml`中添加端口号设置(参考[官网文档-Serve Command OptionsPermalink](https://jekyllrb.com/docs/configuration/#serve-command-options)),如下: - -``` -# port -port: 1234 -``` - -此时,启动jekyll服务后,访问 http://localhost:1234/ 即可 diff --git a/_posts/2016-05-06-regular-expression-group.md b/_posts/2016-05-06-regular-expression-group.md deleted file mode 100644 index 572d53bcfd3..00000000000 --- a/_posts/2016-05-06-regular-expression-group.md +++ /dev/null @@ -1,50 +0,0 @@ ---- -layout: post -title: "浅谈正则表达式中的分组和引用" -date: 2016-05-06 11:40:18 +0800 -categories: JavaScript -tags: 正则 分组 Regular ---- - -* content -{:toc} - -由正则表达式如何匹配相同字符出发,讲讲正则表达式中的选择、分组和引用。 - -## 问题 - -在外刊君读者群中看到有人提出这样的一个需求: - -> 把字符串切成连续相同字符的正则怎么写?比如`abbcccdddd`切成`a,bb,ccc,dddd` - -之前我对正则表达式也是略有研究,想尝试一下。其实我对正则表达式的学习基本完全来源于犀牛书的第10章,真正看懂这一章,我觉得操作正则表达式应该不在话下。 - - - - - -## 我的答案 - -先给出我的答案吧: - -```js -'abbccddd'.match(/(\w)\1*/g) // ["a", "bb", "cc", "ddd"] -``` - -## 说明 - - -拿到这个问题,首先要匹配字符`[a-zA-Z0-9]`,这里直接使用`\w`。然后是全局匹配,在最后加上`g`。难点在于怎么判断重复。 - -翻看了犀牛书后,又读了一遍分组和引用的部分。使用小括号`()`将字符作为一个最小单元,同时小括号还能记忆这个组合相匹配的字符串。再使用反斜杠`\`引用前面分组的表达式,数字1表示第一个小括号。这时完成了2个字符重复的要求。最后再使用`*`来匹配出现0次或n次。这个正则表达式就写完了。 - -下面详细说说分组和引用。 - -**正则表达式的选择、分组和引用字符表** - -字符 | 含义 ---- | --- -`|` | 选择,匹配的是该符号左边的子表达式或右边的子表达式 -`(...)` | 组合,将几个项组合为一个单元,这个单元可通过`*` `+` `?` `|` 等符号加以修饰,**而且可以记住和这个组合相匹配的字符串以提供伺候的引用使用** -`(?:...)` | 只组合,把项组合到一个段元,但不记忆与该组相匹配的字符 -`\n` | 和第n个分组第一次匹配的字符相匹配,组是圆括号中的子表达式(也有可能是嵌套的),组索引是从左到右的左括号数,`(?:`形式的分组不编码 diff --git a/_posts/2016-06-07-JavaScript-good-parts-note1.md b/_posts/2016-06-07-JavaScript-good-parts-note1.md deleted file mode 100644 index 75a45257c75..00000000000 --- a/_posts/2016-06-07-JavaScript-good-parts-note1.md +++ /dev/null @@ -1,569 +0,0 @@ ---- -layout: post -title: "JavaScript 语言精粹笔记1-语法、对象、函数" -categories: JavaScript -tags: 对象 函数 this 闭包 面向对象 作用域 ---- - -* content -{:toc} - -记录一下阅读蝴蝶书的笔记,本篇为第一部分包含书中前三章内容:语法、对象和函数。 - - - - -![](https://img3.doubanio.com/lpic/s3651235.jpg) - -原书中第一章为精华,做了一些周边介绍,略去。 - -## 语法 - -### 空白 - -这里说一下JavaScript的注释,一种是 `/* */` 包围的块注释,另一种是 `//` 开头的行注释。 - -因为块注释的字符可能是JavaScript中正则表达式字面量,因此不是很安全,如: - -```js -/* - var rm_a = /a*/.match(s) -*/ -``` - -### 标识符 - -标识符由一个字母开头,后面可选择性的加上一个或多个字母、数字或下划线。要避免保留字。 - -标识符被用于语句、变量、参数、属性名、运算符和标记。 - -### 数字 - -可以存在指数部分,100和1e2完全相等 - -```js -100 === 1e2 // true -``` - -使用`isNaN`来检测`NaN`。 - -### 字符串 - -当年 JavaScript 被创建的时候,Unicode 是16位字符集,因此 JavaScript 字符串是16位的。 - -用双引号或单引号包裹。 - -重点说一下转义字符`\` - -反斜杠后面可以跟`"`, `'`, `\`, `/`, `b` (backspace), `f` (formfeed), `n`, `r` (carriage return), `t`, `u1234` - -```js -'A' === '\u0041' // true -``` - -### 语句 - -每个`