Skip to content

Commit ca60412

Browse files
committed
Merge remote-tracking branch 'refs/remotes/nqdeng/master'
2 parents 4068660 + aafeef4 commit ca60412

File tree

11 files changed

+2214
-1946
lines changed

11 files changed

+2214
-1946
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2010-2013 Alibaba.com, Inc.
1+
Copyright (c) 2013-2014 Alibaba.com, Inc.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
这是一本NodeJS新手入门教程,涵盖了使用NodeJS开发各种程序所必要的知识,请点击以下链接阅读。
55

66
> [http://nqdeng.github.io/7-days-nodejs/](http://nqdeng.github.io/7-days-nodejs/)
7+
8+
另外,如果愿意协助完善这篇教程的话,您可能需要用到[天书](https://github.com/nqdeng/tianshu)这个小工具。

index.html

Lines changed: 1981 additions & 1869 deletions
Large diffs are not rendered by default.

index.tpl

Lines changed: 162 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,39 @@
22
<html>
33
<head>
44
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
56
<title>七天学会NodeJS</title>
67
<style>
78
body {
8-
font-family: Tahoma;
9-
font-size: 10pt;
9+
color: #333;
10+
font-family: sans-serif;
11+
font-size: 12pt;
1012
line-height: 170%;
11-
padding: 0 10pt;
13+
padding: 0 30px 0 270px;
14+
}
15+
16+
header .banner {
17+
margin: 0 0 1em 0;
18+
}
19+
20+
header .banner, nav .banner {
21+
color: #777;
22+
font-size: 10pt;
23+
font-weight: bold;
24+
}
25+
26+
header h1 {
27+
background: #0c3;
28+
border-radius: 4px;
29+
color: #fff;
30+
font-size: 24pt;
31+
margin: 0;
32+
padding: 1.2em 0;
33+
text-align: center;
1234
}
1335
1436
nav {
15-
background: gray;
16-
color: white;
37+
font-size: 10pt;
1738
overflow-x: hidden;
1839
overflow-y: auto;
1940
position: fixed;
@@ -23,45 +44,86 @@ bottom: 0;
2344
width: 240px;
2445
}
2546
26-
header {
27-
padding-left: 240px;
47+
nav .menubar {
48+
border-bottom: solid 1px #ccc;
49+
display: none;
50+
height: 48px;
51+
line-height: 48px;
52+
padding: 0 10px;
2853
}
2954
30-
header h1 {
31-
background: #ccffcc;
32-
border-radius: 15px;
33-
color: #006600;
34-
font-size: 18pt;
55+
nav .button {
56+
background: #777;
57+
border: 1px solid #333;
58+
color: #fff;
59+
font-size: 10pt;
60+
font-weight: bold;
61+
padding: 8px;
62+
border-radius: 4px;
63+
}
64+
65+
nav ul {
66+
padding: 0 0 0 10px;
67+
}
68+
69+
nav ul a {
70+
color: #333;
71+
text-decoration: none;
72+
}
73+
74+
nav ul a:hover {
75+
text-decoration: underline;
76+
}
77+
78+
nav li {
79+
line-height: 180%;
80+
list-style: none;
3581
margin: 0;
36-
padding: 1.5em;
37-
text-align: center;
82+
padding: 0;
83+
}
84+
85+
nav .level2 {
86+
font-size: 11pt;
87+
font-weight: bold;
3888
}
3989
40-
article {
41-
padding-left: 240px;
90+
nav .level3 {
91+
padding-left: 1em;
92+
}
93+
94+
nav .level3:before {
95+
content: "» ";
96+
}
97+
98+
nav .level4 {
99+
padding-left: 2em;
100+
}
101+
102+
nav .level4:before {
103+
content: "";
42104
}
43105
44106
article h2 {
45107
border-bottom: dotted 1px #777;
46-
color: #006600;
47108
font-size: 12pt;
109+
line-height: 100%;
48110
margin: 4em 0 1em 0;
49111
padding: 0 0 0.3em 0;
50112
}
51113
52114
article h3 {
53-
border-left: 4px solid #ff6666;
54-
color: #000;
55-
font-size: 11pt;
115+
font-size: 12pt;
56116
line-height: 100%;
57-
margin: 1em 0;
58-
padding: 0 0 0 0.5em;
117+
margin: 2em 0 1em 0;
118+
padding: 0;
59119
}
60120
61121
article h4 {
62-
color: #000;
63-
font-size: 10pt;
64-
margin: 1em 0;
122+
font-size: 12pt;
123+
font-style:italic;
124+
font-weight: normal;
125+
line-height: 100%;
126+
margin: 1.2em 0 1em 0;
65127
padding: 0;
66128
}
67129
@@ -81,7 +143,7 @@ color: #f00;
81143
article pre {
82144
background: #eee;
83145
border-left: solid 2px #3c0;
84-
color: #000;
146+
font-size: 10pt;
85147
margin: 1em 0;
86148
padding: 0 0 0 1em;
87149
overflow-x: auto;
@@ -97,57 +159,96 @@ margin: 0;
97159
padding: 0 0 0 1em;
98160
}
99161
100-
nav ul {
101-
margin: 10px;
102-
padding: 0;
162+
article ul, article ol {
163+
padding-left: 2em;
103164
}
104165
105-
nav a {
106-
color: white;
107-
text-decoration: none;
166+
footer {
167+
border-top: 1px solid #ccc;
168+
font-size: 10pt;
169+
margin-top: 4em;
108170
}
109171
110-
nav a:hover {
111-
text-decoration: underline;
172+
@media (max-width: 768px) {
173+
174+
body {
175+
padding: 0 10px 0 230px;
112176
}
113177
114-
nav li {
115-
list-style: none;
178+
nav {
179+
width: 230px;
180+
}
181+
182+
}
183+
184+
@media (max-width: 480px) {
185+
186+
body {
187+
padding: 64px 10px 0 10px;
188+
}
189+
190+
header .banner {
191+
display: none;
192+
}
193+
194+
nav {
195+
position: absolute;
196+
width: 100%;
197+
}
198+
199+
nav .menubar {
200+
display: block;
201+
}
202+
203+
nav .banner {
204+
float: right;
205+
}
206+
207+
nav ul {
208+
background: #fff;
209+
display: none;
210+
font-size: 14pt;
116211
margin: 0;
117-
padding: 0;
212+
padding: 0 0 0 8px;
118213
}
119214
120215
nav .level2 {
121-
font-size: 11pt;
216+
font-size: 16pt;
122217
font-weight: bold;
123218
}
124219
125-
nav .level3 {
126-
padding-left: 1em;
220+
nav li {
221+
line-height: 240%;
127222
}
128223
129-
nav .level3:before {
130-
content: "» ";
224+
.index nav ul {
225+
display: block;
131226
}
132227
133-
nav .level4 {
134-
padding-left: 2em;
228+
.index article {
229+
display: none;
135230
}
136231
137-
nav .level4:before {
138-
content: "";
139-
}
140-
141-
footer {
142-
padding-left: 240px;
143232
}
144233
</style>
234+
<script>
235+
(function (tags) {
236+
var i = 0, len = tags.length;
237+
238+
for (; i < len; ++i) {
239+
document.createElement(tags[i]);
240+
}
241+
}([ 'header', 'nav', 'article', 'footer' ]));
242+
</script>
145243
</head>
146244
<body>
147245
<header>
148246
<x-markdown src="section/00_header.md" />
149247
</header>
150248
<nav>
249+
<div class="menubar">
250+
<a class="button">&#9776;&nbsp;索引</a>
251+
</div>
151252
<x-index />
152253
</nav>
153254
<article>
@@ -162,5 +263,15 @@ padding-left: 240px;
162263
<footer>
163264
<x-markdown src="section/99_footer.md" />
164265
</footer>
266+
<script>
267+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
268+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
269+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
270+
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
271+
272+
ga('create', 'UA-48219044-1', 'auto');
273+
ga('send', 'pageview');
274+
275+
</script>
165276
</body>
166-
</html>
277+
</html>

section/01_getting_started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Linux系统下没有现成的安装程序可用,虽然一些发行版可以使
9191

9292
// foo1至foo4中保存的是同一个模块的导出对象。
9393

94-
另外,可以使用以下方式加载和使用一个JSON文件,模块名中`.json`扩展名不可省略
94+
另外,可以使用以下方式加载和使用一个JSON文件。
9595

9696
var data = require('./data.json');
9797

@@ -176,4 +176,4 @@ Linux系统下没有现成的安装程序可用,虽然一些发行版可以使
176176

177177
+ NodeJS使用[CMD](http://wiki.commonjs.org/)模块系统,主模块作为程序入口点,所有模块在执行过程中只初始化一次。
178178

179-
+ 除非JS模块不能满足需求,否则不要轻易使用二进制模块,否则你的用户会叫苦连天。
179+
+ 除非JS模块不能满足需求,否则不要轻易使用二进制模块,否则你的用户会叫苦连天。

section/02_code_management_and_deployment.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
3. NODE_PATH环境变量
2323

24-
与PATH环境变量类似,NodeJS允许通过NODE_PATH环境变量来指定额外的模块搜索路径。NODE_PATH环境变量中包含一到多个目录路径,路径之间在*nix下使用`:`分隔,在Windows下使用`;`分隔。例如定义了以下NODE_PATH环境变量:
24+
与PATH环境变量类似,NodeJS允许通过NODE_PATH环境变量来指定额外的模块搜索路径。NODE_PATH环境变量中包含一到多个目录路径,路径之间在Linux下使用`:`分隔,在Windows下使用`;`分隔。例如定义了以下NODE_PATH环境变量:
2525

2626
NODE_PATH=/home/user/lib:/home/lib
2727

@@ -102,9 +102,9 @@
102102

103103
$ node-echo Hello World
104104

105-
#### *nix
105+
#### Linux
106106

107-
*nix系统下,我们可以把JS文件当作shell脚本来运行,从而达到上述目的,具体步骤如下:
107+
在Linux系统下,我们可以把JS文件当作shell脚本来运行,从而达到上述目的,具体步骤如下:
108108

109109
1. 在shell脚本中,可以通过`#!`注释来指定当前脚本使用的解析器。所以我们首先在`node-echo.js`文件顶部增加以下一行注释,表明当前脚本使用NodeJS解析。
110110

@@ -222,9 +222,9 @@ NPM是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署
222222

223223
$ npm install node-echo -g
224224

225-
参数中的`-g`表示全局安装,因此`node-echo`会默认安装到以下位置,并且NPM会自动创建好*nix系统下需要的软链文件或Windows系统下需要的`.cmd`文件。
225+
参数中的`-g`表示全局安装,因此`node-echo`会默认安装到以下位置,并且NPM会自动创建好Linux系统下需要的软链文件或Windows系统下需要的`.cmd`文件。
226226

227-
- /usr/local/ # *nix系统下
227+
- /usr/local/ # Linux系统下
228228
- lib/node_modules/
229229
+ node-echo/
230230
...
@@ -296,7 +296,7 @@ NPM是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署
296296

297297
+ 编写代码前先规划好目录结构,才能做到有条不紊。
298298

299-
+ 捎大些的程序可以将代码拆分为多个模块管理,更大些的程序可以使用包来组织模块。
299+
+ 稍大些的程序可以将代码拆分为多个模块管理,更大些的程序可以使用包来组织模块。
300300

301301
+ 合理使用`node_modules``NODE_PATH`来解耦包的使用方式和物理路径。
302302

0 commit comments

Comments
 (0)