-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
804 lines (470 loc) · 60.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Steven叔叔's Blog</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description">
<meta property="og:type" content="website">
<meta property="og:title" content="Steven叔叔's Blog">
<meta property="og:url" content="http://yoursite.com/index.html">
<meta property="og:site_name" content="Steven叔叔's Blog">
<meta property="og:description">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Steven叔叔's Blog">
<meta name="twitter:description">
<link rel="alternative" href="/atom.xml" title="Steven叔叔's Blog" type="application/atom+xml">
<link rel="icon" href="/favicon.png">
<link rel="stylesheet" href="/css/style.css" type="text/css">
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
</head>
<body>
<div id="container">
<div class="left-col">
<div class="overlay"></div>
<div class="intrude-less">
<header id="header" class="inner">
<a href="/" class="profilepic">
<img lazy-src="/img/newbie.png" class="js-avatar">
</a>
<hgroup>
<h1 class="header-author"><a href="/">Steven叔叔</a></h1>
</hgroup>
<div class="switch-btn">
<div class="icon">
<div class="icon-ctn">
<div class="icon-wrap icon-house" data-idx="0">
<div class="birdhouse"></div>
<div class="birdhouse_holes"></div>
</div>
<div class="icon-wrap icon-ribbon hide" data-idx="1">
<div class="ribbon"></div>
</div>
<div class="icon-wrap icon-me hide" data-idx="3">
<div class="user"></div>
<div class="shoulder"></div>
</div>
</div>
</div>
<div class="tips-box hide">
<div class="tips-arrow"></div>
<ul class="tips-inner">
<li>菜单</li>
<li>标签</li>
<li>关于我</li>
</ul>
</div>
</div>
<div class="switch-area">
<div class="switch-wrap">
<section class="switch-part switch-part1">
<nav class="header-menu">
<ul>
<li><a href="/">主页</a></li>
<li><a href="/archives">所有文章</a></li>
</ul>
</nav>
<nav class="header-nav">
<div class="social">
</div>
</nav>
</section>
<section class="switch-part switch-part2">
<div class="widget tagcloud" id="js-tagcloud">
</div>
</section>
<section class="switch-part switch-part3">
<div id="js-aboutme">我是前端工程师, 我现在在做前端</div>
</section>
</div>
</div>
</header>
</div>
</div>
<div class="mid-col">
<nav id="mobile-nav">
<div class="overlay">
<div class="slider-trigger"></div>
<h1 class="header-author js-mobile-header hide">Steven叔叔</h1>
</div>
<div class="intrude-less">
<header id="header" class="inner">
<div class="profilepic">
<img lazy-src="/img/newbie.png" class="js-avatar">
</div>
<hgroup>
<h1 class="header-author">Steven叔叔</h1>
</hgroup>
<nav class="header-menu">
<ul>
<li><a href="/">主页</a></li>
<li><a href="/archives">所有文章</a></li>
<div class="clearfix"></div>
</ul>
</nav>
<nav class="header-nav">
<div class="social">
</div>
</nav>
</header>
</div>
</nav>
<div class="body-wrap">
<article id="post-shadowsocks-guideline" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2015/06/13/shadowsocks-guideline/" class="article-date">
<time datetime="2015-06-13T01:34:04.000Z" itemprop="datePublished">2015-06-13</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2015/06/13/shadowsocks-guideline/">DigitalOcean Shadowsocks的用户管理系统</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<p>购买的<a href="https://www.digitalocean.com/?refcode=4d886bce0718" target="_blank" rel="external">digitalocean</a>(简称:DO)的VPS除了放置闲置的网站和偶尔翻翻墙之外,其实总体利用率还是很低。有一个电脑小白的朋友,说他想用google找图片,但不知道怎么用google。最近测试并整理了digitalocean部署shadowsocks的管理系统ss-panel的东西,供大家学习参考。</p>
<h2 id="安装步骤">安装步骤</h2><h3 id="安装lnmp">安装lnmp</h3><p>安装<a href="http://lnmp.org" target="_blank" rel="external">lnmp</a>步骤很简单,直接follow官方教程指引基本就可以了。但是需要注意的是lnmp自带的php版本为5.3,需要在线升级到5.4之后ss-panel才能用。</p>
<h3 id="安装shadowsocks_manyuser">安装shadowsocks manyuser</h3><p>注意<a href="https://github.com/mengskysama/shadowsocks" target="_blank" rel="external">shadowsocks manyuser</a>运行时时没有并没有完全读config.json的所有配置项,服务端口和密码都是直接读数据库. 如果要修改只能直接改数据库,稍微有点麻烦。</p>
<h3 id="安装ss-panel">安装ss-panel</h3><p><a href="https://github.com/orvice/ss-panel" target="_blank" rel="external">ss-panel</a>只是针对Shadows Manyuser的前端程序,所以2者实际上的数据库是同一个库(假设场景是前端和后端都是同一台机器)</p>
<h3 id="关于ss-panel多节点">关于ss-panel多节点</h3><p>这里我还没去测试,具体的概念就是部署了多个shadowsocks后端程序,然后通过与前端程序共享一个数据库实现。也就是说,mysql需要开放远程连接的方式给所有的后端节点访问。</p>
<h3 id="关于DO节点问题">关于DO节点问题</h3><p>看到很多人吐槽DO节点SSH延迟问题,我之前是用了NY(纽约)节点,SSH很卡,youtube也不顺畅。更不用说1080P了。目前已经转移了加州节点,测试youtube设置720p基本顺畅,1080p还是稍微有点卡。</p>
<h3 id="关于跑满带宽的传说">关于跑满带宽的传说</h3><p>这么好的事情并没发生在我身上。并已经按照网上的说法用了<a href="http://bbs.tcp.hk/thread-41-1-1.html" target="_blank" rel="external">my.serverspeeder.com</a>进行加速。测试分别对比了speedtest.net,youtube.也尝试更换了新加坡的节点,新加坡节点确实可以达到100ms不到的ping值,但就是不太稳定。慢的时候也要300-400ms. 下载速度也没太多的优势,而且serverspeeder加速在新加坡节点下载速度更慢,很奇怪。更有网上其他人说修改ss加密方式对速度也有提升。我也对比了rd4-md5, bf-cfb, aes-256-cfb。感觉速度变化差异不大。我自己安装的宽带是长宽10M. 没对比过电信的速度如何。</p>
<p>如果大家对digitalocean VPS感兴趣,可以点击<a href="https://www.digitalocean.com/?refcode=4d886bce0718" target="_blank" rel="external">https://www.digitalocean.com/?refcode=4d886bce0718</a>进行购买,可以获得10刀,digitalocean最低配置是每月5刀,相当于免费使用2个月。如果大家有使用上的问题,欢迎邮箱<a href="mailto:chaohuang.hong@gmail.com">chaohuang.hong@gmail.com</a>留言给我。</p>
</div>
<div class="article-info article-info-index">
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-css_priority_overwrite" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2015/06/07/css_priority_overwrite/" class="article-date">
<time datetime="2015-06-07T05:47:01.000Z" itemprop="datePublished">2015-06-07</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2015/06/07/css_priority_overwrite/">CSS优先级覆盖问题</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<p>一般来说,CSS优先级覆盖有以下几个概念:</p>
<ul>
<li>!important 重要性</li>
<li>默认继承</li>
<li>优先级计算</li>
</ul>
<h2 id="!important_(重要性)">!important (重要性)</h2><p>!important默认的权重最高,会覆盖其他所有属性. 而且!important属性会无视默认CSS的权重问题,即权重相同后面的会覆盖前面定义的CSS样式<br><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">p</span> <span class="rules">{</span><br><span class="line"> <span class="rule"><span class="attribute">color</span>:<span class="value"> black <span class="important">!important</span></span></span>; <span class="rule">//权重最高</span><br><span class="line">}</span></span> </span><br><span class="line"></span><br><span class="line"><span class="tag">p</span> <span class="rules">{</span><br><span class="line"> <span class="rule"><span class="attribute">color</span>:<span class="value"> red</span></span>;</span><br><span class="line"><span class="rule">}</span></span></span><br></pre></td></tr></table></figure></p>
<h2 id="默认继承">默认继承</h2><p>例如color, font这些属性,父元素的颜色影响子元素是有用的,避免大规模定义,可以提供效率。但类似margin, padding这些CSS是默认不继承父元素,但也提供了以下的方法实现继承:<br><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">aside</span> <span class="rules">{</span><br><span class="line"> <span class="rule"><span class="attribute">margin</span>:<span class="value"> <span class="number">10px</span></span></span>;</span><br><span class="line"><span class="rule">}</span></span></span><br><span class="line"></span><br><span class="line"><span class="tag">aside</span> <span class="tag">section</span> <span class="rules">{</span><br><span class="line"> <span class="rule"><span class="attribute">margin</span>:<span class="value"> inherit</span></span>;</span><br><span class="line"><span class="rule">}</span></span></span><br></pre></td></tr></table></figure></p>
<p>与inherit相对的值是initial. 表示取消继承. (?怎么用?)</p>
<h3 id="通用选择器">通用选择器</h3><h2 id="优先级计算">优先级计算</h2><p>牢记:ID选择器比任意数量的class, 属性或元素选择器要高.<br>用a, b, c, d 代表优先级依次递减。计算公式:</p>
<ul>
<li>a 如果style属性定义的声明,则为1,否则为0;</li>
<li>b 等于id选择器的数目</li>
<li>c 等于属性选择器,class和伪class的数量</li>
<li>d 等于元素名和伪元素的数目</li>
</ul>
<p>以下权重为0,0,1,3(a = 0, b = 0, c = 1, d = 3)<br><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">article</span> <span class="tag">section</span> <span class="tag">h1</span><span class="class">.title</span> <span class="rules">{</span><br><span class="line"> </span><br><span class="line"><span class="rule">}</span></span></span><br></pre></td></tr></table></figure></p>
<p>以下权重为0,1,0,0<br><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><section style="padding-bottom: 10px;"></span><br><span class="line"></section></span><br></pre></td></tr></table></figure></p>
<h3 id="命名空间">命名空间</h3><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">h2</span> <span class="rules">{</span><br><span class="line"> <span class="rule"><span class="attribute">font-size</span>:<span class="value"> <span class="number">24px</span></span></span>;</span><br><span class="line"><span class="rule">}</span></span></span><br><span class="line"></span><br><span class="line"><span class="class">.home</span> <span class="tag">h2</span> <span class="rules">{</span><br><span class="line"> <span class="rule"><span class="attribute">font-size</span>:<span class="value"> <span class="number">36px</span></span></span>;</span><br><span class="line"><span class="rule">}</span></span></span><br><span class="line"></span><br><span class="line"><span class="class">.home</span> <span class="tag">h2</span><span class="class">.hightlight</span> <span class="rules">{</span><br><span class="line"> <span class="rule"><span class="attribute">font-size</span>:<span class="value"> <span class="number">30px</span></span></span>;</span><br><span class="line"><span class="rule">}</span></span></span><br></pre></td></tr></table></figure>
<p>场景:主页定义了h2的字体大小, 子页面重新覆盖了主页面的h2字体大小,因为需求需要,又覆盖了子页面的h2字体大小。<br>这样会导致的问题就是css代码的层级层级越来越长,特别在用LESS/SASS不恰当使用下,这种情况会被大量的滥用。</p>
</div>
<div class="article-info article-info-index">
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-supervisor-manage-python" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2015/06/07/supervisor-manage-python/" class="article-date">
<time datetime="2015-06-07T00:21:29.000Z" itemprop="datePublished">2015-06-07</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2015/06/07/supervisor-manage-python/">使用Supervisor管理python进程</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<h2 id="安装">安装</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">yum install python-setuptools</span><br><span class="line">easy_install supervisor</span><br><span class="line">``` </span><br><span class="line"><span class="comment">## 检查安装是否成功</span></span><br><span class="line">``` bash</span><br><span class="line"><span class="built_in">echo</span>_supervisord_conf</span><br></pre></td></tr></table></figure>
<h2 id="创建配置文件">创建配置文件</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">echo</span>_supervisord_conf > /etc/supervisord.conf</span><br></pre></td></tr></table></figure>
<h2 id="新增进程启动项">新增进程启动项</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[program:shadowsocks]</span><br><span class="line"><span class="built_in">command</span>=python <PATH>/server.py -c <PATH>/config.json</span><br></pre></td></tr></table></figure>
<h2 id="运行">运行</h2><pre><code class="bash">supervisord //启动
supervisorctl //打开命令行
</code></pre>
<p>注意修改conf文件之后用调用supervisorctl reload, 配置文件才能生效</p>
</div>
<div class="article-info article-info-index">
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-SMACSS-guideline" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2015/06/04/SMACSS-guideline/" class="article-date">
<time datetime="2015-06-03T23:19:50.000Z" itemprop="datePublished">2015-06-04</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2015/06/04/SMACSS-guideline/">SMACSS CSS指引</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<p>SMACSS 全称为 Scalable Modular Architecture CSS. 即可扩展模块化结构CSS. </p>
<h1 id="分类规则(SMACSS核心):">分类规则(SMACSS核心):</h1><ul>
<li>Base</li>
<li>Layout</li>
<li>Module</li>
<li>State</li>
<li>Theme</li>
</ul>
<h1 id="Base_Rules_-_基本规则">Base Rules - 基本规则</h1><p>主要应用于元素选择器,后代选择器,子选择器,伪类. 不包括ID或类选择器. </p>
<h2 id="CSS_Resets">CSS Resets</h2><h1 id="Layout_Rules_-_布局规则">Layout Rules - 布局规则</h1><p>唯一主要使用ID选择器(JS Hook)</p>
<h1 id="Module_Rules_-_模块规则">Module Rules - 模块规则</h1><p>页面的”肉”,每一个模块都应该设计成独立的组件,让页面更加灵活。模块可以在页面不同部分简单移动而不会破坏布局。<br>避免使用ID或元素选择器</p>
<h2 id="避免元素选择器">避免元素选择器</h2><p>使用元素的子选择器或后代选择器需要保证元素选择器的可预见性。<br>只加入有语义的选择器。<br>如果希望使用,应该限制在一层类选择器里面。</p>
</div>
<div class="article-info article-info-index">
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-oocss-main-principle" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2015/05/18/oocss-main-principle/" class="article-date">
<time datetime="2015-05-17T16:03:55.000Z" itemprop="datePublished">2015-05-18</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2015/05/18/oocss-main-principle/">2个主要的OOCSS原则</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<h1 id="把容器的内容分离">把容器的内容分离</h1><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="class">.module</span> <span class="rules">{</span><br><span class="line"> <span class="rule"><span class="attribute">margin</span>:<span class="value"> <span class="number">10px</span></span></span>;</span><br><span class="line"><span class="rule">}</span></span></span><br><span class="line"></span><br><span class="line"><span class="class">.hd</span> <span class="rules">{</span><br><span class="line"> <span class="rule"><span class="attribute">padding</span>:<span class="value"> <span class="number">5px</span></span></span>;</span><br><span class="line"> <span class="rule"><span class="attribute">color</span>:<span class="value"> <span class="hexcolor">#333</span></span></span>;</span><br><span class="line"><span class="rule">}</span></span></span><br></pre></td></tr></table></figure>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="title">div</span> <span class="attribute">class</span>=<span class="value">"module"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">h1</span> <span class="attribute">class</span>=<span class="value">"hd"</span>></span>title<span class="tag"></<span class="title">h1</span>></span></span><br><span class="line"><span class="tag"></<span class="title">div</span>></span></span><br></pre></td></tr></table></figure>
<h1 id="元素的结构的规则和皮肤应该分开">元素的结构的规则和皮肤应该分开</h1><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="class">.module</span> <span class="rules">{</span><br><span class="line"> <span class="rule"><span class="attribute">margin</span>:<span class="value"> <span class="number">10px</span></span></span>;</span><br><span class="line"><span class="rule">}</span></span></span><br><span class="line"></span><br><span class="line"><span class="class">.module-sale</span> <span class="rules">{</span><br><span class="line"> <span class="rule"><span class="attribute">background</span>:<span class="value"> <span class="hexcolor">#efefef</span></span></span>;</span><br><span class="line"><span class="rule">}</span></span></span><br></pre></td></tr></table></figure>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="title">div</span> <span class="attribute">class</span>=<span class="value">"module module-sale"</span>></span></span><br><span class="line"> ...</span><br><span class="line"><span class="tag"></<span class="title">div</span>></span></span><br></pre></td></tr></table></figure>
</div>
<div class="article-info article-info-index">
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-javascript-design-pattern" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2015/05/17/javascript-design-pattern/" class="article-date">
<time datetime="2015-05-17T14:15:59.000Z" itemprop="datePublished">2015-05-17</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2015/05/17/javascript-design-pattern/">Javascript 设计模式读书笔记</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<p>一直很喜欢前端界的大牛addyosmani,趁着假期拜读了他的Javascript设计模式<a href="http://addyosmani.com/resources/essentialjsdesignpatterns/book" target="_blank" rel="external">Learning Javascript Design Patterns</a>。这篇文章主要作为个人在javascript底层知识的学习记录和笔记。其实今年来陆陆续续有在关注和看一下国外的书籍及前沿的技术内容,但确实是感觉自己的英文有点菜,看不懂的内容很多,尤其是对于长句子的解读更加弱爆。这方面的动力主要是工作压力原因和个人的意愿,以我目前的知识结构感觉很难让自己及整个团队再上一个台阶。</p>
<h1 id="什么是设计模式">什么是设计模式</h1><h2 id="设计模式3个最主要的好处:">设计模式3个最主要的好处:</h2><ul>
<li>被验证的解决方案</li>
<li>能够被重用</li>
<li>富有表现张力</li>
</ul>
<h1 id="反模式">反模式</h1><ul>
<li>定义大量的全局变量</li>
<li>使用setTimeout或setInterval内部用eval触发的字符串<br>错误用法<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">setTimeout(<span class="string">"myFunc()"</span>, <span class="number">1000</span>);</span><br><span class="line">setTimeout(<span class="string">"myFunc(1,2,3)"</span>, <span class="number">1000</span>);</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>正确用法<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">setTimeout(myFunc, <span class="number">1000</span>);</span><br><span class="line">setTimeout(<span class="function"><span class="keyword">function</span> <span class="params">()</span> </span>{</span><br><span class="line"> myFunc(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>);</span><br><span class="line">});</span><br></pre></td></tr></table></figure></p>
<ul>
<li>修改JS原生的对象原型</li>
<li>直接在一行里面写JS代码</li>
<li>使用document.createElement替代document.write</li>
</ul>
<h1 id="设计模式分类">设计模式分类</h1><h2 id="创建型设计模式">创建型设计模式</h2><p>集中处理对象创建机制,控制创建过程<br>Constructor, Factory, Abstract, Prototype, Singleton, Builder.</p>
<h2 id="结构设计模式">结构设计模式</h2><p>关注对象构成及定义简单的方式实现不同对象的关系<br>Decorator, Facade, Flyweight, Adapter, Proxy</p>
<h2 id="行为设计模式">行为设计模式</h2><p>改进或提高系统里不同对象的通讯<br>Iterator, Mediator, Observer, Visitor.</p>
<h1 id="JS设计模式">JS设计模式</h1><h2 id="原生的对象">原生的对象</h2><p>这里看到有些中文书籍硬生生地把Object literal notation翻译成对象字面量,感觉非常地奇怪。个人更愿意把它叫做Javascript原生对象。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> myObject = {</span><br><span class="line"> key: <span class="string">'value'</span>;</span><br><span class="line"> func: <span class="function"><span class="keyword">function</span><span class="params">()</span> </span>{</span><br><span class="line"> <span class="comment">// ...</span></span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line">myObject.key2 = <span class="string">'new value'</span>;</span><br></pre></td></tr></table></figure></p>
<h2 id="模块模式(Module_Pattern)">模块模式(Module Pattern)</h2><p>模块模式一般是着重于类公有/私有的封装,在Javascript里模块是用一个包含着公有/私有方法和变量的简单对象来模拟。模块模式的封装主要是用闭包,保证只返回公有方法,其他内容保存在闭包里面。<br>这里还有一个叫IIFE的概念。全称是immediately-invoked functional expression. 立即调用函数表达式。通过IIFE实现闭包。Javascript不像传统的其他面向对象语言拥有公有/私有变量的语法,所以通过函数作用域来模拟,除了在返回对象里面定义的方法和变量对外公开,其他变量和方法都属于模块自己私有。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> testModule = <span class="function"><span class="keyword">function</span><span class="params">()</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="keyword">var</span> counter = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> { </span><br><span class="line"> incrementCounter: <span class="function"><span class="keyword">function</span><span class="params">()</span> </span>{</span><br><span class="line"> <span class="keyword">return</span> counter++;</span><br><span class="line"> },</span><br><span class="line"></span><br><span class="line"> resetCounter: <span class="function"><span class="keyword">function</span><span class="params">()</span> </span>{</span><br><span class="line"> counter = <span class="number">0</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">})();</span><br></pre></td></tr></table></figure></p>
<h2 id="模块暴露模式(The_Revealing_Module_Pattern)">模块暴露模式(The Revealing Module Pattern)</h2><p>模块暴露模式其实是做为模块模式的补充,这里这个翻译不知道是不是最合适的。这种js的写法现在已经被大规模的推广,个人感觉比较好的地方就是在代码尾段的返回对象就可以对这个模块对外的接口一目了然。当然这种情况也更多的使用在类似一些until工具类上。但书里提到的关于2者的区别其实界限我没看得太明白,在此暂时搁下再议。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> revealModule = (<span class="function"><span class="keyword">function</span><span class="params">()</span> </span>{</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">var</span> privateVar = <span class="string">'real module'</span>,</span><br><span class="line"> publicVar = <span class="string">'hello'</span>;</span><br><span class="line"> </span><br><span class="line"> <span class="function"><span class="keyword">function</span> <span class="title">privateDisplay</span><span class="params">()</span> </span>{</span><br><span class="line"> <span class="built_in">console</span>.log(<span class="string">'my name:'</span> + privateVar);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">function</span> <span class="title">publicSetName</span><span class="params">(name)</span> </span>{</span><br><span class="line"> privateVar = name;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">function</span> <span class="title">publicGetName</span><span class="params">()</span> </span>{</span><br><span class="line"> <span class="keyword">return</span> privateDisplay();</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> setName: publicSetName,</span><br><span class="line"> getName: publicGetName,</span><br><span class="line"> greeting: publicVar,</span><br><span class="line"> }</span><br><span class="line">})();</span><br></pre></td></tr></table></figure></p>
<h2 id="单例模式">单例模式</h2><p>例子<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> mySingleton = (<span class="function"><span class="keyword">function</span><span class="params">()</span> </span>{</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">var</span> instance;</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">function</span> <span class="title">init</span><span class="params">()</span> </span>{</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> publicMethod: <span class="function"><span class="keyword">function</span><span class="params">()</span> </span>{</span><br><span class="line"> <span class="built_in">console</span>.log(<span class="string">'singleton'</span>);</span><br><span class="line"> }</span><br><span class="line"> };</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> getInstance: <span class="function"><span class="keyword">function</span><span class="params">()</span> </span>{</span><br><span class="line"> <span class="keyword">if</span> (!instance) {</span><br><span class="line"> instance = init();</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> instacne;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">})();</span><br><span class="line">mySingleton.getInstance().publicMethod();</span><br></pre></td></tr></table></figure></p>
<h2 id="观察者模式">观察者模式</h2><p>目前比较流行的Publish/Subscribe模式,<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> pubsub = {};</span><br><span class="line">(<span class="function"><span class="keyword">function</span> <span class="params">(q)</span> </span>{</span><br><span class="line"> <span class="keyword">var</span> topis = {},</span><br><span class="line"> subUid = -<span class="number">1</span>;</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 事件广播(主题名和参数)</span></span><br><span class="line"> q.publish = <span class="function"><span class="keyword">function</span> <span class="params">(topic, args)</span> </span>{</span><br><span class="line"> <span class="keyword">if</span> (!topics[topic]) {</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">var</span> subscribers = topics[topic],</span><br><span class="line"> len = subscribers ? subscribers.length : <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">while</span> (len--) {</span><br><span class="line"> subscribers[len].func(topic, args);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">this</span>;</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="comment">// 订阅事件(主题名和回调函数)</span></span><br><span class="line"> q.suscribe = <span class="function"><span class="keyword">function</span> <span class="params">(topic, func)</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (!topic[topic]) {</span><br><span class="line"> topics[topic] = [];</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">var</span> token = (++subUid).toString();</span><br><span class="line"> topics[topic].push({</span><br><span class="line"> token: token,</span><br><span class="line"> func: func</span><br><span class="line"> });</span><br><span class="line"> <span class="keyword">return</span> token;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> q.unsubscribe = <span class="function"><span class="keyword">function</span> <span class="params">(token)</span> </span>{</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> m <span class="keyword">in</span> topics) {</span><br><span class="line"> <span class="keyword">if</span> (topics[m]) {</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>, j = topics[m].length; i < j; i++) {</span><br><span class="line"> <span class="keyword">if</span> (topics[m][i].token == token) {</span><br><span class="line"> topics[m].splice(i, <span class="number">1</span>);</span><br><span class="line"> <span class="keyword">return</span> token;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">this</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">}(pubsub));</span><br></pre></td></tr></table></figure></p>
<h2 id="中介者模式">中介者模式</h2><h2 id="指令模式">指令模式</h2>
</div>
<div class="article-info article-info-index">
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-Sublime-text-general-config" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2015/05/02/Sublime-text-general-config/" class="article-date">
<time datetime="2015-05-02T03:27:34.000Z" itemprop="datePublished">2015-05-02</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2015/05/02/Sublime-text-general-config/">常用Sublime Text配置及使用技巧</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<p>转Mac OS的工作环境开始有一段时间了,需要一款类似Windows下类似Editplus或Ultradit的工具,作为IDEA下文本编辑或简单代码的轻量IDE补充工具。由于不想折腾VIM类似的工具,所以选择了Sublime Text做为首选工具。这里主要记录Sublime Text的配置及技巧以便平时使用。另一方面不得不感叹社区的成熟,所有工具应有尽有。</p>
<h2 id="配置类">配置类</h2><p>Sublime Text的配置分为系统级(Default)和用户级(User). 用户级默认覆盖系统级的配置。所以这里不建议去修改系统级的配置, 一方面是改错了忘记备份对原文件的破坏,另一方面是不方便查找比较。<br>打开<strong>Preferences</strong>-><strong>Settings - User</strong><br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">{</span><br><span class="line"> ... ...</span><br><span class="line"> <span class="string">"translate_tabs_to_spaces"</span>: <span class="literal">true</span>, // 默认将tab转换为空格</span><br><span class="line"> <span class="string">"scroll_past_end"</span>: <span class="literal">true</span>, // 当文件到末尾时还能继续滚动</span><br><span class="line">}</span><br></pre></td></tr></table></figure></p>
<h2 id="快捷键">快捷键</h2><ul>
<li>Command + L: 选择当前行</li>
<li>Command + D: 选择当前单词</li>
<li>Command + Shift + L: 向前/后选择全部</li>
<li>Command + X: 删除当前行</li>
<li>Command + Shift + P: 打开命令面板</li>
</ul>
<p>更多快捷键参考<a href="http://sublime-text-unofficial-documentation.readthedocs.org/en/latest/reference/keyboard_shortcuts_osx.html" target="_blank" rel="external">Keyboard Shortcuts - OSX</a></p>
<h2 id="插件类">插件类</h2><h3 id="JsFormat">JsFormat</h3><p>使用方法:直接打开一个js文件,按Command + Shift + P, 搜索format回车。</p>
<h3 id="Emmet"><a href="http://emmet.io" target="_blank" rel="external">Emmet</a></h3><p>著名的快速编写前端代码工具</p>
<h3 id="liveReload">liveReload</h3><p>编辑代码时配合浏览器自动刷新效果。</p>
</div>
<div class="article-info article-info-index">
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-Sublime-text-mac-markdown" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2015/05/02/Sublime-text-mac-markdown/" class="article-date">
<time datetime="2015-05-02T01:48:29.000Z" itemprop="datePublished">2015-05-02</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2015/05/02/Sublime-text-mac-markdown/">用Sublime Text打造mac下的markdown编辑器</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<p>为了结合hexo在Mac下更好编辑.md文件,目前选用了Sublime Text2编辑器加markdown插件的方式作为默认MD编辑工具</p>
<hr>
<h2 id="安装_Package_Control">安装 Package Control</h2><p>输入快捷键 Ctrl + ` 进入命令行<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">import urllib2,os; pf=<span class="string">'Package Control.sublime-package'</span>; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) <span class="keyword">if</span> not os.path.exists(ipp) <span class="keyword">else</span> None; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler( ))); open( os.path.join( ipp, pf), <span class="string">'wb'</span> ).write( urllib2.urlopen( <span class="string">'http://sublime.wbond.net/'</span> +pf.replace( <span class="string">' '</span>,<span class="string">'%20'</span> )).read()); <span class="built_in">print</span>( <span class="string">'Please restart Sublime Text to finish installation'</span>)</span><br></pre></td></tr></table></figure></p>
<p>安装后重启可以在<strong>Preferences -> Package Settings</strong>看到<strong>Package Control</strong>.</p>
<h2 id="安装_Markdown_Preview">安装 Markdown Preview</h2><p>输入Command + Shift + p 调出命令面板, 先搜索<strong>Install Package</strong>, 然后再搜索<strong>markdown preview</strong>,点击安装。</p>
<h3 id="定义快捷键">定义快捷键</h3><p><strong>Preferences -> Key Bindings User</strong><br>新增一行<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">{ <span class="string">"keys"</span>: [<span class="string">"alt+m"</span>], <span class="string">"command"</span>: <span class="string">"markdown_preview"</span>, <span class="string">"args"</span>: { <span class="string">"target"</span>: <span class="string">"browser"</span>}}</span><br></pre></td></tr></table></figure></p>
<p>定义alt + m 为 markdown 预览快捷键。</p>
<h3 id="设置语法高亮">设置语法高亮</h3><p><strong>Preferences ->Package Settings->Markdown Preview->Setting Default</strong>找到<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">... ...</span><br><span class="line"><span class="string">"enable_mathjax"</span>: <span class="literal">false</span>,</span><br><span class="line"><span class="string">"enable_highlight"</span>: <span class="literal">false</span></span><br></pre></td></tr></table></figure></p>
<p>将这2个值都改为true。但语法高亮似乎与选择的主题有关。我暂时选择了LAZY的Color Scheme. 中间也尝试了用了iTg,Monokai Extended等主题,都感觉不太理想。可能我自己比较喜欢白色的编辑界面。</p>
</div>
<div class="article-info article-info-index">
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-div-container-wrapper" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2015/05/01/div-container-wrapper/" class="article-date">
<time datetime="2015-05-01T02:55:26.000Z" itemprop="datePublished">2015-05-01</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2015/05/01/div-container-wrapper/">关于网页布局css的container和wrapper</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<p>平时在看网站页面源码的时候总会看到类似class=”container”或者class=”wrapper”类似的用法,为了解决自己的困惑,我搜索了一下相关的关键词,发现其实也有其他人有类似的疑问。<br>这里我找到一个个人比较认同的答案作为这个问题的解释。<br><a href="https://teamtreehouse.com/forum/div-containers-div-wrappers" target="_blank" rel="external">链接在此</a></p>
<hr>
<p>答案大概是这么写的:<br>A container or wrapper is a dummy div used for purposes of setting backgrounds, floats or padding on another div. Sometimes you need an parent div to get a block level element to do what you want, whether that’s simply setting a background or using margin: 0 auto to center a block. People just call them wrappers out of custom and also that it’s a very uncommon need for a class name. It means nothing technically.</p>
<p>也就是说,其实我们用container和wrapper作用差不多,使用场景是当我们需要统一控制块级元素的背景或布局居中时。这时候通过简单地为需要统一表现的块级元素加上一层div来实现控制。<br><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="title">div</span> <span class="attribute">class</span>=<span class="value">"header"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">div</span> <span class="attribute">class</span>=<span class="value">"container"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">ul</span> <span class="attribute">class</span>=<span class="value">"nav"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">li</span> <span class="attribute">class</span>=<span class="value">"nav-item"</span>></span><span class="tag"></<span class="title">li</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">li</span> <span class="attribute">class</span>=<span class="value">"nav-item"</span>></span><span class="tag"></<span class="title">li</span>></span></span><br><span class="line"> <span class="tag"></<span class="title">ul</span>></span></span><br><span class="line"> <span class="tag"></<span class="title">div</span>></span></span><br><span class="line"><span class="tag"></<span class="title">div</span>></span></span><br><span class="line"><span class="tag"><<span class="title">div</span> <span class="attribute">class</span>=<span class="value">"content"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">div</span> <span class="attribute">class</span>=<span class="value">"container"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">div</span> <span class="attribute">class</span>=<span class="value">"article"</span>></span></span><br><span class="line"> ... ...</span><br><span class="line"> <span class="tag"></<span class="title">div</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="tag"></<span class="title">div</span>></span></span><br><span class="line"><span class="tag"></<span class="title">div</span>></span></span><br></pre></td></tr></table></figure></p>
<pre><code class="css"><span class="class">.container</span> <span class="rules">{
<span class="rule"><span class="attribute">width</span>:<span class="value"> <span class="number">980px</span></span></span>;
<span class="rule"><span class="attribute">margin</span>:<span class="value"> <span class="number">0</span> auto</span></span>;
<span class="rule">}</span></span>
</code></pre>
</div>
<div class="article-info article-info-index">
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-hexo-github-blog" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2015/03/28/hexo-github-blog/" class="article-date">
<time datetime="2015-03-28T15:11:05.000Z" itemprop="datePublished">2015-03-28</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2015/03/28/hexo-github-blog/">Hexo + GitHub 搭建个人博客</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<p>这篇文章主要作为自己折腾Hexo搭建自己个人博客的体验及记录。其实Hexo部署远没有想得那么简单,中间自己前后折腾了2个多小时。可能自己对于整个环境和概念半桶水的原因,另外一方面网上这方面的资料也很多了,Google了可以抓到一把。这里不细说,只是结合自己的实际情况来记录。</p>
<hr>
<h2 id="背景知识">背景知识</h2><h3 id="为什么选择Hexo">为什么选择Hexo</h3><p>我的需求是纯静态,轻量,部署简单,不需要数据库,并能支持markdown。<br>本来想选用jekyll,不过本地执行第一条安装指令总是提示服务器超时。无奈之下选择了Hexo, 看过他的介绍, 基于nodejs, 安装和部署都比较小白,合适我这种想装B而又担心太麻烦的人。所以决定上Hexo的贼船。另外还有一个轻博客叫Octopress, 也是基于jekyll, 时间不允许,以后有时间再折腾。</p>
<h2 id="安装步骤">安装步骤</h2><p>安装Hexo前需要有nodejs的运行环境,可以先去nodejs的官网下载并安装。<br>Mac下直接下载binary的安装包(32bit和64bit)直接解压就可以运行了。<br>另外需要一个Github账号,并启用独立Github账号的Pages服务。其实就是相当于给你提供了一个二级域名的博客功能,而且每个用户只能有一个。</p>
<h3 id="安装Hexo">安装Hexo</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">npm install -g hexo</span><br><span class="line">hexo init</span><br><span class="line">npm install</span><br><span class="line">``` </span><br><span class="line"><span class="comment">### 本地部署Hexo</span></span><br><span class="line">``` bash</span><br><span class="line">hexo n <span class="string">'title'</span> 新建文章</span><br><span class="line">hexo g 生成文章</span><br><span class="line">hexo s 启动服务</span><br></pre></td></tr></table></figure>
<h3 id="GitHub设置SSH">GitHub设置SSH</h3><p>可以直接参考 <a href="http://www.jianshu.com/p/05289a4bc8b2" target="_blank" rel="external">如何搭建一个独立博客——简明Github Pages与Hexo教程</a>的[配置和使用Github小节]</p>
<h3 id="将本地的博客文章发布到GitHub">将本地的博客文章发布到GitHub</h3><p>修改本地hexo博客根目录的配置文件_config.yml<br>vi文件最后面的deploy加上<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">... ...</span><br><span class="line">deploy:</span><br><span class="line"> <span class="built_in">type</span>: git</span><br><span class="line"> respoitory: https://github.com/[yourname]/[yourname].github.io.git</span><br><span class="line"> branch: master</span><br></pre></td></tr></table></figure></p>
<p>这里有个特别要注意的地方,就是每个值后面冒号需要英文半角的空格。而且type的类型一定要是git。之前在其他文章里面说是用github,但是在hexo 3.0之后部署总是会提示unknown type。然后就是部署到GitHub上了。<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo d 部署服务</span><br></pre></td></tr></table></figure></p>
<p>这里是hexo比较赞的地方。</p>
<h2 id="实战升级">实战升级</h2><h3 id="更换Hexo主题">更换Hexo主题</h3><p>TODO:</p>
<h3 id="申请独立域名指向GitHub">申请独立域名指向GitHub</h3><p>TODO:</p>
</div>
<div class="article-info article-info-index">
<div class="clearfix"></div>
</div>
</div>
</article>
</div>
<footer id="footer">
<div class="outer">
<div id="footer-info">
<div class="footer-left">
© 2015 Steven叔叔
</div>
<div class="footer-right">
<a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/litten/hexo-theme-yilia" target="_blank">Yilia</a> by Litten
</div>
</div>
</div>
</footer>
</div>
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
<script src="/fancybox/jquery.fancybox.pack.js" type="text/javascript"></script>
<script src="/js/mobile.js" type="text/javascript"></script>
<script src="/js/main.js" type="text/javascript"></script>
<! -- mathjax config similar to math.stackexchange -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
processEscapes: true,
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
}
});
MathJax.Hub.Queue(function() {
var all = MathJax.Hub.getAllJax(), i;
for(i=0; i < all.length; i += 1) {
all[i].SourceElement().parentNode.className += ' has-jax';
}
});
</script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
</div>
</body>
</html>