-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.xml
703 lines (337 loc) · 655 KB
/
search.xml
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
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>语雀云端写作</title>
<link href="/2023/08/12/Writing_on_The_Cloud_With_YuQue/"/>
<url>/2023/08/12/Writing_on_The_Cloud_With_YuQue/</url>
<content type="html"><![CDATA[<p>语雀云端写作实现了 Markdown 格式的博文与博客构建目录的分离,这样的话,我想同时使用多少个主题都是没有问题的了,更重要的事,可以完全实现静态博客在线编辑。</p><span id="more"></span><div class="note primary flat"><p>本文对于文件(代码)变动的描述方式为<code>-</code>指删掉该行,<code>+</code>指增加改行(如果你是直接复制此行,请注意删掉<code>+</code>和上下文对齐),<code>...</code>表示省略上下文。另外,本文对于文件(代码)变动的描述只针对当时的文件(代码)版本,请根据实际情况决定对自己的相应文件(代码)进行变动。</p></div><h2 id="博文迁移">博文迁移<a class="headerlink" href="#博文迁移"></a></h2><p><a href="https://www.yuque.com/login?platform=wechat&inviteToken=f6e959505e77f114312173f53ec62f7b8996ef80b543c7af96cf3f987a7b91e4">首先是注册语雀账号</a>,登陆上后,新建知识库,名称就为个人博客,再点击右上方的新建,选择导入,选择 Markdown 格式,将本地博文(即 _post 下的 Markdown 文件)批量(按住 Ctrl 可多选)导入至知识库个人博客。</p><p>导入成功后会发现每篇博文的开头,即 front-matter 部分,看起来有点乱,可以参看下图说明更正一下。</p><p><img src="https://img.imql.life/illustrations/ac2ddcd3949a2858339eef3443e4719d.png" alt="更正 front-matter" title="更正 front-matter"></p><h2 id="本地调试">本地调试<a class="headerlink" href="#本地调试"></a></h2><h3 id="安装_Elog">安装 Elog<a class="headerlink" href="#安装_Elog"></a></h3><p><a href="https://github.com/LetTTGACO/elog">Elog</a>,一个开放式跨端博客解决方案,可以随意组合写作平台(语雀/Notion/FlowUs)和博客平台(Hexo/Vitepress/Confluence/WordPress)等,是本次实现语雀云端写作的关键。</p><p>本着非必要不升级的原则,我使用的 Node.js 一直以来都是 v12.14.0,本次安装使用的 Elog 要求至少 14 版本的 Node.js,故而我升级 Node.js 到最新的 LTS 版本,即 18 版本。至于如何升级,如果是 Windows,就卸载然后安装,如果是 Linux,推荐使用 NVM 安装。</p><p>全局安装 @elog/cli:</p><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">npm install -g @elog/cli</span><br></pre></td></tr></table></figure><p>进入<博客构建目录>,执行以下命令进行初始化,会在根目录生成一份配置文件 elog.config.js 和本地调试用的环境变量文件 .elog.env。</p><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">elog init</span><br></pre></td></tr></table></figure><p>将 .elog.env 加入 .gitignore,防止隐私数据提交:</p><figure class="highlight diff"><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">.DS_Store</span><br><span class="line">Thumbs.db</span><br><span class="line">db.json</span><br><span class="line">*.log</span><br><span class="line">public/</span><br><span class="line">node_modules/</span><br><span class="line">.deploy*/</span><br><span class="line"><span class="addition">+.elog.env</span></span><br></pre></td></tr></table></figure><h3 id="配置">配置<a class="headerlink" href="#配置"></a></h3><p>编辑 .elog.env,配置语雀认证的环境变量:</p><figure class="highlight diff"><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"># 语雀(Token方式)</span><br><span class="line">YUQUE_TOKEN=</span><br><span class="line"># 语雀(帐号密码方式)</span><br><span class="line">YUQUE_USERNAME=</span><br><span class="line">YUQUE_PASSWORD=</span><br><span class="line">YUQUE_LOGIN=</span><br><span class="line">YUQUE_REPO=</span><br></pre></td></tr></table></figure><div class="note info flat"><p>Token 方式和帐号密码方式二选一,现在使用 Token 需要开会员,没有会员的就使用帐号密码方式。YUQUE_LOGIN 和 YUQUE_REPO 的获取方式见 <a href="https://elog.1874.cool/notion/gvnxobqogetukays#%E8%AF%AD%E9%9B%80">elog 官方文档的关键信息获取</a>。</p></div><p>再配置图床认证的环境变量,平台可在腾讯云、阿里云、又拍云、七牛云和 GitHub 中选择一个,详细配置方式见 <a href="https://elog.1874.cool/notion/gvnxobqogetukays#%E5%9B%BE%E5%BA%8A">elog 官方文档的关键信息获取</a>。</p><p>编辑 elog.config.js,设置写作平台为 yuque-pwd(即帐号密码方式认证的语雀):</p><figure class="highlight diff"><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">write: {</span><br><span class="line"><span class="deletion">- platform: "yuque"</span></span><br><span class="line"><span class="addition">+ platform: "yuque-pwd",</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><p>配置本地部署方式:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">deploy: {</span><br><span class="line"> platform: "local",</span><br><span class="line"> local: {</span><br><span class="line"><span class="deletion">- outputDir: "./docs",</span></span><br><span class="line"><span class="addition">+ outputDir: "source/_posts",</span></span><br><span class="line"> filename: "title",</span><br><span class="line"><span class="deletion">- format: "markdown",</span></span><br><span class="line"><span class="addition">+ format: "matter-markdown",</span></span><br><span class="line"> catalog: false,</span><br><span class="line"> formatExt: "",</span><br><span class="line"> },</span><br><span class="line">...</span><br></pre></td></tr></table></figure><p>开启图床,设置图床平台为腾讯云、阿里云、又拍云、七牛云或 GitHub:</p><figure class="highlight diff"><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><br><span class="line">image: {</span><br><span class="line"><span class="deletion">- enable: false,</span></span><br><span class="line"><span class="addition">+ enable: true</span></span><br><span class="line"><span class="deletion">- platform: "local",</span></span><br><span class="line"><span class="addition">+ platform: "<图床平台>",</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><p>最后配置图床,配置方式见 <a href="https://elog.1874.cool/notion/fe8ywmt999gon12w#%E5%9B%BE%E5%BA%8A%E5%B9%B3%E5%8F%B0">elog 官方文档的配置详情</a>。</p><h3 id="同步">同步<a class="headerlink" href="#同步"></a></h3><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">elog <span class="built_in">sync</span> -e .elog.env</span><br></pre></td></tr></table></figure><p>如果日志显示同步成功,本地调试即成功。同时,注意到当前目录生成了一个缓存文件 elog.cache.json,其中是我们文章的原始数据。</p><h2 id="持续集成">持续集成<a class="headerlink" href="#持续集成"></a></h2><p>本地安装 @elog/cli:</p><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">npm install @elog/cli</span><br></pre></td></tr></table></figure><p>为了防止 hexo 在生成博客源文件时报错,新建目录 cache,将 elog.cache.json 移动过去。</p><p>编辑 package.json,新建一个 NPM 命令用于同步:</p><figure class="highlight diff"><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">...</span><br><span class="line">"scripts": {</span><br><span class="line"> "build": "hexo generate",</span><br><span class="line"> "clean": "hexo clean",</span><br><span class="line"> "deploy": "hexo deploy",</span><br><span class="line"> "server": "hexo server",</span><br><span class="line"><span class="addition">+ "sync": "elog sync -a cache/elog.cache.json"</span></span><br><span class="line"> },</span><br><span class="line">...</span><br></pre></td></tr></table></figure><p>前往博客构建仓库添加密钥,如下图,添加 YUQUE_TOKEN(YUQUE_USERNAME、YUQUE_PASSWORD)、YUQUE_LOGIN、YUQUE_REPO 的值,再添加图床的密钥,如使用腾讯云作为图床平台,需添加 COS_SECRET_ID、COS_SECRET_KEY、COS_BUCKET、COS_REGION 和 COS_HOST 的值。</p><p><img src="https://img.imql.life/illustrations/90710f82bec002595dbc8594e8ccbea4.png" alt="添加密钥" title="添加密钥"></p><p>编辑 GitHub Actions 工作流:</p><div class="tabs" id="hexo-build"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#hexo-build-1">注释版</button></li><li class="tab"><button type="button" data-href="#hexo-build-2">清洁版</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="hexo-build-1"><figure class="highlight diff"><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><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br></pre></td><td class="code"><pre><span class="line">name: hexo-build</span><br><span class="line"># 仓库分支main有推送时执行jobs下定义的任务</span><br><span class="line">on:</span><br><span class="line"> push:</span><br><span class="line"> branches:</span><br><span class="line"> - main</span><br><span class="line"># 设置时区为上海</span><br><span class="line">env:</span><br><span class="line"> TZ: Asia/Shanghai</span><br><span class="line">jobs:</span><br><span class="line"> # 定义名为blog-build的任务</span><br><span class="line"> blog-build:</span><br><span class="line"> # 定义运行的操作系统</span><br><span class="line"> runs-on: ubuntu-latest</span><br><span class="line"> # 定义步骤</span><br><span class="line"> steps:</span><br><span class="line"> # 签出仓库的默认分支,此处即为main,同时迁出子项目,此处即为主题仓库</span><br><span class="line"> - name: Checkout</span><br><span class="line"> uses: actions/checkout@v3</span><br><span class="line"> with:</span><br><span class="line"> submodules: true</span><br><span class="line"> # 安装别名为lts/Hydrogen的Node.js,即18版本,同时进行全局缓存</span><br><span class="line"><span class="deletion">- - name: Install Node.js v12.14.0</span></span><br><span class="line"><span class="addition">+ - name: Install Node.js lts/Hydrogen</span></span><br><span class="line"> uses: actions/setup-node@v3</span><br><span class="line"> with:</span><br><span class="line"><span class="deletion">- node-version: "12.14.0"</span></span><br><span class="line"><span class="addition">+ node-version: "lts/Hydrogen"</span></span><br><span class="line"> cache: "npm"</span><br><span class="line"> # 缓存文件夹node_modules并生成唯一码</span><br><span class="line"> - name: Cache dependencies</span><br><span class="line"> uses: actions/cache@v3</span><br><span class="line"> id: cache-dependencies</span><br><span class="line"> with:</span><br><span class="line"> path: node_modules</span><br><span class="line"> key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}</span><br><span class="line"> # 如果唯一码比对不成功,重新安装依赖,成功则沿用缓存</span><br><span class="line"> - name: Install dependencies</span><br><span class="line"> if: steps.cache-dependencies.outputs.cache-hit != 'true'</span><br><span class="line"> run: npm ci</span><br><span class="line"><span class="addition">+ - name: Pull posts from Yuque</span></span><br><span class="line"><span class="addition">+ env:</span></span><br><span class="line"><span class="addition">+ YUQUE_TOKEN: ${{ secrets.YUQUE_TOKEN }}</span></span><br><span class="line"><span class="addition">+ YUQUE_LOGIN: ${{ secrets.YUQUE_LOGIN }}</span></span><br><span class="line"><span class="addition">+ YUQUE_REPO: ${{ secrets.YUQUE_REPO }}</span></span><br><span class="line"><span class="addition">+ COS_SECRET_ID: ${{ secrets.COS_SECRET_ID }}</span></span><br><span class="line"><span class="addition">+ COS_SECRET_KEY: ${{ secrets.COS_SECRET_KEY }}</span></span><br><span class="line"><span class="addition">+ COS_BUCKET: ${{ secrets.COS_BUCKET }}</span></span><br><span class="line"><span class="addition">+ COS_REGION: ${{ secrets.COS_REGION }}</span></span><br><span class="line"><span class="addition">+ COS_HOST: ${{ secrets.COS_HOST }}</span></span><br><span class="line"><span class="addition">+ run: |</span></span><br><span class="line"><span class="addition">+ # elog.cache.json被指定在子目录cache下,需要先创建,先判断有没有,没有才创建</span></span><br><span class="line"><span class="addition">+ [ ! -d "cache" ] && mkdir cache</span></span><br><span class="line"><span class="addition">+ npm run sync</span></span><br><span class="line"> - name: Setup private rsa key</span><br><span class="line"> env:</span><br><span class="line"> DEPLOY_KEY: ${{secrets.DEPLOY_KEY}}</span><br><span class="line"> run: |</span><br><span class="line"> mkdir -p ~/.ssh/</span><br><span class="line"> echo "$DEPLOY_KEY" > ~/.ssh/id_rsa</span><br><span class="line"> chmod 600 ~/.ssh/id_rsa</span><br><span class="line"> ssh-keyscan github.com >> ~/.ssh/known_hosts</span><br><span class="line"> ssh-keyscan gitee.com >> ~/.ssh/known_hosts</span><br><span class="line"> - name: Download and clone PUBLIC</span><br><span class="line"> run: |</span><br><span class="line"> # 下载自己的GitHub用户仓库,下载的文件为master.zip</span><br><span class="line"> curl -LsO https://github.com/ql-isaac/<自己的Github用户名>.github.io/archive/refs/heads/master.zip</span><br><span class="line"> # 解压</span><br><span class="line"> unzip master.zip -d .</span><br><span class="line"> # 重命名为public</span><br><span class="line"> mv <自己的Github用户名>.github.io-master/ public</span><br><span class="line"> # 克隆自己的GitHub用户仓库,重命令为.deploy_git</span><br><span class="line"> git clone [email protected]:ql-isaac/<自己的Github用户名>.github.io.git .deploy_git</span><br><span class="line"> - name: Download DB</span><br><span class="line"> uses: dawidd6/action-download-artifact@v2</span><br><span class="line"> continue-on-error: true # 构件最多只能保存90天,90天过后这一步会报错,设置成报错继续执行</span><br><span class="line"> with:</span><br><span class="line"> github_token: ${{secrets.GITHUB_TOKEN}}</span><br><span class="line"> name: "DB"</span><br><span class="line"> - name: Generate and deploy</span><br><span class="line"> run: |</span><br><span class="line"> git config --global user.name "${{secrets.GIT_NAME}}"</span><br><span class="line"> git config --global user.email "${{secrets.GIT_EMAIL}}"</span><br><span class="line"> npm run build && npm run deploy</span><br><span class="line"> - name: Upload DB for next workflow to download</span><br><span class="line"> uses: actions/upload-artifact@v3</span><br><span class="line"> with:</span><br><span class="line"> name: "DB"</span><br><span class="line"> path: db.json</span><br><span class="line"> retention-days: 90</span><br><span class="line"><span class="addition">+ - name: Upload Cache for next workflow to download</span></span><br><span class="line"><span class="addition">+ uses: actions/upload-artifact@v3</span></span><br><span class="line"><span class="addition">+ with:</span></span><br><span class="line"><span class="addition">+ name: "Cache"</span></span><br><span class="line"><span class="addition">+ path: cache</span></span><br><span class="line"><span class="addition">+ retention-days: 90</span></span><br><span class="line"><span class="addition">+ - name: Upload Posts for next workflow to download</span></span><br><span class="line"><span class="addition">+ uses: actions/upload-artifact@v3</span></span><br><span class="line"><span class="addition">+ with:</span></span><br><span class="line"><span class="addition">+ name: "Posts"</span></span><br><span class="line"><span class="addition">+ path: "source/_posts"</span></span><br><span class="line"><span class="addition">+ retention-days: 90</span></span><br></pre></td></tr></table></figure><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="hexo-build-2"><figure class="highlight diff"><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><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br></pre></td><td class="code"><pre><span class="line">name: hexo-build</span><br><span class="line">on:</span><br><span class="line"> push:</span><br><span class="line"> branches:</span><br><span class="line"> - main</span><br><span class="line">env:</span><br><span class="line"> TZ: Asia/Shanghai</span><br><span class="line">jobs:</span><br><span class="line"> blog-build:</span><br><span class="line"> runs-on: ubuntu-latest</span><br><span class="line"> steps:</span><br><span class="line"> - name: Checkout</span><br><span class="line"> uses: actions/checkout@v3</span><br><span class="line"> with:</span><br><span class="line"> submodules: true</span><br><span class="line"><span class="deletion">- - name: Install Node.js v12.14.0</span></span><br><span class="line"><span class="addition">+ - name: Install Node.js lts/Hydrogen</span></span><br><span class="line"> uses: actions/setup-node@v3</span><br><span class="line"> with:</span><br><span class="line"><span class="deletion">- node-version: "12.14.0"</span></span><br><span class="line"><span class="addition">+ node-version: "lts/Hydrogen"</span></span><br><span class="line"> cache: "npm"</span><br><span class="line"> - name: Cache dependencies</span><br><span class="line"> uses: actions/cache@v3</span><br><span class="line"> id: cache-dependencies</span><br><span class="line"> with:</span><br><span class="line"> path: node_modules</span><br><span class="line"> key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}</span><br><span class="line"> - name: Install dependencies</span><br><span class="line"> if: steps.cache-dependencies.outputs.cache-hit != 'true'</span><br><span class="line"> run: npm ci</span><br><span class="line"><span class="addition">+ - name: Pull posts from Yuque</span></span><br><span class="line"><span class="addition">+ env:</span></span><br><span class="line"><span class="addition">+ YUQUE_TOKEN: ${{ secrets.YUQUE_TOKEN }}</span></span><br><span class="line"><span class="addition">+ YUQUE_LOGIN: ${{ secrets.YUQUE_LOGIN }}</span></span><br><span class="line"><span class="addition">+ YUQUE_REPO: ${{ secrets.YUQUE_REPO }}</span></span><br><span class="line"><span class="addition">+ COS_SECRET_ID: ${{ secrets.COS_SECRET_ID }}</span></span><br><span class="line"><span class="addition">+ COS_SECRET_KEY: ${{ secrets.COS_SECRET_KEY }}</span></span><br><span class="line"><span class="addition">+ COS_BUCKET: ${{ secrets.COS_BUCKET }}</span></span><br><span class="line"><span class="addition">+ COS_REGION: ${{ secrets.COS_REGION }}</span></span><br><span class="line"><span class="addition">+ COS_HOST: ${{ secrets.COS_HOST }}</span></span><br><span class="line"><span class="addition">+ run: |</span></span><br><span class="line"><span class="addition">+ [ ! -d "cache" ] && mkdir cache</span></span><br><span class="line"><span class="addition">+ npm run sync</span></span><br><span class="line"> - name: Setup private rsa key</span><br><span class="line"> env:</span><br><span class="line"> DEPLOY_KEY: ${{secrets.DEPLOY_KEY}}</span><br><span class="line"> run: |</span><br><span class="line"> mkdir -p ~/.ssh/</span><br><span class="line"> echo "$DEPLOY_KEY" > ~/.ssh/id_rsa</span><br><span class="line"> chmod 600 ~/.ssh/id_rsa</span><br><span class="line"> ssh-keyscan github.com >> ~/.ssh/known_hosts</span><br><span class="line"> ssh-keyscan gitee.com >> ~/.ssh/known_hosts</span><br><span class="line"> - name: Download and clone PUBLIC</span><br><span class="line"> run: |</span><br><span class="line"> curl -LsO https://github.com/ql-isaac/<自己的Github用户名>.github.io/archive/refs/heads/master.zip</span><br><span class="line"> unzip master.zip -d .</span><br><span class="line"> mv <自己的Github用户名>.github.io-master/ public</span><br><span class="line"> git clone [email protected]:ql-isaac/<自己的Github用户名>.github.io.git .deploy_git</span><br><span class="line"> - name: Download DB</span><br><span class="line"> uses: dawidd6/action-download-artifact@v2</span><br><span class="line"> continue-on-error: true</span><br><span class="line"> with:</span><br><span class="line"> github_token: ${{secrets.GITHUB_TOKEN}}</span><br><span class="line"> name: "DB"</span><br><span class="line"> - name: Generate and deploy</span><br><span class="line"> run: |</span><br><span class="line"> git config --global user.name "${{secrets.GIT_NAME}}"</span><br><span class="line"> git config --global user.email "${{secrets.GIT_EMAIL}}"</span><br><span class="line"> npm run build && npm run deploy</span><br><span class="line"> - name: Upload DB for next workflow to download</span><br><span class="line"> uses: actions/upload-artifact@v3</span><br><span class="line"> with:</span><br><span class="line"> name: "DB"</span><br><span class="line"> path: db.json</span><br><span class="line"> retention-days: 90</span><br><span class="line"><span class="addition">+ - name: Upload Cache for next workflow to use</span></span><br><span class="line"><span class="addition">+ uses: actions/upload-artifact@v3</span></span><br><span class="line"><span class="addition">+ with:</span></span><br><span class="line"><span class="addition">+ name: "Cache"</span></span><br><span class="line"><span class="addition">+ path: cache</span></span><br><span class="line"><span class="addition">+ retention-days: 90</span></span><br><span class="line"><span class="addition">+ - name: Upload Posts for next workflow to use</span></span><br><span class="line"><span class="addition">+ uses: actions/upload-artifact@v3</span></span><br><span class="line"><span class="addition">+ with:</span></span><br><span class="line"><span class="addition">+ name: "Posts"</span></span><br><span class="line"><span class="addition">+ path: "source/_posts"</span></span><br><span class="line"><span class="addition">+ retention-days: 90</span></span><br></pre></td></tr></table></figure><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><p>提交并推送:</p><figure class="highlight diff"><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">git add .</span><br><span class="line">git commit -m ":green_heart: 使用elog实现语雀云端写作"</span><br><span class="line">git push</span><br></pre></td></tr></table></figure><p>再次编辑 GitHub Actions 工作流:</p><div class="tabs" id="hexo-build"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#hexo-build-1">注释版</button></li><li class="tab"><button type="button" data-href="#hexo-build-2">清洁版</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="hexo-build-1"><figure class="highlight diff"><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><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br></pre></td><td class="code"><pre><span class="line">name: hexo-build</span><br><span class="line">on:</span><br><span class="line"># 将执行jobs下定义的任务的充分条件改为有类型为publish的外部事件触发</span><br><span class="line"><span class="deletion">- push:</span></span><br><span class="line"><span class="deletion">- branches:</span></span><br><span class="line"><span class="deletion">- - main</span></span><br><span class="line"><span class="addition">+ repository_dispatch:</span></span><br><span class="line"><span class="addition">+ types:</span></span><br><span class="line"><span class="addition">+ - publish</span></span><br><span class="line"># 设置时区为上海</span><br><span class="line">env:</span><br><span class="line"> TZ: Asia/Shanghai</span><br><span class="line">jobs:</span><br><span class="line"> # 定义名为blog-build的任务</span><br><span class="line"> blog-build:</span><br><span class="line"> # 定义运行的操作系统</span><br><span class="line"> runs-on: ubuntu-latest</span><br><span class="line"> # 定义步骤</span><br><span class="line"> steps:</span><br><span class="line"> # 签出仓库的默认分支,此处即为main,同时迁出子项目,此处即为主题仓库</span><br><span class="line"> - name: Checkout</span><br><span class="line"> uses: actions/checkout@v3</span><br><span class="line"> with:</span><br><span class="line"> submodules: true</span><br><span class="line"> # 安装别名为lts/Hydrogen的Node.js,即18版本,同时进行全局缓存</span><br><span class="line"> - name: Install Node.js lts/Hydrogen</span><br><span class="line"> uses: actions/setup-node@v3</span><br><span class="line"> with:</span><br><span class="line"> node-version: "lts/Hydrogen"</span><br><span class="line"> cache: "npm"</span><br><span class="line"> # 缓存文件夹node_modules并生成唯一码</span><br><span class="line"> - name: Cache dependencies</span><br><span class="line"> uses: actions/cache@v3</span><br><span class="line"> id: cache-dependencies</span><br><span class="line"> with:</span><br><span class="line"> path: node_modules</span><br><span class="line"> key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}</span><br><span class="line"> # 如果唯一码比对不成功,重新安装依赖,成功则沿用缓存</span><br><span class="line"> - name: Install dependencies</span><br><span class="line"> if: steps.cache-dependencies.outputs.cache-hit != 'true'</span><br><span class="line"> run: npm ci</span><br><span class="line"><span class="addition">+ - name: Download Posts from the last workflow</span></span><br><span class="line"><span class="addition">+ uses: dawidd6/action-download-artifact@v2</span></span><br><span class="line"><span class="addition">+ continue-on-error: true # 构件最多只能保存90天,90天过后这一步会报错,设置成报错继续执行</span></span><br><span class="line"><span class="addition">+ with:</span></span><br><span class="line"><span class="addition">+ github_token: ${{secrets.GITHUB_TOKEN}}</span></span><br><span class="line"><span class="addition">+ name: "Posts"</span></span><br><span class="line"><span class="addition">+ path: "source/_posts"</span></span><br><span class="line"><span class="addition">+ - name: Download Cache from the last workflow</span></span><br><span class="line"><span class="addition">+ continue-on-error: true</span></span><br><span class="line"><span class="addition">+ uses: dawidd6/action-download-artifact@v2</span></span><br><span class="line"><span class="addition">+ continue-on-error: true</span></span><br><span class="line"><span class="addition">+ with:</span></span><br><span class="line"><span class="addition">+ github_token: ${{secrets.GITHUB_TOKEN}}</span></span><br><span class="line"><span class="addition">+ name: "Cache"</span></span><br><span class="line"><span class="addition">+ path: "cache"</span></span><br><span class="line"> - name: Pull posts from Yuque</span><br><span class="line"> env:</span><br><span class="line"> YUQUE_TOKEN: ${{ secrets.YUQUE_TOKEN }}</span><br><span class="line"> YUQUE_LOGIN: ${{ secrets.YUQUE_LOGIN }}</span><br><span class="line"> YUQUE_REPO: ${{ secrets.YUQUE_REPO }}</span><br><span class="line"> COS_SECRET_ID: ${{ secrets.COS_SECRET_ID }}</span><br><span class="line"> COS_SECRET_KEY: ${{ secrets.COS_SECRET_KEY }}</span><br><span class="line"> COS_BUCKET: ${{ secrets.COS_BUCKET }}</span><br><span class="line"> COS_REGION: ${{ secrets.COS_REGION }}</span><br><span class="line"> COS_HOST: ${{ secrets.COS_HOST }}</span><br><span class="line"> run: |</span><br><span class="line"> [ ! -d "cache" ] && mkdir cache</span><br><span class="line"> npm run sync</span><br><span class="line"> - name: Setup private rsa key</span><br><span class="line"> env:</span><br><span class="line"> DEPLOY_KEY: ${{secrets.DEPLOY_KEY}}</span><br><span class="line"> run: |</span><br><span class="line"> mkdir -p ~/.ssh/</span><br><span class="line"> echo "$DEPLOY_KEY" > ~/.ssh/id_rsa</span><br><span class="line"> chmod 600 ~/.ssh/id_rsa</span><br><span class="line"> ssh-keyscan github.com >> ~/.ssh/known_hosts</span><br><span class="line"> ssh-keyscan gitee.com >> ~/.ssh/known_hosts</span><br><span class="line"> - name: Download and clone PUBLIC</span><br><span class="line"> run: |</span><br><span class="line"> # 下载自己的GitHub用户仓库,下载的文件为master.zip</span><br><span class="line"> curl -LsO https://github.com/ql-isaac/<自己的Github用户名>.github.io/archive/refs/heads/master.zip</span><br><span class="line"> # 解压</span><br><span class="line"> unzip master.zip -d .</span><br><span class="line"> # 重命名为public</span><br><span class="line"> mv <自己的Github用户名>.github.io-master/ public</span><br><span class="line"> # 克隆自己的GitHub用户仓库,重命令为.deploy_git</span><br><span class="line"> git clone [email protected]:ql-isaac/<自己的Github用户名>.github.io.git .deploy_git</span><br><span class="line"> - name: Download DB</span><br><span class="line"> uses: dawidd6/action-download-artifact@v2</span><br><span class="line"> continue-on-error: true # 构件最多只能保存90天,90天过后这一步会报错,设置成报错继续执行</span><br><span class="line"> with:</span><br><span class="line"> github_token: ${{secrets.GITHUB_TOKEN}}</span><br><span class="line"> name: "DB"</span><br><span class="line"> - name: Generate and deploy</span><br><span class="line"> run: |</span><br><span class="line"> git config --global user.name "${{secrets.GIT_NAME}}"</span><br><span class="line"> git config --global user.email "${{secrets.GIT_EMAIL}}"</span><br><span class="line"> npm run build && npm run deploy</span><br><span class="line"> - name: Upload DB for next workflow to download</span><br><span class="line"> uses: actions/upload-artifact@v3</span><br><span class="line"> with:</span><br><span class="line"> name: "DB"</span><br><span class="line"> path: db.json</span><br><span class="line"> retention-days: 90</span><br><span class="line"> - name: Upload Cache for next workflow to download</span><br><span class="line"> uses: actions/upload-artifact@v3</span><br><span class="line"> with:</span><br><span class="line"> name: "Cache"</span><br><span class="line"> path: cache</span><br><span class="line"> retention-days: 90</span><br><span class="line"> - name: Upload Posts for next workflow to download</span><br><span class="line"> uses: actions/upload-artifact@v3</span><br><span class="line"> with:</span><br><span class="line"> name: "Posts"</span><br><span class="line"> path: "source/_posts"</span><br><span class="line"> retention-days: 90</span><br></pre></td></tr></table></figure><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="hexo-build-2"><figure class="highlight diff"><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><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br></pre></td><td class="code"><pre><span class="line">name: hexo-build</span><br><span class="line">on:</span><br><span class="line"><span class="deletion">- push:</span></span><br><span class="line"><span class="deletion">- branches:</span></span><br><span class="line"><span class="deletion">- - main</span></span><br><span class="line"><span class="addition">+ repository_dispatch:</span></span><br><span class="line"><span class="addition">+ types:</span></span><br><span class="line"><span class="addition">+ - publish</span></span><br><span class="line">env:</span><br><span class="line"> TZ: Asia/Shanghai</span><br><span class="line">jobs:</span><br><span class="line"> blog-build:</span><br><span class="line"> runs-on: ubuntu-latest</span><br><span class="line"> steps:</span><br><span class="line"> - name: Checkout</span><br><span class="line"> uses: actions/checkout@v3</span><br><span class="line"> with:</span><br><span class="line"> submodules: true</span><br><span class="line"> - name: Install Node.js lts/Hydrogen</span><br><span class="line"> uses: actions/setup-node@v3</span><br><span class="line"> with:</span><br><span class="line"> node-version: "lts/Hydrogen"</span><br><span class="line"> cache: "npm"</span><br><span class="line"> - name: Cache dependencies</span><br><span class="line"> uses: actions/cache@v3</span><br><span class="line"> id: cache-dependencies</span><br><span class="line"> with:</span><br><span class="line"> path: node_modules</span><br><span class="line"> key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}</span><br><span class="line"> - name: Install dependencies</span><br><span class="line"> if: steps.cache-dependencies.outputs.cache-hit != 'true'</span><br><span class="line"> run: npm ci</span><br><span class="line"><span class="addition">+ - name: Download Posts from the last workflow</span></span><br><span class="line"><span class="addition">+ uses: dawidd6/action-download-artifact@v2</span></span><br><span class="line"><span class="addition">+ continue-on-error: true</span></span><br><span class="line"><span class="addition">+ with:</span></span><br><span class="line"><span class="addition">+ github_token: ${{secrets.GITHUB_TOKEN}}</span></span><br><span class="line"><span class="addition">+ name: "Posts"</span></span><br><span class="line"><span class="addition">+ path: "source/_posts"</span></span><br><span class="line"><span class="addition">+ - name: Download Cache from the last workflow</span></span><br><span class="line"><span class="addition">+ uses: dawidd6/action-download-artifact@v2</span></span><br><span class="line"><span class="addition">+ continue-on-error: true</span></span><br><span class="line"><span class="addition">+ with:</span></span><br><span class="line"><span class="addition">+ github_token: ${{secrets.GITHUB_TOKEN}}</span></span><br><span class="line"><span class="addition">+ name: "Cache"</span></span><br><span class="line"><span class="addition">+ path: "cache"</span></span><br><span class="line"> - name: Pull posts from Yuque</span><br><span class="line"> env:</span><br><span class="line"> YUQUE_TOKEN: ${{ secrets.YUQUE_TOKEN }}</span><br><span class="line"> YUQUE_LOGIN: ${{ secrets.YUQUE_LOGIN }}</span><br><span class="line"> YUQUE_REPO: ${{ secrets.YUQUE_REPO }}</span><br><span class="line"> COS_SECRET_ID: ${{ secrets.COS_SECRET_ID }}</span><br><span class="line"> COS_SECRET_KEY: ${{ secrets.COS_SECRET_KEY }}</span><br><span class="line"> COS_BUCKET: ${{ secrets.COS_BUCKET }}</span><br><span class="line"> COS_REGION: ${{ secrets.COS_REGION }}</span><br><span class="line"> COS_HOST: ${{ secrets.COS_HOST }}</span><br><span class="line"> run: |</span><br><span class="line"> [ ! -d "cache" ] && mkdir cache</span><br><span class="line"> npm run sync</span><br><span class="line"> - name: Setup private rsa key</span><br><span class="line"> env:</span><br><span class="line"> DEPLOY_KEY: ${{secrets.DEPLOY_KEY}}</span><br><span class="line"> run: |</span><br><span class="line"> mkdir -p ~/.ssh/</span><br><span class="line"> echo "$DEPLOY_KEY" > ~/.ssh/id_rsa</span><br><span class="line"> chmod 600 ~/.ssh/id_rsa</span><br><span class="line"> ssh-keyscan github.com >> ~/.ssh/known_hosts</span><br><span class="line"> ssh-keyscan gitee.com >> ~/.ssh/known_hosts</span><br><span class="line"> - name: Download and clone PUBLIC</span><br><span class="line"> run: |</span><br><span class="line"> curl -LsO https://github.com/ql-isaac/<自己的Github用户名>.github.io/archive/refs/heads/master.zip</span><br><span class="line"> unzip master.zip -d .</span><br><span class="line"> mv <自己的Github用户名>.github.io-master/ public</span><br><span class="line"> git clone [email protected]:ql-isaac/<自己的Github用户名>.github.io.git .deploy_git</span><br><span class="line"> - name: Download DB</span><br><span class="line"> uses: dawidd6/action-download-artifact@v2</span><br><span class="line"> continue-on-error: true</span><br><span class="line"> with:</span><br><span class="line"> github_token: ${{secrets.GITHUB_TOKEN}}</span><br><span class="line"> name: "DB"</span><br><span class="line"> - name: Generate and deploy</span><br><span class="line"> run: |</span><br><span class="line"> git config --global user.name "${{secrets.GIT_NAME}}"</span><br><span class="line"> git config --global user.email "${{secrets.GIT_EMAIL}}"</span><br><span class="line"> npm run build && npm run deploy</span><br><span class="line"> - name: Upload DB for next workflow to download</span><br><span class="line"> uses: actions/upload-artifact@v3</span><br><span class="line"> with:</span><br><span class="line"> name: "DB"</span><br><span class="line"> path: db.json</span><br><span class="line"> retention-days: 90</span><br><span class="line"> - name: Upload Cache for next workflow to download</span><br><span class="line"> uses: actions/upload-artifact@v3</span><br><span class="line"> with:</span><br><span class="line"> name: "Cache"</span><br><span class="line"> path: cache</span><br><span class="line"> retention-days: 90</span><br><span class="line"> - name: Upload Posts for next workflow to download</span><br><span class="line"> uses: actions/upload-artifact@v3</span><br><span class="line"> with:</span><br><span class="line"> name: "Posts"</span><br><span class="line"> path: "source/_posts"</span><br><span class="line"> retention-days: 90</span><br></pre></td></tr></table></figure><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><p>将 source 下 _posts 和 cache 下的 elog.cache.json 加入 .gitignore 并删除掉,这两个地方的文件已经不需要。</p><p>最终提交并推送:</p><figure class="highlight diff"><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">git add .</span><br><span class="line">git commit -m ":green_heart: 使用elog实现语雀云端写作(终)"</span><br><span class="line">git push</span><br></pre></td></tr></table></figure><p>这样,在语雀上写好博文并更新,只需要地址栏输入以下地址(外部事件触发 API),即可触发持续集成,实现云端写作。</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://serverless-api-elog.vercel.app/api/github?user=<自己GitHub用户名>&repo=<博客构建仓库名>&event_type=publish&token=<自己生成的Token></span><br></pre></td></tr></table></figure><div class="note success flat"><p>生成 Token 的方式(勾选 repo 的权限):</p><p><img src="https://img.imql.life/illustrations/00a92719a9a976b6a2a985afec041d27.png" alt="image.png"></p></div><p>以上 API 是 elog 官方在 Vercel 上搭建的,使用的 Vercel 默认域名,会经常被墙,我们可以自己搭建一个并且使用上自己的域名(未备案也行,因为 Vercel 是国外服务)。</p><p>fork <a href="https://github.com/LetTTGACO/serverless-api">serverless-api</a>,<a href="https://vercel.com/dashboard">登录 Vercel</a>,新建,导入刚刚 fork 的项目,部署。到域名设置那里,添加自己的域名,如 publish.xxx.xx,再到域名供应商那里添加一下 cname 解析,最后回到域名设置那里,确认解析生效,这样,将以上地址中域名替换为自己的域名得到自己的 API。</p>]]></content>
<categories>
<category> 我的博客 </category>
</categories>
<tags>
<tag> elog </tag>
</tags>
</entry>
<entry>
<title>玩转我的博客</title>
<link href="/2022/10/16/Play_with_My_Blog/"/>
<url>/2022/10/16/Play_with_My_Blog/</url>
<content type="html"><![CDATA[<p>要想玩转博客,参考<a href="https://www.imql.life/link/">友链</a>中小伙伴或者第一方的教程是必不可少的,本文收集和整理了一下。</p><span id="more"></span><h2 id="评论系统">评论系统<a class="headerlink" href="#评论系统"></a></h2><p>评论系统最开始使用的 Valine,其使用的云服务是 LeanCloud,但 LeanCloud 免费版云引擎会强制休眠,参考<a href="https://www.antmoe.com/posts/ff6aef7b/index.html">优雅解决 LeanCloud 流控问题</a>得以解决。</p><p>后开始使用 Twikoo,参考<a href="https://twikoo.js.org/quick-start.html">快速开始</a>于腾讯云开发平台部署成功,2022 年 9 月 8 日腾讯云开发推出新的收费模式,不再免费,参考<a href="https://blog.zhheo.com/p/99d020fe.html"> Twikoo 腾讯云函数部署转移到私有部署</a>和<a href="https://twikoo.js.org/quick-start.html#vercel-%E9%83%A8%E7%BD%B2">快速开始的 Vercel 部署章节</a>将评论系统迁移至 Vercel。</p><h2 id="友链系统">友链系统<a class="headerlink" href="#友链系统"></a></h2><h2 id="优雅的更新主题">优雅的更新主题<a class="headerlink" href="#优雅的更新主题"></a></h2>]]></content>
<categories>
<category> 我的博客 </category>
</categories>
</entry>
<entry>
<title>证券投资基金基础知识</title>
<link href="/2022/05/29/Basic_Knowledge_of_Securities_Investment_Funds/"/>
<url>/2022/05/29/Basic_Knowledge_of_Securities_Investment_Funds/</url>
<content type="html"><![CDATA[<p>投资管理基础;权益投资;固定收益投资;衍生工具;另类投资;投资管理流程与投资者需求;投资组合管理;投资交易管理;投资风险管理;基金业绩评价;基金的投资交易与结算;基金的估值、费用与会计核算;基金的利润分配和税收;基金国际化的发展概况。</p><span id="more"></span><h2 id="投资管理基础">投资管理基础<a class="headerlink" href="#投资管理基础"></a></h2><h3 id="财务报表">财务报表<a class="headerlink" href="#财务报表"></a></h3><h4 id="概述(理解)">概述(理解)<a class="headerlink" href="#概述(理解)"></a></h4><div class="tabs" id="financial-statement"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#financial-statement-1">概念</button></li><li class="tab"><button type="button" data-href="#financial-statement-2">构成</button></li><li class="tab"><button type="button" data-href="#financial-statement-3">作用</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="financial-statement-1"><p>财务报表按照财务会计准则定期编制,将企业一定期间内的会计事项做一系列的汇总表示,用以显示企业实际的财务状况和经营业绩的优劣。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="financial-statement-2"><p>由资产负债表、利润表和现金流量表三大报表,另外还有所有者权益变动表构成。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="financial-statement-3"><p>了解企业财务状况、计算财务比率和分析企业的营运状况、价值和风险特征。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h4 id="资产负债表(重点掌握)">资产负债表(重点掌握)<a class="headerlink" href="#资产负债表(重点掌握)"></a></h4><div class="tabs" id="balance-sheet"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#balance-sheet-1">概念</button></li><li class="tab"><button type="button" data-href="#balance-sheet-2">构成</button></li><li class="tab"><button type="button" data-href="#balance-sheet-3">所有者权益组成</button></li><li class="tab"><button type="button" data-href="#balance-sheet-4">作用</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="balance-sheet-1"><p>资产负债表是企业的“第一会计报表”,反映了企业在特定时点的财务状况,是企业经营管理活动结果的集中体现。报告时点通常为会计季末、半年末或年末。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="balance-sheet-2"><ul><li>资产:企业所拥有的或掌握的,以及被其他企业所欠的各种资源和财产。</li><li>负债:企业所应支付的所有债务。</li><li>所有者权益:又称股东权益或净资产,即在清偿各种债务以后,企业股东所拥有的资产价值。</li></ul><p><img src="https://img.imql.life/illustrations/e431dd9916aaa7fcbd643e8f9c6a3554.svg" alt=""></p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="balance-sheet-3"><ul><li>股本:按照面值计算的股本金,也称为实收资本。</li><li>资本公积:包括股票发行溢价、法定财产重估增值、接受捐赠资产、政府专项拨款转入等。</li><li>盈余公积:分为法定盈余公积和任意盈余公积。</li><li>未分配利润:企业留待以后年度分配的利润或待分配利润。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="balance-sheet-4"><ol><li>资产负债表列出了企业占有资源的数量和性质;</li><li>资产负债表上的资源为分析收入来源性质及其稳定性提供了基础;</li><li>资产负债表上的资产项可以揭示企业资金的占用情况,负债项则说明企业的资金来源和财务状况,有利于投资者分析企业长期债务或短期债务的偿还能力,是否存在财务困难以及违约风险等;</li><li>资产负债表可以为收益把关。可以大大限制资产和负债的操作程度,与利润表相比更加规范和准确。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h4 id="利润表(掌握)">利润表(掌握)<a class="headerlink" href="#利润表(掌握)"></a></h4><div class="tabs" id="income-statement"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#income-statement-1">概念</button></li><li class="tab"><button type="button" data-href="#income-statement-2">构成</button></li><li class="tab"><button type="button" data-href="#income-statement-3">分析</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="income-statement-1"><p>也称损益表,反应一定时期(如一个会计季度或会计年度)的总体经营成果,揭示企业财务状况发生变动的直接原因。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="income-statement-2"><p><img src="https://img.imql.life/illustrations/89a9d993df05aa4737d2aedcc83ed8ec.svg" alt=""></p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="income-statement-3"><ol><li>概念:分析企业如何组织收入、控制成本费用支出以实现盈利的能力。</li><li>作用:用于评价企业的经营绩效,同时还可以通过收支结构和业务结构分析,评价各部类业绩成长对企业总盈余的贡献度。</li></ol><div class="note info flat"><p>在评价企业的整体业绩时,重点在于企业的净利润,即息税前利润(EBIT)减去利息费用和税费。</p></div><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h4 id="现金流量表(重点掌握)">现金流量表(重点掌握)<a class="headerlink" href="#现金流量表(重点掌握)"></a></h4><div class="tabs" id="cash-flow-statement"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#cash-flow-statement-1">概念</button></li><li class="tab"><button type="button" data-href="#cash-flow-statement-2">编制原理</button></li><li class="tab"><button type="button" data-href="#cash-flow-statement-3">基本构成</button></li><li class="tab"><button type="button" data-href="#cash-flow-statement-4">作用</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="cash-flow-statement-1"><p>也称账务状况变动表,所表达的是在特定会计期间内,企业的现金(包括现金等价物)的增减变动等情形。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="cash-flow-statement-2"><p>根据收付实现制(即实际现金流入和现金流出)为基础编制。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="cash-flow-statement-3"><ul><li>经营活动产生的现金流量(CFO),是与生产商品、提供劳务、缴纳税金等直接相关的业务所产生的现金流量。</li><li>投资活动产生的现金流量(CFI),包括为正常生产经营活动投资的长期资产以及对外投资所产生的股权与债权。</li><li>筹资(也称融资)活动产生的现金流量(CFF),反映的是企业长期资本(股票和债券、贷款等)筹集资金状况。</li></ul><div class="note info flat"><p>以上三部分现金流相加则得到净现金流(NCF):<img src="https://img.imql.life/illustrations/30f82544df0a8c46cf924e6e73cf97a2.svg" alt=""></p></div><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="cash-flow-statement-4"><ol><li>反映企业的现金流量,评价企业未来产生现金净流量的能力。</li><li>评价企业偿还债务、支付投资利润的能力,谨慎判断企业财务状况。</li><li>分析净收益与现金流量间的差异,并解释差异产生的原因。</li><li>通过对现金投资与融资、非现金投资与融资的分析,全面了解企业财务状况。</li></ol><p>分析现金流量表,有助于投资者估计今后企业的偿债能力、获取现金的能力、创造现金流量的能力和支付股利的能力。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h3 id="财务报表分析">财务报表分析<a class="headerlink" href="#财务报表分析"></a></h3><h4 id="概念(理解)">概念(理解)<a class="headerlink" href="#概念(理解)"></a></h4><p>财务报表分析指通过对企业财务报表相关财务数据进行解析,挖掘企业经营和发展的相关财务信息,从而为评价企业的经营业绩和财务状况提供帮助。</p><h4 id="财务比率分析(重点掌握)">财务比率分析(重点掌握)<a class="headerlink" href="#财务比率分析(重点掌握)"></a></h4><h5 id="财务比率分析概述">财务比率分析概述<a class="headerlink" href="#财务比率分析概述"></a></h5><div class="tabs" id="financial-ratios-analysis"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#financial-ratios-analysis-1">概念和表现形式</button></li><li class="tab"><button type="button" data-href="#financial-ratios-analysis-2">常用的指标</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="financial-ratios-analysis-1"><p>财务比率分析指用财务比率来描述企业财务状况、盈利能力以及流动性的分析方法。</p><p>财务比率通常表现为比值形式,由不同的会计数据计算形成。这种计算方法消除了企业规模的影响,适用于比较不同行业、不同规模企业之间的财务状况,对同一企业各期变动情况的比较也起着重要作用。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="financial-ratios-analysis-2"><ol><li>流动性比率。包括流动比率和速动比率。</li><li>财务杠杆比率。包括资产负债率、权益乘数和负债权益比、利息倍数。</li><li>营运效率比率。包括存货周转率、应收账款周转率、总资产周转率。</li><li>盈利能力比率。包括销售利润率、资产收益率、净资产收益率。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h5 id="流动性比率">流动性比率<a class="headerlink" href="#流动性比率"></a></h5><div class="tabs" id="liquidity-ratio"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#liquidity-ratio-1">概述</button></li><li class="tab"><button type="button" data-href="#liquidity-ratio-2">常用的指标</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="liquidity-ratio-1"><ol><li>概念:流动性比率是用来衡量企业的短期偿债能力的比率。</li><li>流动性比率重点关注的是企业的流动资产和流动负债。<ol><li>流动资产。主要包括现金及现金等价物、应收票据、应收账款和存货等。他们能够在短期内快速变现,因而流动性很强。</li><li>流动负债。主要包括短期借款、应付票据、应付账款等。</li></ol></li><li>企业的流动资产和流动负债的共同特征:由于存续期较短,它们的市场价值与账面价值通常较接近。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="liquidity-ratio-2"><ul><li>流动比率。即流动资产对于流动负债的覆盖率。<ul><li>计算公式:<img src="https://img.imql.life/illustrations/7ee76096f1a768965b2898467b8fd51e.svg" alt=""></li><li>当流动比率大于 2 时,即使只有一半流动资产能在短期内变现,企业也可以足额偿付其短期债务。</li><li>对于短期债权人来说,流动比率越高越好,因为越高意味者他们收回债款的风险越低。</li><li>对于企业来说,流动比率并非越高越好。流动资产比例过大会影响企业的经营获利或者投资盈利状况。</li></ul></li><li>速动比率。体现企业流动资产除去存货后的流动性状况。<ul><li>计算公式:<img src="https://img.imql.life/illustrations/571419e039729f91deb7e46106830f99.svg" alt=""></li><li>速动比率总是不大于流动比率,对于短期偿债能力的衡量,速动比率比流动比率更加直观可信。通常,速动比率大于 1 时,企业才能维持较好的短期偿债能力和财务稳定状况。流动资产的内部转换不会改变流动比率,但可能改变速动比率。</li></ul></li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h5 id="财务杠杆比率">财务杠杆比率<a class="headerlink" href="#财务杠杆比率"></a></h5><div class="tabs" id="financial-leverage-ratio"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#financial-leverage-ratio-1">概念</button></li><li class="tab"><button type="button" data-href="#financial-leverage-ratio-2">常用的指标</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="financial-leverage-ratio-1"><p>财务杠杆比率衡量的是企业长期偿债能力。由于企业的长期负债与企业的资本结构即使用的财务杠杆有关,所有称为财务杠杆比率。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="financial-leverage-ratio-2"><ul><li>资产负债率,是负债总额(包括短期负债和长期负债)占总资产的比例。<ul><li>计算公式:<img src="https://img.imql.life/illustrations/5ebeedb9b38e466f0c4a4addffa15186.svg" alt=""></li><li>资产负债率是日常使用频率最高的债务比率。资产负债率难以精确计算决定,可通过对同业企业的比较进行参考,其余情况下,应该根据企业具体的资本结构与价值关系,遵循适中原则进行判断。</li></ul></li><li>权益乘数和负债权益比,是由资产负债率衍生出来的两个重要比率。<ul><li>计算公式:<img src="https://img.imql.life/illustrations/ef4bda2360379cc3e8b77e4e6c4a9f7c.svg" alt=""><img src="https://img.imql.life/illustrations/41e288114c21d35795b0f5d3fa7b4ea8.svg" alt=""></li></ul></li><li>利息倍数,衡量企业对于长期债务利息保障程度。<ul><li>计算公式:<img src="https://img.imql.life/illustrations/824702353a0fe25d3e3a94a1607dbb71.svg" alt=""></li><li>EBIT 是息税前利润。对于债权人来说,利息倍数越高越安全。对于举债经营的企业来说,为了维持正常的偿债能力,利息倍数至少应该为 1,并且越高越好。若利息倍数过低,企业将面临亏损、偿债的稳定性与安全性下降的风险。</li></ul></li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h5 id="营运效率比率">营运效率比率<a class="headerlink" href="#营运效率比率"></a></h5><div class="tabs" id="operational-efficiency-ratio"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#operational-efficiency-ratio-1">概述</button></li><li class="tab"><button type="button" data-href="#operational-efficiency-ratio-2">常用的指标</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="operational-efficiency-ratio-1"><ol><li>概念:营运效率用来体现企业经营期间的资产从投入到产出的流转速度,可以反映企业资产的管理质量和利用效率。</li><li>营运效率比率可以分成两类。<ol><li>短期比率。这类比率主要考查存货和应收账款两部分的使用效率,即存货周转率、应收账款周转率。</li><li>长期比率。主要指的是总资产周转率,考查的是企业账面上所有资产的使用效率。</li></ol></li><li>企业的流动资产和流动负债的共同特征:由于存续期较短,它们的市场价值与账面价值通常较接近。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="operational-efficiency-ratio-2"><ul><li>存货周转率。存货周转率显示了企业在一年或者 1 个经营周期内存货的周转次数。<ul><li>计算公式:<img src="https://img.imql.life/illustrations/27faad79562dc74adcac666465fece4a.svg" alt=""><img src="https://img.imql.life/illustrations/15b9c3726362c4b327572badfda32bc9.svg" alt=""></li><li>存货周转率越大,说明存货销售、变现所用的时间越短,存货管理效率越高。</li></ul></li><li>应收账款周转率。应收账款周转率显示了企业在一年或者 1 个经营周期内应收账款的周转次数。<ul><li>计算公式:<img src="https://img.imql.life/illustrations/1f2ba73ab14c714c7ec16091ca39e6cb.svg" alt=""><img src="https://img.imql.life/illustrations/c49405712a41c566accd36ec6acb63c3.svg" alt=""></li><li>应收账款周转率越大,说明应收账款变现、销售收入收回所需的时间越短。</li></ul></li><li>总资产周转率:衡量的是一家企业所有资产的使用效率。<ul><li>计算公式:<img src="https://img.imql.life/illustrations/d321ffd6be928d94660909845f4d08fb.svg" alt=""></li><li>总资产周转率越大,说明企业的销售能力越强,资产利用效率越高。</li></ul></li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h5 id="盈利能力利率">盈利能力利率<a class="headerlink" href="#盈利能力利率"></a></h5><div class="tabs" id="profitability-rate"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#profitability-rate-1">概念</button></li><li class="tab"><button type="button" data-href="#profitability-rate-2">常用的指标</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="profitability-rate-1"><p>财务杠杆比率衡量的是企业长期偿债能力。由于企业的长期负债与企业的资本结构即使用的财务杠杆有关,所有称为财务杠杆比率。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="profitability-rate-2"><ul><li>资产负债率,是负债总额(包括短期负债和长期负债)占总资产的比例。<ul><li>计算公式:<img src="https://img.imql.life/illustrations/5ebeedb9b38e466f0c4a4addffa15186.svg" alt=""></li><li>资产负债率是日常使用频率最高的债务比率。资产负债率难以精确计算决定,可通过对同业企业的比较进行参考,其余情况下,应该根据企业具体的资本结构与价值关系,遵循适中原则进行判断。</li></ul></li><li>权益乘数和负债权益比,是由资产负债率衍生出来的两个重要比率。<ul><li>计算公式:<img src="https://img.imql.life/illustrations/ef4bda2360379cc3e8b77e4e6c4a9f7c.svg" alt=""><img src="https://img.imql.life/illustrations/41e288114c21d35795b0f5d3fa7b4ea8.svg" alt=""></li></ul></li><li>利息倍数,衡量企业对于长期债务利息保障程度。<ul><li>计算公式:<img src="https://img.imql.life/illustrations/824702353a0fe25d3e3a94a1607dbb71.svg" alt=""></li><li>EBIT 是息税前利润。对于债权人来说,利息倍数越高越安全。对于举债经营的企业来说,为了维持正常的偿债能力,利息倍数至少应该为 1,并且越高越好。若利息倍数过低,企业将面临亏损、偿债的稳定性与安全性下降的风险。</li></ul></li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h3 id="货币的时间价值与利率">货币的时间价值与利率<a class="headerlink" href="#货币的时间价值与利率"></a></h3><h3 id="常用的描述性统计概念">常用的描述性统计概念<a class="headerlink" href="#常用的描述性统计概念"></a></h3><h2 id="权益投资">权益投资<a class="headerlink" href="#权益投资"></a></h2><h3 id="资本结构">资本结构<a class="headerlink" href="#资本结构"></a></h3><h3 id="权益类证券">权益类证券<a class="headerlink" href="#权益类证券"></a></h3><h4 id="股票(掌握)">股票(掌握)<a class="headerlink" href="#股票(掌握)"></a></h4><h4 id="存托凭证">存托凭证<a class="headerlink" href="#存托凭证"></a></h4><h4 id="可转换债券(重点掌握)">可转换债券(重点掌握)<a class="headerlink" href="#可转换债券(重点掌握)"></a></h4><h4 id="权证">权证<a class="headerlink" href="#权证"></a></h4><h2 id="固定收益投资">固定收益投资<a class="headerlink" href="#固定收益投资"></a></h2><h3 id="债券与债券市场">债券与债券市场<a class="headerlink" href="#债券与债券市场"></a></h3><h4 id="债券市场概述(重点掌握)">债券市场概述(重点掌握)<a class="headerlink" href="#债券市场概述(重点掌握)"></a></h4><h4 id="债券的种类(重点掌握)">债券的种类(重点掌握)<a class="headerlink" href="#债券的种类(重点掌握)"></a></h4><h4 id="债券违约时的受偿顺序(掌握)">债券违约时的受偿顺序(掌握)<a class="headerlink" href="#债券违约时的受偿顺序(掌握)"></a></h4><h4 id="投资债券的风险(重点掌握)">投资债券的风险(重点掌握)<a class="headerlink" href="#投资债券的风险(重点掌握)"></a></h4><h5 id="中国债券交易市场体系(理解)">中国债券交易市场体系(理解)<a class="headerlink" href="#中国债券交易市场体系(理解)"></a></h5><h3 id="债券价值的分析">债券价值的分析<a class="headerlink" href="#债券价值的分析"></a></h3><h4 id="债券的估值方法(掌握)">债券的估值方法(掌握)<a class="headerlink" href="#债券的估值方法(掌握)"></a></h4><h4 id="债券的收益率(重点掌握)">债券的收益率(重点掌握)<a class="headerlink" href="#债券的收益率(重点掌握)"></a></h4><h4 id="利率期限结构、债券收益率曲线(理解)">利率期限结构、债券收益率曲线(理解)<a class="headerlink" href="#利率期限结构、债券收益率曲线(理解)"></a></h4><div class="tabs" id="term-structure-of-interest-rate"><ul class="nav-tabs"><li class="tab"><button type="button" data-href="#term-structure-of-interest-rate-1">利率期限结构</button></li><li class="tab"><button type="button" data-href="#term-structure-of-interest-rate-2">收益率曲线</button></li></ul><div class="tab-contents"><div class="tab-item-content" id="term-structure-of-interest-rate-1"><p>利率期限结构是指在某一时点上,各种不同期限债券的收益率和到期期限之间的关系,将这种关系在以期限为横坐标、收益率为纵坐标的直角坐标系上表示出来,就得到收益率曲线。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="term-structure-of-interest-rate-2"><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h4 id="信用利差(理解)">信用利差(理解)<a class="headerlink" href="#信用利差(理解)"></a></h4><div class="tabs" id="credit-spreads"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#credit-spreads-1">信用利差概述</button></li><li class="tab"><button type="button" data-href="#credit-spreads-2"><Tab名2></button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="credit-spreads-1"><ol><li>信用利差是指除了信用评级不同外,其他所有方面都相同(包括但不限于期限、嵌入条款等)的两种债券收益率之间的差额。一般而言,投资者会要求更高的收益来补偿较高的违约风险,即违约风险越高,投资收益率也</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="credit-spreads-2"><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h3 id="货币市场工具">货币市场工具<a class="headerlink" href="#货币市场工具"></a></h3><h4 id="货币市场工具概述">货币市场工具概述<a class="headerlink" href="#货币市场工具概述"></a></h4><div class="tabs" id="currency-market-tool"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#currency-market-tool-1">定义</button></li><li class="tab"><button type="button" data-href="#currency-market-tool-2">功能</button></li><li class="tab"><button type="button" data-href="#currency-market-tool-3">特点</button></li><li class="tab"><button type="button" data-href="#currency-market-tool-4">种类</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="currency-market-tool-1"><p>货币市场工具一般指短期的(一年之内)、具有高流动性的低风险证券,具体包括银行间回购协议、定期存款、商业票据、银行承兑汇票、短期国债、中央银行票据等。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="currency-market-tool-2"><ol><li>货币市场工具为商业银行管理流动性以及企业融通短期资金提供了有效的手段。</li><li>因货币市场工具交易而形成的短期利率在整个市场的利率体系中充当了基准利率,为市场上其余证券利率的确定提供了重要的参考依据,是判断市场上银根松紧程度的重要指标。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="currency-market-tool-3"><ol><li>均是债务契约。</li><li>期限在一年以内(含一年)。</li><li>流动性高。</li><li>为大宗交易。主要由机构投资者参与,个人投资者很少有机会参与买卖。</li><li>本金安全性高,风险较低。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="currency-market-tool-4"><ol><li></li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h2 id="衍生工具">衍生工具<a class="headerlink" href="#衍生工具"></a></h2><h2 id="另类投资">另类投资<a class="headerlink" href="#另类投资"></a></h2><h2 id="投资管理流程与投资者需求">投资管理流程与投资者需求<a class="headerlink" href="#投资管理流程与投资者需求"></a></h2><h2 id="投资组合管理">投资组合管理<a class="headerlink" href="#投资组合管理"></a></h2><h2 id="投资交易管理">投资交易管理<a class="headerlink" href="#投资交易管理"></a></h2><h2 id="投资风险管理">投资风险管理<a class="headerlink" href="#投资风险管理"></a></h2><h3 id="市场风险">市场风险<a class="headerlink" href="#市场风险"></a></h3><h4 id="类型">类型<a class="headerlink" href="#类型"></a></h4><div class="tabs" id="the-type-of-market-risk"><ul class="nav-tabs"><li class="tab"><button type="button" data-href="#the-type-of-market-risk-1">政策风险</button></li><li class="tab"><button type="button" data-href="#the-type-of-market-risk-2">经济周期性波动风险</button></li><li class="tab"><button type="button" data-href="#the-type-of-market-risk-3">利率风险</button></li><li class="tab"><button type="button" data-href="#the-type-of-market-risk-4">购买力风险</button></li><li class="tab"><button type="button" data-href="#the-type-of-market-risk-5">汇率风险</button></li></ul><div class="tab-contents"><div class="tab-item-content" id="the-type-of-market-risk-1"><p>政策风险是指因宏观政策的变化导致的对基金收益的影响,宏观政策包括财政政策、产业政策、货币政策等,政策风险的管理主要在于对国家宏观政策的把握与预测经济周期性。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="the-type-of-market-risk-2"><p>经济发展有一定周期性,由于基金投资的是金融市场已存在的金融工具,所以基金便会追随经济总体趋向而发生变动,如当经济处于低迷时期,基金行情也会随之处于低迷状态。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="the-type-of-market-risk-3"><p>利率风险指的是因利率变化而产生的基金价值的不确定性。利率变动主要受通货膨胀预期、中央银行的货币政策、经济周期和国际利率水平等的影响。利率变动是不确定的,经常发生,并且利率变动是一个积累的过程,因此利率风险具备一定隐蔽性。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="the-type-of-market-risk-4"><p>购买力风险指的是作为基金利润主要分配形式的现金,可能由于通货膨胀等因素的影响而导致购买力下降,降低基金实际收益,使投资者收益率降低的风险,又称为通货膨胀风险。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="the-type-of-market-risk-5"><p>汇率风险指的是因汇率变动而产生的基金价值的不确定性。影响汇率的因素有国际收支及外汇储备、利率、通货膨胀和政治局势等。合格境内机构投资者(QDII)基金由于涉及外汇业务对汇率反应较为敏感。当投资境外的市场时,基金面临最大的风险就是汇率风险。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h4 id="主要管理措施">主要管理措施<a class="headerlink" href="#主要管理措施"></a></h4><ol><li>密切关注宏观经济指标和趋势</li><li>密切关注行业的周期性、市场竞争、价格、政策环境</li><li>关注投资组合的风险调整后收益</li><li>加强对场外交易的监控</li><li>加强对重大投资的监测</li><li>运用定量风险模型和优化技术</li></ol><h3 id="信用风险">信用风险<a class="headerlink" href="#信用风险"></a></h3><h3 id="流动性风险">流动性风险<a class="headerlink" href="#流动性风险"></a></h3><h3 id="投资风险的测度">投资风险的测度<a class="headerlink" href="#投资风险的测度"></a></h3><h4 id="风险指标">风险指标<a class="headerlink" href="#风险指标"></a></h4><div class="tabs" id="risk-indicators"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#risk-indicators-1">概述</button></li><li class="tab"><button type="button" data-href="#risk-indicators-2"><Tab名2></button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="risk-indicators-1"><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="risk-indicators-2"><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h2 id="基金业绩评价">基金业绩评价<a class="headerlink" href="#基金业绩评价"></a></h2><h2 id="基金的投资交易与结算">基金的投资交易与结算<a class="headerlink" href="#基金的投资交易与结算"></a></h2><h2 id="基金的估值、费用与会计核算">基金的估值、费用与会计核算<a class="headerlink" href="#基金的估值、费用与会计核算"></a></h2><h3 id="基金资产估值">基金资产估值<a class="headerlink" href="#基金资产估值"></a></h3><h4 id="相关概念">相关概念<a class="headerlink" href="#相关概念"></a></h4><h2 id="基金的利润分配与税收">基金的利润分配与税收<a class="headerlink" href="#基金的利润分配与税收"></a></h2><h2 id="基金国际化的发展概况">基金国际化的发展概况<a class="headerlink" href="#基金国际化的发展概况"></a></h2>]]></content>
<categories>
<category> 2022年基金从业资格证备考 </category>
</categories>
</entry>
<entry>
<title>基金法律法规、职业道德与业务规范</title>
<link href="/2022/05/28/Fund_Laws_and_Regulations_Professional_Ethics_and_Business_Norms/"/>
<url>/2022/05/28/Fund_Laws_and_Regulations_Professional_Ethics_and_Business_Norms/</url>
<content type="html"><![CDATA[<p>金融、资产管理与投资基金;证券投资基金概述;证券投资基金的类型;证券投资基金的监管;基金职业道德;基金的募集、交易与登记; 基金的信息披露;基金客户和销售机构;基金销售行为规范及信息管理;基金客户服务;基金管理人公司治理和风险管理;基金管理人的内部控制;基金管理人的合规管理。</p><span id="more"></span><h2 id="金融市场、资产管理与投资基金">金融市场、资产管理与投资基金<a class="headerlink" href="#金融市场、资产管理与投资基金"></a></h2><h3 id="居民理财与金融市场">居民理财与金融市场<a class="headerlink" href="#居民理财与金融市场"></a></h3><h4 id="金融与居民理财(理解)">金融与居民理财(理解)<a class="headerlink" href="#金融与居民理财(理解)"></a></h4><ul><li>金融:货币资金的融通,货币资金是在居民从事生产活动过程中产生的。</li><li>居民:社会最古老、最基本的经济主体,包括个人和企业。</li><li>理财:通过对账务进行管理,实现财产的保值、增值。目前居民理财主要方式有两类,即货币储蓄与投资。</li><li>储蓄:具有保值性特征,是指居民将暂时不用或结余的货币收入存入银行或其他金融机构,以保证本金安全,并期望获得一定利息收益的一种存款活动。</li><li>投资:未来收益具有不确定性,是指投资者当期投入一定数额的资金而期望在未来获得回报,所得的回报应该能补偿投资资金被占用的时间、预期的通货膨胀率以及期望更多的未来收益。最普遍的投资产品包括股票、债券、基金等。</li></ul><h4 id="金融市场(掌握)">金融市场(掌握)<a class="headerlink" href="#金融市场(掌握)"></a></h4><h5 id="分类">分类<a class="headerlink" href="#分类"></a></h5><div class="tabs" id="category"><ul class="nav-tabs"><li class="tab"><button type="button" data-href="#category-1">按交易工具期限划分</button></li><li class="tab"><button type="button" data-href="#category-2">按交易标的物划分</button></li><li class="tab"><button type="button" data-href="#category-3">按交割期限划分</button></li><li class="tab"><button type="button" data-href="#category-4">按交易性质划分</button></li><li class="tab"><button type="button" data-href="#category-5">按地理范围划分</button></li></ul><div class="tab-contents"><div class="tab-item-content" id="category-1"><ul><li>货币市场(短期金融市场):专门融通一年以内短期资金的场所。典型的货币市场有同业拆借市场、回购协议市场、票据市场、大额可转让定期存单市场等。</li><li>资本市场(长期金融市场):以期限在一年以上的有价证券为交易工具进行长期资金交易的市场。<ul><li>广义的资本市场:银行中长期存贷款市场和有价证券市场(中长期债券市场和股票市场)。</li><li>狭义的资本市场:专指中长期债券市场和股票市场。</li></ul></li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="category-2"><ul><li>票据市场:各种票据进行交易的场所,按其交易方式可划分为<a href="https://baike.baidu.com/item/%E7%A5%A8%E6%8D%AE%E6%89%BF%E5%85%91%E5%B8%82%E5%9C%BA/10852887">票据承兑市场</a>和<a href="https://baike.baidu.com/item/%E7%A5%A8%E6%8D%AE%E8%B4%B4%E7%8E%B0%E5%B8%82%E5%9C%BA/10852894">贴现市场</a>。</li><li>证券市场:股票、债券、基金等有价证券发行和转让流通的市场。</li><li>衍生工具市场:各种衍生金融工具进行交易的市场。其中,衍生金融工具主要包括远期合约、期货合约、期权合约和互换协议等。</li><li>外汇市场:各国中央银行、外汇银行、外汇经纪人及客户组成的外汇买卖、经营活动的总和。</li><li>黄金市场:专门集中进行黄金买卖的交易中心或场所。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="category-3"><ul><li>现货市场:交易协议达成后在两个交易日内进行交割的市场。</li><li>期货市场:交易在协议达成后并不立刻交割,而是约定在某一特定时间后进行交割的市场。期货市场协议成交和标的交割是分离的。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="category-4"><ul><li>发行市场(一级市场):筹集资金的公司或政府机构将其新发行的股票和债券等证券销售给最初购买者的金融市场。</li><li>流通市场(二级市场):已经发行的证券进行买卖、转让和流通的市场。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="category-5"><ul><li>国内金融市场:一国范围内的资金融通与资金交易的市场,通常仅由国内金融机构参与,不会涉及货币资金的跨境流动。可分为全国性、区域性及地方性的金融市场。</li><li>国际金融市场:国家与国家之间的资金融通与资金交易的市场,涉及货币资金的跨境流动,由经营国家间货币业务的金融机构组成,其经营内容广泛,包括跨境的资金借贷、外汇买卖、证券买卖、资金交易等。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h5 id="构成要素">构成要素<a class="headerlink" href="#构成要素"></a></h5><div class="tabs" id="element"><ul class="nav-tabs"><li class="tab"><button type="button" data-href="#element-1">市场参与者</button></li><li class="tab"><button type="button" data-href="#element-2">金融工具</button></li><li class="tab"><button type="button" data-href="#element-3">金融交易的组织方式</button></li></ul><div class="tab-contents"><div class="tab-item-content" id="element-1"><p>金融市场的参与者有政府、中央银行、金融机构、企业和个人居民等。其中,金融机构和个人居民的角色最为重要。</p><p>金融机构在金融市场具有支配性作用,是最重要的中间机构,也是储蓄转化为投资的重要渠道,在金融市场上充当资金的供给者、需求者和中间人等多重角色。</p><p>个人居民是金融市场上主要的资金供给者,也是维持金融市场供求均衡的重要力量。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="element-2"><ul><li>地位:金融工具是金融市场上进行交易的载体,最初被称为信用工具,是证明债权债务关系并据以进行货币资金交易的合法凭证。</li><li>性质:金融工具是法律契约,交易双方的权利和义务受法律保护。具有广泛的社会可接受性,流通转让性强。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="element-3"><ul><li>场内交易方式:有固定场所、有制度、集中进行交易,在我国主要指交易所的交易方式。</li><li>场外交易方式:在证券交易所之外各金融机构柜台上买卖双方进行面议、分散交易,如柜台交易方式。我国典型的场外交易市场有银行间债券市场、代办股份转让系统、债券柜台交易市场等。</li><li>电信网络交易方式:没有固定场所,交易双方也不直接接触,主要借助电子通信或互联网络技术手段来完成交易。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h5 id="监管">监管<a class="headerlink" href="#监管"></a></h5><div class="tabs" id="supervision"><ul class="nav-tabs"><li class="tab"><button type="button" data-href="#supervision-1">“市场失灵”的表现</button></li><li class="tab"><button type="button" data-href="#supervision-2">我国金融市场的监管体系</button></li></ul><div class="tab-contents"><div class="tab-item-content" id="supervision-1"><ol><li>外部性问题;</li><li>脆弱性问题;</li><li>不完全竞争问题;</li><li>信息不对成问题。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="supervision-2"><p>我国金融市场监管采取的是银行保险业、证券业分业监管的模式。</p><ol><li>在国务院的领导下,中国人民银行作为中央银行,承担宏观监管职责。</li><li>中国银行保险监督管理委员会、中国证监会分别对银行业、保险业金融机构和证券业金融机构及这些机构的业务活动实施监督管理。</li><li>交易所、行业协会等自律机构在各自范围内实施自律管理。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h3 id="金融资产与资产管理行业">金融资产与资产管理行业<a class="headerlink" href="#金融资产与资产管理行业"></a></h3><h4 id="金融资产(掌握)">金融资产(掌握)<a class="headerlink" href="#金融资产(掌握)"></a></h4><div class="tabs" id="financial-assets"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#financial-assets-1">概念</button></li><li class="tab"><button type="button" data-href="#financial-assets-2">分类</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="financial-assets-1"><p>金融资产是一种凭证,不但代表了未来收益或资产的合法要求权,标示了明确的价值,而且表明了交易双方的所有权关系和债权关系。</p><p>来源:资金的供给者主要通过投资金融工具获得各种类型的金融资产。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="financial-assets-2"><ul><li>债券类金融资产:以票据、债券等契约型投资工具为主。</li><li>股权类金融资产:以各类股票为主。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h4 id="资产管理(理解)">资产管理(理解)<a class="headerlink" href="#资产管理(理解)"></a></h4><div class="tabs" id="asset-management"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#asset-management-1">概念</button></li><li class="tab"><button type="button" data-href="#asset-management-2">特征</button></li><li class="tab"><button type="button" data-href="#asset-management-3">本质</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="asset-management-1"><p>资产管理是指金融机构受投资者委托进行证券和其他金融产品的投资并提供金融资产管理服务、收取费用的行为。其目的是实现投资者的特定目标和利益。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="asset-management-2"><ol><li>从参与方角度来看:包括委托方(投资者)和受托方(资产管理人)两大参与方,受托方根据委托方授权,进行资产投资管理,承担受托人义务。</li><li>从受托资产角度开看:受托资产主要是货币等金融资产。</li><li>从管理方式角度来看:主要通过投资于银行存款、证券、期货、基金、保险、实体企业股权以及其他可被证券化的资产实现增值。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="asset-management-3"><ul><li>本质:受入之托、代人理财。<ul><li>一切资产管理活动都要求所获取的收益与所承担的风险相匹配。</li><li>管理人必须坚持“卖者有责”,受人之托、忠人之事,做到诚实守信、勤勉尽责、实事求是。</li><li>投资人必须做到“买者自负”,不存在任何保底保收益等“刚性兑付”行为。</li></ul></li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h4 id="资产管理行业(重点掌握)">资产管理行业(重点掌握)<a class="headerlink" href="#资产管理行业(重点掌握)"></a></h4><div class="tabs" id="asset-management-industry"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#asset-management-industry-1">范围</button></li><li class="tab"><button type="button" data-href="#asset-management-industry-2">作用</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="asset-management-industry-1"><p>资产管理行业涉及面非常广泛,包括银行、证券、保险、基金、信托、期货等行业,但是具体范围目前仍无明确界定。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="asset-management-industry-2"><ol><li>对于市场经济来说:资产管理行业能够为市场经济体系有效配置资源,提高整个社会经济的效率和生产服务水平,能对金融资产进行合理定价,给金融市场提供流动性,降低交易成本,使金融市场更加健康,最终有利于一国经济的发展。</li><li>对于企业和个人来说:资产管理行业能够帮助投资者搜集、处理各种和投资有关的信息,提供各类投资机会,帮助投资者进行投资决策,并提供决策的最佳执行服务,使投资融资更加便利,创造出十分广泛的投资产品和服务,满足投资者的各种投资需求,使资金的需求方和提供方能够便利地连接起来。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h3 id="我国资产管理行业的状况">我国资产管理行业的状况<a class="headerlink" href="#我国资产管理行业的状况"></a></h3><h4 id="我国资产管理行业概况">我国资产管理行业概况<a class="headerlink" href="#我国资产管理行业概况"></a></h4><div class="tabs" id="asset-management-industry-of-china"><ul class="nav-tabs"><li class="tab"><button type="button" data-href="#asset-management-industry-of-china-1">传统的资产管理行业</button></li><li class="tab"><button type="button" data-href="#asset-management-industry-of-china-2">我国资产管理行业的状况</button></li></ul><div class="tab-contents"><div class="tab-item-content" id="asset-management-industry-of-china-1"><ol><li>基金管理公司提供各类公募基金、私募基金。</li><li>信托公司提供各类信托计划。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="asset-management-industry-of-china-2"><p>现状:机构投资者广泛参与,各类资产管理业务交叉融合。除传统的基金管理公司和信托公司外,银行、证券、保险等各类金融机构也开展资产管理业务,券商资产管理计划、保险资产管理计划、期货资产管理计划、银行理财等各种资产管理产品也迅速发展。</p><p>形成原因:居民个人财富不断积累、金融监管机构对资产管理的金融管制逐渐放松和投资者理财需求不断上升。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h4 id="我国各类资产管理业务简介(掌握)">我国各类资产管理业务简介(掌握)<a class="headerlink" href="#我国各类资产管理业务简介(掌握)"></a></h4><div class="tabs" id="various-asset-management-business-of-china"><ul class="nav-tabs"><li class="tab"><button type="button" data-href="#various-asset-management-business-of-china-1">证券投资基金管理公司及其子公司资产管理业务</button></li><li class="tab"><button type="button" data-href="#various-asset-management-business-of-china-2">私募机构资产管理业务</button></li></ul><div class="tab-contents"><div class="tab-item-content" id="various-asset-management-business-of-china-1"><ol><li>证券投资基金管理公司是经国务院证券监督管理机构批准,在中国境内设立,从事证券投资基金管理业务和国务院证券监督管理机构许可的其他业务的企业法人。</li><li>业务:<ol><li>公开募集基金:向不特定对象募集资金或者向特定对象募集资金累计超过 200 人以及法律、行政法规规定的其他情形。</li><li>特定客户资产管理业务:向特定客户募集资金或者接受特定客户财产委托担任资产管理人,托管机构担任资产托管人,运用委托财产进行投资,为资产委托人获取利益的活动。特定客户资产管理业务可以分为为单一客户办理特定资产管理业务和为多个客户办理特定资产管理业务。<ol><li>为单一客户办理特定资产管理业务:客户委托的初始资产不得低于 3000 万元,国务院证券监督管理机构另有规定的除外。</li><li>为多个客户办理特定资产管理业务:单个资产管理计划的委托人不得超过 200 人,但单笔委托金额在 300 万元以上的不受此限制;客户委托的初始资产合计应在 3000 万元~50 亿元,国务院证券监督管理机构另有规定的除外。</li></ol></li><li>专项资产管理计划:基金管理人设立专门的子公司,投资于未通过证券交易所转让的股权、债券及其他财产权利以及中国证监会认可的其他资产的特点资产管理计划。</li><li>私募股权基金管理业务 :基金管理人可以设立专门子公司,通过设立特殊目的机构或者设立合伙企业或者公司形式的私募股权投资基金来从事私募股权投资基金管理业务。</li></ol></li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="various-asset-management-business-of-china-2"><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h3 id="投资基金简介">投资基金简介<a class="headerlink" href="#投资基金简介"></a></h3><h4 id="投资基金的含义(掌握)">投资基金的含义(掌握)<a class="headerlink" href="#投资基金的含义(掌握)"></a></h4><div class="tabs" id="investment-funds"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#investment-funds-1">含义</button></li><li class="tab"><button type="button" data-href="#investment-funds-2">方式</button></li><li class="tab"><button type="button" data-href="#investment-funds-3">性质</button></li><li class="tab"><button type="button" data-href="#investment-funds-4">可投资的资产</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="investment-funds-1"><p>投资基金是指通过向投资者发行受益凭证(基金份额),将社会上的资金集中起来,交由专业的基金管理机构投资于各种资产,实现保值增值的一种资产管理方式。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="investment-funds-2"><p>组合投资、专业管理、利益共享、风险共担的集合投资方式。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="investment-funds-3"><p>属于间接投资工具。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="investment-funds-4"><ul><li>金融资产,包括股票、债券、外汇、股权、期货、期权等。</li><li>其它资产,包括房地产、大宗能源、林权、艺术品等。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h4 id="投资基金的主要类别(掌握)">投资基金的主要类别(掌握)<a class="headerlink" href="#投资基金的主要类别(掌握)"></a></h4><div class="tabs" id="main-category"><ul class="nav-tabs"><li class="tab"><button type="button" data-href="#main-category-1">按资金募集方式划分</button></li><li class="tab"><button type="button" data-href="#main-category-2">按法律形式划分</button></li><li class="tab"><button type="button" data-href="#main-category-3">按运作方式划分</button></li><li class="tab"><button type="button" data-href="#main-category-4">按所投资的对象划分</button></li></ul><div class="tab-contents"><div class="tab-item-content" id="main-category-1"><ol><li>公募基金:已公开方式发售基金份额募集资金设立的证券投资基金,又称“公开募集基金”,包含向不特定对象募集资金、向特定对象募集资金累计超过 200 人以及法律、行政法规规定的其他情形。</li><li>私募基金:以非公开方式向合格投资者募集资金设立的证券投资基金,又称“非公开募集基金”。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="main-category-2"><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="main-category-3"><p>属于间接投资工具。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="main-category-4"><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h2 id="证券投资基金概述">证券投资基金概述<a class="headerlink" href="#证券投资基金概述"></a></h2><h3 id="证券投资基金的含义和特点">证券投资基金的含义和特点<a class="headerlink" href="#证券投资基金的含义和特点"></a></h3><h4 id="证券投资基金的含义">证券投资基金的含义<a class="headerlink" href="#证券投资基金的含义"></a></h4><div class="tabs" id="meaning"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#meaning-1">含义</button></li><li class="tab"><button type="button" data-href="#meaning-2">理解</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="meaning-1"><p>证券投资基金是指通过发售基金份额,将众多投资者的资金汇集起来,形成独立财产,委托基金管理人进行投资管理,基金托管人进行财产托管,由基金投资人共享投资收益、共担投资风险的集合投资方式。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="meaning-2"><ol><li>本质上是间接通过基金管理人代理投资的一种方式。</li><li>基金管理人和基金托管人可以按照基金的资产规模获得一定比例的管理费收入和托管费收入。</li><li>证券投资基金在世界各国的称谓有所不同。</li></ol><ul><li>在美国称“共同基金”。</li><li>在英国和中国香港特别行政区称“单位信托基金”。</li><li>在欧洲一些国家和地区称“集合投资基金”或“集合投资计划”。</li><li>在日本和中国台湾地区称“证券投资信托基金”。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h4 id="证券投资基金的特点(重点掌握)">证券投资基金的特点(重点掌握)<a class="headerlink" href="#证券投资基金的特点(重点掌握)"></a></h4><div class="tabs" id="characteristic"><ul class="nav-tabs"><li class="tab"><button type="button" data-href="#characteristic-1">集合理财、专业管理</button></li><li class="tab"><button type="button" data-href="#characteristic-2">组合投资、分散风险</button></li><li class="tab"><button type="button" data-href="#characteristic-3">利益共享、风险共担</button></li><li class="tab"><button type="button" data-href="#characteristic-4">严格监管、信息透明</button></li><li class="tab"><button type="button" data-href="#characteristic-5">独立托管、保障安全</button></li></ul><div class="tab-contents"><div class="tab-item-content" id="characteristic-1"><ol><li>特点集合理财表现在将众多投资者的资金汇集起来,委托基金管理人集中进行投资,这样可以发挥资金的规模优势,降低投资成本。</li><li>特点专业管理表现在基金管理人拥有更为专业的软、硬件资源,能够更好地对证券市场进行全方位的动态跟踪与深入分析。这样,中小投资者也能享受到专业化的投资管理服务。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="characteristic-2"><p>基金通常会购买多种股票组合投资,投资者购买基金就相当于用很少的资金购买一篮子股票,在市场不利时,能够有效降低风险;在市场有利时,能够享受到组合投资带来的利益。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="characteristic-3"><p>基金投资所产生的风险和利益均由所有投资者按比例进行分配,基金管理人和基金托管人作为提供服务的机构,一般按基金合同的规定从基金资产中收取一定比例的管理费、托管费,并不参与基金收益的分配,也不承担基金投资产生的风险。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="characteristic-4"><p>基金监管机构对证券投资基金业实行严格的监管制度,并强制基金进行及时、准确、充分的信息披露。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="characteristic-5"><p>基金管理人负责基金的投资操作,基金托管人负责基金财产的保管,形成相互制约、相互监督的制衡机制,保障投资者资金的安全。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h4 id="证券投资基金与其他金融工具的比较(重点掌握)">证券投资基金与其他金融工具的比较(重点掌握)<a class="headerlink" href="#证券投资基金与其他金融工具的比较(重点掌握)"></a></h4><p>基金与股票、债券的比较:</p><div class="tabs" id="comparison-with-stocks-&-bonds"><ul class="nav-tabs"><li class="tab"><button type="button" data-href="#comparison-with-stocks-&-bonds-1">反映的经济关系不同</button></li><li class="tab"><button type="button" data-href="#comparison-with-stocks-&-bonds-2">所筹资金的投向不同</button></li><li class="tab"><button type="button" data-href="#comparison-with-stocks-&-bonds-3">投资收益和风险大小不同</button></li></ul><div class="tab-contents"><div class="tab-item-content" id="comparison-with-stocks-&-bonds-1"><ul><li>基金:信托关系,是一种受益凭证。</li><li>所有权关系,是一种所有权凭证。</li><li>债券债务关系,是一种债权凭证。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="comparison-with-stocks-&-bonds-2"><ul><li>基金:间接投资工具,主要投向有价证券等金融工具或产品。</li><li>股票、债权:直接投资工具,主要投向实业领域。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="comparison-with-stocks-&-bonds-3"><ul><li>基金:风险相对适中、收益相对稳健。</li><li>股票:高风险、高收益。</li><li>债券:低风险、低收益。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><p>基金与银行储蓄的比较:</p><div class="tabs" id="comparison-with-bank's-savings"><ul class="nav-tabs"><li class="tab"><button type="button" data-href="#comparison-with-bank's-savings-1">性质不同</button></li><li class="tab"><button type="button" data-href="#comparison-with-bank's-savings-2">收益和风险特性不同</button></li><li class="tab"><button type="button" data-href="#comparison-with-bank's-savings-3">信息披露程度不同</button></li></ul><div class="tab-contents"><div class="tab-item-content" id="comparison-with-bank's-savings-1"><ul><li>基金:是一种收益凭证,基金管理人不承担投资损失的风险。</li><li>银行储蓄:是一种信用凭证,属于银行负债,银行负有法定的保本付息责任。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="comparison-with-bank's-savings-2"><ul><li>基金:收益具有一定的波动性,投资风险较大。</li><li>银行储蓄:利率相对固定,投资相对比较安全。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="comparison-with-bank's-savings-3"><ul><li>基金:定期披露。</li><li>银行储蓄:无须披露。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h3 id="证券投资基金的运作与参与主体">证券投资基金的运作与参与主体<a class="headerlink" href="#证券投资基金的运作与参与主体"></a></h3><h4 id="证券投资基金的运作(重点掌握)">证券投资基金的运作(重点掌握)<a class="headerlink" href="#证券投资基金的运作(重点掌握)"></a></h4><div class="tabs" id="operations"><ul class="nav-tabs"><li class="tab"><button type="button" data-href="#operations-1">环节</button></li><li class="tab"><button type="button" data-href="#operations-2">活动</button></li></ul><div class="tab-contents"><div class="tab-item-content" id="operations-1"><p>基金的募集、基金的投资管理、基金资产的托管、基金份额的登记交易、基金的估值和会计核算、基金的信息披露和其他基金运作活动在内的所有相关环节。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="operations-2"><ol><li>基金的市场营销:主要涉及基金份额的募集和客户服务。</li><li>基金的投资管理:体现了基金管理人的服务价值。</li><li>基金的后台管理:基金份额的注册登记、基金资产的估值、会计核算、信息披露等后台管理服务对保障基金的安全运作起着重要的作用。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h4 id="证券投资基金的参与主体(重点掌握)">证券投资基金的参与主体(重点掌握)<a class="headerlink" href="#证券投资基金的参与主体(重点掌握)"></a></h4><h5 id="基金当事人">基金当事人<a class="headerlink" href="#基金当事人"></a></h5><div class="tabs" id="parties-to-the-fund"><ul class="nav-tabs"><li class="tab"><button type="button" data-href="#parties-to-the-fund-1">基金份额持有人</button></li><li class="tab"><button type="button" data-href="#parties-to-the-fund-2">基金管理人</button></li><li class="tab"><button type="button" data-href="#parties-to-the-fund-3">基金托管人</button></li></ul><div class="tab-contents"><div class="tab-item-content" id="parties-to-the-fund-1"><ol><li>地位:基金投资者,基金的出资人、基金资产的所有者和基金投资回报的受益人。</li><li>按照《中华人民共和国证券投资基金法》第四十六条规定,我国基金份额持有人享有以下权利:<ol><li>分享基金财产收益;</li><li>参与分配清算后的剩余基金财产;</li><li>依法转让或者申请赎回其持有的基金份额;</li><li>按照规定要求召开基金份额持有人大会;</li><li>对基金份额持有人大会审议事项行使表决权;</li><li>查阅或者复制公开披露的基金信息资料;</li><li>对基金管理人、基金托管人、基金销售机构损害其合法权益的行为依法提出诉讼;</li><li>基金合同约定的其他权利。</li></ol></li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="parties-to-the-fund-2"><ol><li>地位:基金产品的募集者和管理者,是基金运作中的核心。</li><li>职责:按照基金合同的约定,负责基金资产的投资运作,力争在有效控制风险的同时为基金投资者获取最大的投资收益。</li><li>我国的基金管理人:依法设立的基金管理公司。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="parties-to-the-fund-3"><ol><li>地位:基金资产的保管者。</li><li>职责:保管基金资产,进行基金资金清算、会计复核以及对基金投资运作的监督等。</li><li>我国的基金托管人:依法设立并取得基金托管资格的商业银行或其他金融机构。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h5 id="基金市场服务机构">基金市场服务机构<a class="headerlink" href="#基金市场服务机构"></a></h5><div class="tabs" id="fund-market-service-agency"><ul class="nav-tabs"><li class="tab"><button type="button" data-href="#fund-market-service-agency-1">基金销售机构</button></li><li class="tab"><button type="button" data-href="#fund-market-service-agency-2">基金销售支付机构</button></li><li class="tab"><button type="button" data-href="#fund-market-service-agency-3">基金份额登记机构</button></li><li class="tab"><button type="button" data-href="#fund-market-service-agency-4">基金估值核算机构</button></li><li class="tab"><button type="button" data-href="#fund-market-service-agency-5">基金投资顾问机构</button></li><li class="tab"><button type="button" data-href="#fund-market-service-agency-6">基金评价机构</button></li><li class="tab"><button type="button" data-href="#fund-market-service-agency-7">基金信息技术系统服务机构</button></li><li class="tab"><button type="button" data-href="#fund-market-service-agency-8">律师事务所和会计师事务所</button></li></ul><div class="tab-contents"><div class="tab-item-content" id="fund-market-service-agency-1"><p>指受基金管理公司委托,从事基金销售业务活动的机构,包括基金管理人以及经中国证监会认定的可以从事基金销售的其他机构。目前可申请从事基金代理销售的机构:商业银行、证券公司、保险公司、证券投资咨询机构以及独立基金销售机构。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="fund-market-service-agency-2"><ul><li>指从事基金销售支付业务活动的商业银行或者支付机构。其法定义务是按照规定办理基金销售结算资金的划付。</li><li>从事销售支付活动的条件:<ol><li>取得了中国人民银行颁发的《支付业务许可证》,并具有完善的资金清算和管理制度,能够确保基金销售结算资金的安全、独立和及时划付。</li><li>从事公开募集基金销售支付业务的,应当按照中国证监会的规定进行备案。</li></ol></li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="fund-market-service-agency-3"><ul><li>指从事基金份额登记业务活动的机构。</li><li>主要职责:<ol><li>建立并管理投资人的基金账户;</li><li>负责基金份额的登记;</li><li>基金交易的确认;</li><li>代理发放红利;</li><li>建立并保管基金份额持有人名册;</li><li>法律法规或份额登记服务协议规定的其他职责。</li></ol></li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="fund-market-service-agency-4"><ul><li>指从事基金估值核算业务活动的机构。基金管理人及其委托的基金估值核算机构均可办理基金估值核算业务。</li><li>拟从事公开募集基金估值核算业务的条件:必须向中国证监会申请注册。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="fund-market-service-agency-5"><ul><li>指从事基金投资顾问业务活动的机构。</li><li>提供公开募集基金投资顾问业务的条件:必须向工商登记注册地的中国证监会派出机构申请注册。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="fund-market-service-agency-6"><ul><li>指从事基金评价业务活动的机构。</li><li>从事公开募集基金评价业务的条件:应当向基金业协会申请注册。</li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="fund-market-service-agency-7"><ul><li>指为基金管理人、基金托管人和基金服务机构提供基金业务核心应用软件开发、信息系统运营维护、信息系统安全保障和基金交易电子商务平台等业务活动的机构。</li><li>开展基金信息技术系统服务业务具备的条件:<ol><li>应当具备国家有关部门规定的资质条件或者取得相关资质认证。</li><li>具有开展业务所需要的人员、设备、技术、知识产权等条件。</li><li>其信息技术系统服务应当符合法律法规、中国证监会以及行业自律组织等的业务规范要求。</li></ol></li></ul><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="fund-market-service-agency-8"><p>律师事务所和会计师事务所作为专业、独立的中介服务机构,为基金提供法律、会计服务。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h3 id="证券投资基金业在金融体系中的地位与作用(重点掌握)">证券投资基金业在金融体系中的地位与作用(重点掌握)<a class="headerlink" href="#证券投资基金业在金融体系中的地位与作用(重点掌握)"></a></h3><div class="tabs" id="position-and-role"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#position-and-role-1">极大地拓宽了中小投资者的投资渠道</button></li><li class="tab"><button type="button" data-href="#position-and-role-2">优化金融结构,促进经济增长</button></li><li class="tab"><button type="button" data-href="#position-and-role-3"><Tab名2></button></li><li class="tab"><button type="button" data-href="#position-and-role-4"><Tab名2></button></li><li class="tab"><button type="button" data-href="#position-and-role-5"><Tab名2></button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="position-and-role-1"><p>对于中小投资者来说,投资基金是比投资股票更好的选择。对于中小投资者来说,股票市场变幻莫测,由于缺乏投资经验,再加上信息条件的限制,对个股研究有较大的局限性,很难在股市中获得良好的投资收益,而且风险较大。投资基金把众多投资者的小额资金汇集起来进行组合投资,由专业投资机构进行管理和运作,为投资者提供有效参与证券市场的投资渠道,已经成为广大民众普遍接受的一种理财方式。</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="position-and-role-2"><p>证券投资基金将中小投资者的闲散</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="position-and-role-3"><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="position-and-role-4"><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="position-and-role-5"><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h2 id="证券投资基金的类型">证券投资基金的类型<a class="headerlink" href="#证券投资基金的类型"></a></h2><h3 id="证券投资基金的分类">证券投资基金的分类<a class="headerlink" href="#证券投资基金的分类"></a></h3><h4 id="证券投资基金分类的意义">证券投资基金分类的意义<a class="headerlink" href="#证券投资基金分类的意义"></a></h4><h4 id="证券投资基金分类的标准(掌握)">证券投资基金分类的标准(掌握)<a class="headerlink" href="#证券投资基金分类的标准(掌握)"></a></h4><div class="tabs" id="sense"><ul class="nav-tabs"><li class="tab"><button type="button" data-href="#sense-1">根据投资对象划分</button></li><li class="tab"><button type="button" data-href="#sense-2">根据投资目标划分</button></li></ul><div class="tab-contents"><div class="tab-item-content" id="sense-1"><ol><li>股票基金:80%以上基金资产投资于股票。</li><li>债券基金:80%以上基金资产投资于债券。</li><li>货币市场基金:仅投资于货币市场工具。</li><li>混合基金:投资于股票、债券和货币市场工具,但股票投资和债券投资的比例不符合股票基金、债券基金的规定。</li><li>基金中基金(FOF):以基金为主要投资标的、80%以上的基金资产投资于其他基金份额。ETF 联接基金是一种特殊的基金中基金,是指将绝大部分基金资产投资于跟踪同一标的指数的 ETF,紧密跟踪标的指数表现,追求跟踪偏离度和跟踪误差最小化,采用开放式运作方式的基金。</li><li>另类投资基金:以股票、债券、货币等传统资产以外的资产为投资标的基金。我国的另类投资基金主要包括:<ol><li>商品基金:以商品现货或者期货合约为投资对象,主要有黄金 ETF 和商品期货 ETF。</li><li>非上市股权基金。</li><li>房地产基金。</li></ol></li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="sense-2"><ol><li>增长型基金:以追求资本增值为基本目标的基金,较少考虑当期收入,主要以具有良好增长潜力的股票为投资对象。其特点是风险较大、收益较高。</li><li>收入型基金:以追求稳定的经常性收入为基本目标的基金,主要以大盘蓝筹股、公司债、政府债券等稳定收益证券为投资对象。其特点是风险较小、收益较低。</li></ol><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div>]]></content>
<categories>
<category> 2022年基金从业资格证备考 </category>
</categories>
</entry>
<entry>
<title>Windows 11 和 Arch Linux 双系统</title>
<link href="/2022/04/30/Dual_Booting_Windows_11_and_Arch_Linux/"/>
<url>/2022/04/30/Dual_Booting_Windows_11_and_Arch_Linux/</url>
<content type="html"><![CDATA[<p>还不会安装 Linux?从安装 Arch Linux 开始吧!Windows 11 和 Arch Linux 双系统,启动!</p><span id="more"></span><h2 id="下载系统镜像-3">下载系统镜像<a class="headerlink" href="#下载系统镜像-3"></a></h2><p><a href="https://archlinux.org/download/">前往官方下载地址</a>,我使用的 HTTP 下载:</p><p><img src="https://img.imql.life/illustrations/5f9604e4d1e2035a5ff78a3b85b87788.png" alt="HTTP下载.png"></p><h2 id="磁盘管理">磁盘管理<a class="headerlink" href="#磁盘管理"></a></h2><p>使用 Windows 的磁盘管理从 D 盘分 170GB 空闲空间出来,如下图。</p><p><img src="https://img.imql.life/illustrations/2fd0e04e9af29291bffdcec0dbbbf57b.png" alt="170GB.png"></p><h2 id="制作启动盘">制作启动盘<a class="headerlink" href="#制作启动盘"></a></h2><p>空 U 盘插入电脑,如下图,使用 <a href="https://rufus.ie/">Rufus</a> 制作,注意分区类型为 GPT 而非默认的 MBR,写入方式为推荐的 ISO。</p><p><img src="https://img.imql.life/illustrations/2412b18d9fa8a94c497d32e2d2a0b562.png" alt="制作.png"></p><p><img src="https://img.imql.life/illustrations/93b5e0f1e7a6bfb5b9c7a80b05843346.png" alt="以ISO镜像模式写入.png"></p><h2 id="禁用快速启动和休眠">禁用快速启动和休眠<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup><a class="headerlink" href="#禁用快速启动和休眠"></a></h2><p><img src="https://img.imql.life/illustrations/150747027b71d50cdd6271273704fc96.png" alt="禁用快速启动和休眠.png"></p><h2 id="时间表示标准统一">时间表示标准统一<sup class="footnote-ref"><a href="#fn2" id="fnref2">[2]</a></sup><a class="headerlink" href="#时间表示标准统一"></a></h2><p>Windows 默认使用的时间表示标准为 localtime,Arch Linux 默认为 UTC。在此修改 Windows 的为 UTC 以保持统一,Windows 11 中执行如下命令。</p><figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">reg add <span class="string">"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation"</span> /v RealTimeIsUniversal /d <span class="number">1</span> /t REG_DWORD /f</span><br></pre></td></tr></table></figure><p>重新启动 Windows 11 生效。</p><h2 id="BIOS_设置确认">BIOS 设置确认<a class="headerlink" href="#BIOS_设置确认"></a></h2><p>启动盘插入电脑,重启电脑,同时不停按 F2 进入 BIOS,确认以下几点:</p><ul><li>引导模式为 UEFI;</li><li>禁用 Secure Boot;</li><li>如果硬盘是 NVMe 的,硬盘的启动方式需为 AHCI。</li></ul><h2 id="从_U_盘启动">从 U 盘启动<a class="headerlink" href="#从_U_盘启动"></a></h2><p>F10 保存退出 BIOS 后不停按 F12 进入启动项选择界面,键盘上下键选择带“EFI”“USB”字样的,一般是第二个,等待。</p><p>下面就可以正式开始安装 Arch Linux:</p><p><img src="https://img.imql.life/illustrations/3bfe20f3ff7d2cf9156a866c1d59c458.png" alt="正式开始安装.png"></p><h2 id="验证引导模式">验证引导模式<a class="headerlink" href="#验证引导模式"></a></h2><p>要验证引导模式,执行下列命令列出 efivars 目录。</p><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">ls</span> /sys/firmware/efi/efivars</span><br></pre></td></tr></table></figure><p>如果命令结果显示了目录且没有报告错误,则系统以 UEFI 模式引导。</p><h2 id="连接无线网">连接无线网<a class="headerlink" href="#连接无线网"></a></h2><p>进入交互式提示符(interactive prompt):</p><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">iwctl</span><br></pre></td></tr></table></figure><p>列出所有 WiFi 设备:</p><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">device list</span><br></pre></td></tr></table></figure><p>我的网卡名字为 wlan0,扫描:</p><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">station wlan0 scan</span><br></pre></td></tr></table></figure><p>列出所有可用的网络:</p><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">station wlan0 get-networks</span><br></pre></td></tr></table></figure><p>连接到一个网络:</p><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">station wlan0 connect <Network name></span><br></pre></td></tr></table></figure><p>输入密码后回车,没有提示的话就是连接成功了,可执行下列命令查看连接状态。</p><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">station wlan0 show</span><br></pre></td></tr></table></figure><p>退出交互式提示符:</p><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">exit</span></span><br></pre></td></tr></table></figure><h2 id="更新系统时间">更新系统时间<a class="headerlink" href="#更新系统时间"></a></h2><p>使用 timedatectl 确保系统时间是准确的:</p><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">timedatectl set-ntp <span class="literal">true</span></span><br></pre></td></tr></table></figure><h2 id="建立硬盘分区">建立硬盘分区<a class="headerlink" href="#建立硬盘分区"></a></h2><p>查看分区情况:</p><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">lsblk</span><br></pre></td></tr></table></figure><p>我的硬盘名字为 nvme0n1,使用 cfdisk 进行管理:</p><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">cfdisk /dev/nvme0n1</span><br></pre></td></tr></table></figure><p>找到以上分出来的 170GB 的空闲空间,选择 New,首先是给根分区分配 32GB,再选择剩下的 138GB,如下图。</p><p><img src="https://img.imql.life/illustrations/384e65272ef67709711fbee3f123d5a4.png" alt="剩下的138GB.png"></p><p>选择 New,给交换分区分配 3GB,选择 Type,设定分区类型为 Linux swap,如下图。</p><p><img src="https://img.imql.life/illustrations/2d008cc243095a670e9c25fc1852ba9c.png" alt="Linux_swap.png"></p><p>选择剩下的 135GB,选择 New,给家分区分配剩下的空间,选择 Type,设定分区类型为 Linux home,如下图。</p><p><img src="https://img.imql.life/illustrations/119c382b48d2688c2e433a78f738544b.png" alt="Linux_home.png"></p><p>选择 Write,输入 yes 回车:</p><p><img src="https://img.imql.life/illustrations/cf5f129c57f279989af4cdcf2493bae9.png" alt="Write.png"></p><p>选择 Quit 退出。</p><h2 id="格式化分区">格式化分区<a class="headerlink" href="#格式化分区"></a></h2><p>再次查看分区情况,发现多了三个分区:</p><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">lsblk</span><br></pre></td></tr></table></figure><p>将根分区格式化为 ext4 格式:</p><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">mkfs.ext4 /dev/nvme0n1p5</span><br></pre></td></tr></table></figure><p>将交换分区格式化:</p><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">mkswap /dev/nvme0n1p6</span><br></pre></td></tr></table></figure><p>将家分区格式化为 ext4 格式:</p><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">mkfs.ext4 /dev/nvme0n1p7</span><br></pre></td></tr></table></figure><h2 id="挂载分区">挂载分区<a class="headerlink" href="#挂载分区"></a></h2><p>将根分区所对应硬盘卷挂载到<code>/mnt</code>:</p><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">mount /dev/nvme0n1p5 /mnt</span><br></pre></td></tr></table></figure><p>激活交换分区:</p><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">swapon /dev/nvme0n1p6</span><br></pre></td></tr></table></figure><p>建立目录 home:</p><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">mkdir</span> /mnt/home</span><br></pre></td></tr></table></figure><p>将家分区所对应硬盘卷挂载到目录 home:</p><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">mount /dev/nvme0n1p7 /mnt/home</span><br></pre></td></tr></table></figure><p>查看硬盘,找到 EFI System 分区所对应硬盘卷为 nvme0n1p1。:</p><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">fdisk -l</span><br></pre></td></tr></table></figure><p>建立目录 boot:</p><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">mkdir</span> /mnt/boot</span><br></pre></td></tr></table></figure><p>将 EFI System 分区所对应硬盘卷挂载目录 boot:</p><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">mount /dev/nvme0n1p1 /mnt/boot</span><br></pre></td></tr></table></figure><h2 id="配置镜像">配置镜像<a class="headerlink" href="#配置镜像"></a></h2><p>使用 reflector 来获取速度最快的 6 个镜像,并将地址保存至目录 mirrorlist:</p><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">reflector -c China -a 6 --<span class="built_in">sort</span> rate --save /etc/pacman.d/mirrorlist</span><br></pre></td></tr></table></figure><p>更新应用软件库(源),检查下载速度:</p><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">pacman -Syy</span><br></pre></td></tr></table></figure><h2 id="安装必需软件包">安装必需软件包<a class="headerlink" href="#安装必需软件包"></a></h2><p>使用 pacstrap 脚本,安装 base/base-devel 软件包、 Linux 内核、常规硬件的固件、Vim 和 AMD CPU 驱动:</p><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">pacstrap /mnt base base-devel linux linux-firmware vim amd-ucode</span><br></pre></td></tr></table></figure><h2 id="配置系统">配置系统<a class="headerlink" href="#配置系统"></a></h2><h3 id="fstab">fstab<a class="headerlink" href="#fstab"></a></h3><p>用以下命令生成文件 fstab(用<code>-U</code>设置 UUID):</p><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">genfstab -U /mnt >> /mnt/etc/fstab</span><br></pre></td></tr></table></figure><p>检查生成的文件 fstab:</p><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">cat</span> /mnt/etc/fstab</span><br></pre></td></tr></table></figure><p>切换到装好的系统:</p><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">arch-chroot /mnt</span><br></pre></td></tr></table></figure><h3 id="时区">时区<a class="headerlink" href="#时区"></a></h3><p>设置<a href="https://wiki.archlinux.org/title/Time_zone">时区</a>:</p><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">ln</span> -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime</span><br></pre></td></tr></table></figure><p>同步硬件时钟:</p><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">hwclock --systohc</span><br></pre></td></tr></table></figure><h3 id="本地化">本地化<a class="headerlink" href="#本地化"></a></h3><p>编辑文件 locale.gen:</p><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">vim /etc/locale.gen</span><br></pre></td></tr></table></figure><p>取消掉 en_US.UTF-8 UTF-8 和 zh_CN.UTF-8 UTF-8 前的注释(#)。</p><p>生成 locale 信息:</p><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">locale-gen</span><br></pre></td></tr></table></figure><p>创建 <a href="https://man.archlinux.org/man/locale.conf.5">locale.conf(5)</a> 文件,<a href="https://wiki.archlinux.org/title/Locale_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)#%E7%B3%BB%E7%BB%9F%E5%8C%BA%E5%9F%9F%E8%AE%BE%E7%BD%AE">设定 LANG 变量</a>:</p><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">vim /etc/locale.conf</span><br></pre></td></tr></table></figure><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">LANG=en_US.UTF-8</span><br></pre></td></tr></table></figure><h3 id="网络">网络<a class="headerlink" href="#网络"></a></h3><p>创建文件 hostname,自定义设定主机名:</p><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">vim /etc/hostname</span><br></pre></td></tr></table></figure><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">PC-LAPTOP</span><br></pre></td></tr></table></figure><p>修改文件 hosts:</p><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">vim /etc/hosts</span><br></pre></td></tr></table></figure><p>增加行如下(中间的空白用 tab 而非空格,PC-LAPTOP 替换为你自己的主机名)。</p><figure class="highlight diff"><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"># Static table lookup for hostnames.</span><br><span class="line"># See hosts(5) for details.</span><br><span class="line"><span class="addition">+</span></span><br><span class="line"><span class="addition">+127.0.0.1 localhost</span></span><br><span class="line"><span class="addition">+::1 localhost</span></span><br><span class="line"><span class="addition">+127.0.1.1 PC-LAPTOP.localdomain PC-LAPTOP</span></span><br></pre></td></tr></table></figure><h3 id="Root_密码">Root 密码<a class="headerlink" href="#Root_密码"></a></h3><figure class="highlight diff"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">passwd</span><br></pre></td></tr></table></figure><p>输入并确认密码(密码没有回显,输完直接回车即可)。</p><h3 id="安装基本软件包">安装基本软件包<a class="headerlink" href="#安装基本软件包"></a></h3><p>安装基本软件包,使用 GRUB 为启动器:</p><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">pacman -S grub efibootmgr networkmanager network-manager-applet dialog wireless_tools wpa_supplicant os-prober mtools dosfstools ntfs-3g linux-headers reflector git sudo</span><br></pre></td></tr></table></figure><p>编辑文件 grub:</p><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">vim /etc/default/grub</span><br></pre></td></tr></table></figure><p>取消掉 GRUB_DISABLE_OS_PROBER=false 前的注释(#)。</p><p>再执行以下命令:</p><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">grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Arch</span><br></pre></td></tr></table></figure><p>生成 grub.cfg:</p><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">grub-mkconfig -o /boot/grub/grub.cfg</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/84c7248e37454fc1007dd0464c9065e0.png" alt="grub-mkconfig.png"></p><h2 id="重启">重启<a class="headerlink" href="#重启"></a></h2><p>退出新系统:</p><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">exit</span></span><br></pre></td></tr></table></figure><p>取消挂载:</p><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">umount -R /mnt</span><br></pre></td></tr></table></figure><p>重启:</p><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">reboot</span><br></pre></td></tr></table></figure><h2 id="登入新系统">登入新系统<a class="headerlink" href="#登入新系统"></a></h2><h3 id="连接无线网-2">连接无线网<a class="headerlink" href="#连接无线网-2"></a></h3><p>启动网络服务:</p><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">systemctl <span class="built_in">enable</span> --now NetworkManager</span><br></pre></td></tr></table></figure><p>设置 WiFi:</p><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">nmtui</span><br></pre></td></tr></table></figure><h3 id="创建个人用户并授权">创建个人用户并授权<a class="headerlink" href="#创建个人用户并授权"></a></h3><p>创建用户 ql,创建家目录,加入 wheel 组,指定 shell:</p><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">useradd -m -G wheel -s /bin/bash ql</span><br></pre></td></tr></table></figure><p>为用户 ql 设定密码:</p><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">passwd ql</span><br></pre></td></tr></table></figure><p>编辑文件 sudoers:</p><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">EDITOR=vim visudo</span><br></pre></td></tr></table></figure><p>取消掉<code>%wheel ALL=(ALL:ALL) NOPASSWD: ALL</code>前的注释(#)。</p><h3 id="安装显卡驱动">安装显卡驱动<a class="headerlink" href="#安装显卡驱动"></a></h3><p>我的电脑是 AMD 集显:</p><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">pacman -S xf86-video-amdgpu</span><br></pre></td></tr></table></figure><h3 id="安装_Display_Server">安装 Display Server<a class="headerlink" href="#安装_Display_Server"></a></h3><p>我装的是开源世界最为流行的 xorg:</p><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">pacman -S xorg</span><br></pre></td></tr></table></figure><p>出现选择直接回车即可。</p><h3 id="安装_Display_Manager">安装 Display Manager<a class="headerlink" href="#安装_Display_Manager"></a></h3><p>我装的是 KDE 的:</p><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">pacman -S sddm</span><br></pre></td></tr></table></figure><p>设置开机自动启动:</p><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">systemctl <span class="built_in">enable</span> sddm</span><br></pre></td></tr></table></figure><h3 id="安装_Desktop_Environment">安装 Desktop Environment<a class="headerlink" href="#安装_Desktop_Environment"></a></h3><p>安装 KDE:</p><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">pacman -S plasma kde-applications packagekit-qt5</span><br></pre></td></tr></table></figure><p>一路默认即可。</p><h3 id="重启-2">重启<a class="headerlink" href="#重启-2"></a></h3><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">reboot</span><br></pre></td></tr></table></figure><p>以个人用户登录。</p><h3 id="安装字体">安装字体<a class="headerlink" href="#安装字体"></a></h3><p>英文字体:</p><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">sudo pacman -S ttf-dejavu ttf-droid ttf-hack ttf-font-awesome otf-font-awesome ttf-lato ttf-liberation ttf-linux-libertine ttf-opensans ttf-roboto ttf-ubuntu-font-family</span><br></pre></td></tr></table></figure><p>中文字体:</p><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">sudo pacman -S ttf-hannom noto-fonts noto-fonts-extra noto-fonts-emoji noto-fonts-cjk adobe-source-code-pro-fonts adobe-source-sans-fonts adobe-source-serif-fonts adobe-source-han-sans-cn-fonts adobe-source-han-sans-hk-fonts adobe-source-han-sans-tw-fonts adobe-source-han-serif-cn-fonts wqy-zenhei wqy-microhei</span><br></pre></td></tr></table></figure><h3 id="系统语言">系统语言<a class="headerlink" href="#系统语言"></a></h3><p>按 Win 键,搜索运行 language,添加简体中文(在最下方),调整其优先级到最上方,Apply(应用):</p><p><img src="https://img.imql.life/illustrations/08c27c0c494c4894355239b5da75681f.png" alt="系统语言.png"></p><p>注销重新登录以生效。</p><h3 id="添加_archlinuxcn_源">添加 archlinuxcn 源<a class="headerlink" href="#添加_archlinuxcn_源"></a></h3><p>编辑文件 pacman.conf:</p><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">sudo vim /etc/pacman.conf</span><br></pre></td></tr></table></figure><p>文件末尾空一行追加以下内容(使用的北外的镜像站)。</p><figure class="highlight plaintext"><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">[archlinuxcn]</span><br><span class="line">Server = https://mirrors.bfsu.edu.cn/archlinuxcn/$arch</span><br></pre></td></tr></table></figure><p>同步并安装 archlinuxcn-keyring:</p><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">sudo pacman -Sy && sudo pacman -S archlinuxcn-keyring</span><br></pre></td></tr></table></figure><h3 id="安装_yay">安装 yay<a class="headerlink" href="#安装_yay"></a></h3><p><a href="https://github.com/Jguer/yay">yay</a> 是一个受欢迎的 <a href="https://wiki.archlinux.org/title/Arch_User_Repository">AUR</a> 助手,执行以下命令安装。</p><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">sudo pacman -S yay</span><br></pre></td></tr></table></figure><h3 id="安装输入法">安装输入法<sup class="footnote-ref"><a href="#fn3" id="fnref3">[3]</a></sup><a class="headerlink" href="#安装输入法"></a></h3><p>安装 fcitx、fcitx-im 和 fcitx-configtool:</p><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">sudo pacman -S fcitx fcitx-im fcitx-configtool</span><br></pre></td></tr></table></figure><p>安装 <a href="https://aur.archlinux.org/packages/fcitx-sogoupinyin/">fcitx-sogoupinyin</a>:</p><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">yay -S fcitx-sogoupinyin</span><br></pre></td></tr></table></figure><p>一路回车即可。</p><p>创建文件 .pam_environment:</p><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">vim ~/.pam_environment</span><br></pre></td></tr></table></figure><p>设置 IM 环境变量:</p><figure class="highlight plaintext"><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">GTK_IM_MODULE DEFAULT=fcitx</span><br><span class="line">QT_IM_MODULE DEFAULT=fcitx</span><br><span class="line">XMODIFIERS DEFAULT=\@im=fcitx</span><br></pre></td></tr></table></figure><p>注销重新登录,按 Win 键,搜索“Fcitx 配置”,回车运行,将位于第一个的“键盘 - 英语(美国)”删除,输入法即可正常使用了。</p><h3 id="安装_Timeshift">安装 Timeshift<a class="headerlink" href="#安装_Timeshift"></a></h3><p>当系统出现故障的时候,可以通过备份的快照来恢复系统。</p><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">sudo pacman -S timeshift</span><br></pre></td></tr></table></figure><p>按 Win 键或者 Alt+Space,搜索运行 Timeshift。</p><p>快照类型一般选择 RSYNC:</p><p><img src="https://img.imql.life/illustrations/63c1deb6f5662f20344d876d87f6b5af.png" alt="选择快照类型.png"></p><p>选择快照位置:</p><p><img src="https://img.imql.life/illustrations/e1f73ba8c4128cd7cfc1dd59d3a9b28c.png" alt="选择快照位置.png"></p><p>选择快照等级:</p><p><img src="https://img.imql.life/illustrations/00373ee1d29601e5854597831f847992.png" alt="选择快照等级.png"></p><p>默认是不备份用户目录,默认即可。</p><p>设置完成:</p><p><img src="https://img.imql.life/illustrations/14d974905b3339cceb70866cadac1ff7.png" alt="设置完成.png"></p><p>启用并启动 <a href="https://wiki.archlinux.org/title/Cron_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)">cron</a>:</p><figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo systemctl enable <span class="literal">--now</span> cronie</span><br></pre></td></tr></table></figure><h3 id="安装_fish">安装 fish<a class="headerlink" href="#安装_fish"></a></h3><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">sudo pacman -S fish</span><br></pre></td></tr></table></figure><p>设定为默认 shell:</p><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">chsh -s /usr/bin/fish</span><br></pre></td></tr></table></figure><p>注销重新登录以生效。</p><h3 id="禁用休眠">禁用休眠<sup class="footnote-ref"><a href="#fn4" id="fnref4">[4]</a></sup><a class="headerlink" href="#禁用休眠"></a></h3><p>编辑文件 sleep.conf:</p><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">vim /etc/systemd/sleep.conf</span><br></pre></td></tr></table></figure><figure class="highlight diff"><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">[Sleep]</span><br><span class="line">#AllowSuspend=yes</span><br><span class="line"><span class="deletion">-#AllowHibernation=yes</span></span><br><span class="line"><span class="deletion">-#AllowSuspendThenHibernate=yes</span></span><br><span class="line"><span class="deletion">-#AllowHybridSleep=yes</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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">[Sleep]</span><br><span class="line">#AllowSuspend=yes</span><br><span class="line"><span class="addition">+AllowHibernation=no</span></span><br><span class="line"><span class="addition">+AllowSuspendThenHibernate=no</span></span><br><span class="line"><span class="addition">+AllowHybridSleep=no</span></span><br></pre></td></tr></table></figure><h3 id="安装火狐浏览器">安装火狐浏览器<a class="headerlink" href="#安装火狐浏览器"></a></h3><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">sudo pacman -S firefox</span><br></pre></td></tr></table></figure><p>安装中文语言包:</p><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">sudo pacman -S firefox-i18n-zh-cn</span><br></pre></td></tr></table></figure><h2 id="美化启动项选择界面">美化启动项选择界面<a class="headerlink" href="#美化启动项选择界面"></a></h2><p>每次重启电脑,如下图,默认的启动项选择界面看起来比较简朴,我们可以换一个主题。</p><p><img src="https://img.imql.life/illustrations/b6c9b499166502f5ab2733698115dd6d.png" alt="默认的启动项选择界面.png"></p><p><a href="https://github.com/AdisonCavani/distro-grub-themes">前往主题仓库</a>,下载 Arch 主题文件:</p><p><img src="https://img.imql.life/illustrations/9ed9aa73446cc14d3e785c38a4f71718.png" alt="arch.png"></p><p>安装 Grub Customizer:</p><figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo pacman <span class="literal">-S</span> grub<span class="literal">-customizer</span></span><br></pre></td></tr></table></figure><p>按 Win 键或者 Alt+Space,搜索运行 Grub Customizer。</p><p>点击外观设置,设定分辨率为 1920x1080:</p><p><img src="https://img.imql.life/illustrations/f92cad978180676abcad444479c50ed3.png" alt="自定义分辨率.png"></p><p>点击主题后面的加号,选择以上下载好的主题文件,点击左上角文件,保存:</p><p><img src="https://img.imql.life/illustrations/3010e38e90ec4f52cd43ee26ea34a994.png" alt="保存.png"></p><p>重启,至此,Windows 11 和 Arch Linux 双系统安装园满完成。</p><h2 id="参考-4">参考<a class="headerlink" href="#参考-4"></a></h2><ul><li><a href="https://zhuanlan.zhihu.com/p/138951848">2021 Archlinux 双系统安装教程(超详细)</a></li><li><a href="https://zhuanlan.zhihu.com/p/433920079">Archlinux 安装教程超详细(2021.11.15)</a></li><li><a href="https://wiki.archlinux.org/title/General_recommendations_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)">General recommendations</a></li></ul><hr class="footnotes-sep"><section class="footnotes"><ol class="footnotes-list"><li id="fn1" class="footnote-item"><p><a href="https://wiki.archlinux.org/title/Dual_boot_with_Windows">Dual boot with Windows</a> <a href="#fnref1" class="footnote-backref">↩︎</a></p></li><li id="fn2" class="footnote-item"><p><a href="https://wiki.archlinux.org/title/System_time#UTC_in_Microsoft_Windows">UTC in Microsoft Windows</a> <a href="#fnref2" class="footnote-backref">↩︎</a></p></li><li id="fn3" class="footnote-item"><p><a href="https://wiki.archlinux.org/title/Fcitx_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)">Fcitx</a> <a href="#fnref3" class="footnote-backref">↩︎</a></p></li><li id="fn4" class="footnote-item"><p><a href="https://wiki.archlinux.org/title/Power_management#Disabling_suspend">Disabling suspend</a> <a href="#fnref4" class="footnote-backref">↩︎</a></p></li></ol></section>]]></content>
<categories>
<category> PC </category>
</categories>
<tags>
<tag> Windows </tag>
<tag> Arch Linux </tag>
</tags>
</entry>
<entry>
<title>Windows 10&11 安装指南</title>
<link href="/2022/04/20/The_Installation_Guide_of_Windows_10_and_Windows_11/"/>
<url>/2022/04/20/The_Installation_Guide_of_Windows_10_and_Windows_11/</url>
<content type="html"><![CDATA[<p>还不会安装 Windows?Windows 10&11 安装指南奉上。</p><span id="more"></span><h2 id="下载系统镜像-2">下载系统镜像<a class="headerlink" href="#下载系统镜像-2"></a></h2><p>两个下载渠道:<a href="https://www.microsoft.com/zh-cn/software-download">微软官网</a>和 <a href="https://next.itellyou.cn">I Tell You(新版)</a>,推荐 I Tell You (新版),这是一个提供原版软件下载链接的网站,下载工具的话就推荐<a href="https://www.xunlei.com/index.html">迅雷</a>。我选择的 Windows 10 和 Window 11 镜像分别为:</p><p><img src="https://img.imql.life/illustrations/4f492a33cd4965a5d79ef0955d09e1a3.png" alt="Windows_10.png"></p><p><img src="https://img.imql.life/illustrations/4afb01eb459bc934a904d00ce5f8b196.png" alt="Windows_11.png"></p><p>直接点击复制右边的下载链接(建议 BT),如果此时你的迅雷正在运行中的话,此时会自动解析种子并提示下载,如下图,速度还是很快的。</p><p><img src="https://img.imql.life/illustrations/1e3e0006af3e1163e3efb51da8b152a7.png" alt="速度很快.png"></p><p>下载完成后勾选一下显示校验信息:</p><p><img src="https://img.imql.life/illustrations/0affe41db723d3d076c2a29fbcfee04e.png" alt="Windows_10校验码.png"></p><p><img src="https://img.imql.life/illustrations/d274140340fb886a6daa7db833633fe5.png" alt="Windows_11校验码.png"></p><p>使用软件帮忙生成系统镜像的校验码(MD5、SHA1 和 SHA256 任选一个类型),我这里就直接使用 Windows 自带的命令来生成 SHA256 校验码:</p><figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">certutil.exe <span class="literal">-hashfile</span> .\zh<span class="literal">-cn_windows_10_business_editions_version_21h2_updated_april_2022_x64_dvd_b0024895</span>.iso SHA256</span><br></pre></td></tr></table></figure><figure class="highlight plaintext"><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">SHA256 hash of .\zh-cn_windows_10_business_editions_version_21h2_updated_april_2022_x64_dvd_b0024895.iso:</span><br><span class="line">c0dd1ec3bfd04bcc1b69bfaa988e418caf594287c2ca52d291cb63f01df273ff</span><br><span class="line">CertUtil: -hashfile command completed successfully.</span><br></pre></td></tr></table></figure><figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">certutil.exe <span class="literal">-hashfile</span> .\zh<span class="literal">-cn_windows_11_business_editions_updated_april_2022_x64_dvd_dec0b963</span>.iso SHA256</span><br></pre></td></tr></table></figure><figure class="highlight plaintext"><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">SHA256 hash of .\zh-cn_windows_11_business_editions_updated_april_2022_x64_dvd_dec0b963.iso:</span><br><span class="line">828ce37ed9c1c07002b865f00580a6a44b759ebfcbb83afb484da88fd7c6ef9d</span><br><span class="line">CertUtil: -hashfile command completed successfully.</span><br></pre></td></tr></table></figure><div class="note info flat"><p>注意系统镜像路径,我这里是在迅雷下载文件夹下进入 Windows Powershell 执行的。</p></div><p>将生成的校验码和图中的进行比对,完全一致则表明系统镜像未损坏。</p><h2 id="方法一:直接安装">方法一:直接安装<a class="headerlink" href="#方法一:直接安装"></a></h2><div class="note success flat"><p>适用情况:电脑比较卡;希望从 Windows 7、Windows 8 或 Windows 8.1 升级到 Windows 10/11。</p></div><p>Windows 11 安装要求较为严苛,如下图,请在安装前确认机器满足要求。</p><p><img src="https://img.imql.life/illustrations/cc2f22885ce9760812246795263cb29f.png" alt="Windows_11安装要求.png"></p><div class="note info flat"><p>直接安装 Windows 10/11 步骤一致,下面以 Windows 10 为例说明。</p></div><p>首先确保下载的镜像不在 C 盘,如果原来的操作系统是 Windows 7 之后的系统,直接双击打开镜像文件。</p><p>如果原来的操作系统为 Windwos 7,是不能直接双击打开镜像文件的,需要使用解压缩工具将镜像文件解压出来,例如使用 7z。</p><p>双击运行 setup.exe。</p><p>首先是提示你是否要对现在的镜像文件进行更新,建议这里选择更改 Windows 安装程序下载更新的方式:</p><p><img src="https://img.imql.life/illustrations/2691a7924eccaf0ca638c446e9ed872a.png" alt="更改安装程序下载更新的方式.png"></p><p>选择不是现在,下一步(要是现在更新的话就需要等较长时间):</p><p><img src="https://img.imql.life/illustrations/2228cacfe2a310102146648fe3f92572.png" alt="不是现在.png"></p><p>检查准备中:</p><p><img src="https://img.imql.life/illustrations/e330eb0672b52e9248b2929017eb816c.png" alt="检查准备中.png"></p><p>选择版本,我这里选择专业版:</p><p><img src="https://img.imql.life/illustrations/9b47b8b9da3a3f508d2a6caf6d869ddf.png" alt="Windows_10专业版.png"></p><p>接受条款:</p><p><img src="https://img.imql.life/illustrations/a2f561690cbabffa75b1d31fa6fba2e2.png" alt="接受条款.png"></p><p>最后的准备:</p><p><img src="https://img.imql.life/illustrations/16191682699f2492257dba03b352326c.png" alt="最后的准备.png"></p><p>这里就默认保留个人文件和应用,也就是仅仅操作系统会被改变,C 盘中的个人文件和应用会被保留,可以自行更改要保留的内容。</p><p><img src="https://img.imql.life/illustrations/964e915ff11712a727062337655567bd.png" alt="保留个人文件和应用.png"></p><div class="note warning flat"><p>升级跨度比较大的话这里只能保留 C 盘中的个人文件。</p></div><p>开始安装,等待即可。</p><h2 id="方法二:从_U_盘启动安装">方法二:从 U 盘启动安装<a class="headerlink" href="#方法二:从_U_盘启动安装"></a></h2><div class="note success flat"><p>适用情况:刚组装了一台台式机,还没有操作系统;电脑进不去了,C 盘没什么文件,可以直接格式化。</p></div><p>空 U 盘插入到一台正常使用的电脑上,使用 <a href="https://rufus.ie/">Rufus</a> 制作启动盘:</p><p><img src="https://img.imql.life/illustrations/6aea48e9b453b49b525b8d4bb93f7849.png" alt="制作.png"></p><p>在制作 Windows 11 安装 U 盘时,注意到镜像选项处有两个特别的选项,如下图,简单理解就是一个会去检查是否支持 TPM 2.0,一个不会。</p><p><img src="https://img.imql.life/illustrations/3385906ad02d0aaa095dc1287a45e7bc.png" alt="需要TPM2.0.png"></p><p><img src="https://img.imql.life/illustrations/fb3e5abfa0edacb8e817f63764a8a619.png" alt="不需要TPM2.0.png"></p><p>制作完成后就可以将安装盘插到要安装的机器上,启动电脑,同时不停按 F2 进入 BIOS,确认引导模式为 UEFI。</p><p>F10 保存退出 BIOS,同时不停按 F12 进入启动项选择界面。键盘上下键选择带“EFI”“USB”字样的,一般是第二个,回车。</p><p>下一步:</p><p><img src="https://img.imql.life/illustrations/cbd03453b8976de4629a99c0405333cc.png" alt="下一步.png"></p><p>现在安装:</p><p><img src="https://img.imql.life/illustrations/66ad6d7f443df4939e18449720fc6b86.png" alt="现在安装.png"></p><p>选择要安装的 Windows 10/11,我这里选择专业版:</p><p><img src="https://img.imql.life/illustrations/04ecf28931a9694cf7d7f2fc319077ef.png" alt="选择要安装的Windows_10.png"></p><p><img src="https://img.imql.life/illustrations/44cf871b1470015c8d1700bb0cb44a6c.png" alt="选择要安装的Windows_11.png"></p><p>接受:</p><p><img src="https://img.imql.life/illustrations/24e9a7e38770bc91ae01c5115cf03d2c.png" alt="接受.png"></p><p>自定义安装:</p><p><img src="https://img.imql.life/illustrations/149abcb6b5d30fac48420c705810922d.png" alt="自定义安装.png"></p><p>上图中如果选择升级安装,会有下面的提示。</p><p><img src="https://img.imql.life/illustrations/0fdafbcba9ada3b4dfd51fa6c905f5bc.png" alt="升级选项不可用.png"></p><p>如果这是一台新机器,还没有安装操作系统,那么选择未分配空间的驱动器,选择新建,设定 C 盘大小,应用,确定:</p><div class="note info flat"><p>C 盘大小建议设定为 50-100GB。</p></div><p><img src="https://img.imql.life/illustrations/baf8e6365fdf4b06d6c782c41b79c0c3.png" alt="驱动器0.png"></p><p>接着依次划分剩余的未分配空间给 D 盘、E 盘等盘。</p><p>如果这是一台旧机器,C 盘上安装过操作系统,但是 C 盘没什么文件,可以直接格式化,那么我们依次删除前三个驱动器分区:</p><p><img src="https://img.imql.life/illustrations/8505f97a0440ce80d8db19c80d169f7e.png" alt="前三个驱动器分区.png"></p><p><img src="https://img.imql.life/illustrations/fe0e3457a04d4c7aa6749e2cb6f0d2ec.png" alt="删除分区1.png"></p><p><img src="https://img.imql.life/illustrations/835cad69f583a35595825561f8c716c0.png" alt="删除分区2.png"></p><p><img src="https://img.imql.life/illustrations/a5b9884fbcf6202d8a6448a090e657ca.png" alt="删除分区3.png"></p><p>这里有可能只有两个驱动器分区需要删除:</p><p><img src="https://img.imql.life/illustrations/6c75cf646f2a5d5e35a8629d3f501db9.png" alt="前两个驱动器分区.png"></p><p>接下来就和上述机器还没有安装操作系统的情况一样,选择未分配空间的驱动器,新建 C 盘、D 盘和 E 盘等盘。</p><p>选择新建的 C 盘(第一个类型为主分区的分区),下一步:</p><p><img src="https://img.imql.life/illustrations/e02e1698e397eca429a7b58fa08706ed.png" alt="下一步.png"></p><p>安装中,等待即可:</p><p><img src="https://img.imql.life/illustrations/9b89164e9a836174b5ed2ecba60ed38c.png" alt="安装中.png"></p><h2 id="方法三:在_PE_中安装">方法三:在 PE 中安装<a class="headerlink" href="#方法三:在_PE_中安装"></a></h2><div class="note info flat"><p>PE,即预安装环境,是带有有限服务的最小 Windows,在 PE 中安装 Windows 是最好的 Windows 安装办法。</p></div><h3 id="制作_PE">制作 PE<a class="headerlink" href="#制作_PE"></a></h3><p>首先需要一个 U 盘,最好容量大一下,这样可以放下多个镜像,许多其他软件,满足各种安装需要。制作 PE 的软件比较多,强烈推荐<a href="https://www.wepe.com.cn/">微 PE</a> 和<a href="https://www.upe.net/">优启通</a>,我这里以优启通为例。</p><p>运行优启通,选择磁盘,全新制作:</p><p><img src="https://img.imql.life/illustrations/59c81bca1d8655f335a86a6aa9672b78.png" alt="优启通.png"></p><p>制作完成后就可以将 PE 盘插到要安装的机器上,启动电脑,同时不停按 F2 进入 BIOS,确认引导模式为 UEFI。</p><p>F10 保存退出 BIOS,同时不停按 F12 进入启动项选择界面。键盘上下键选择带“EFI”“USB”字样的,一般是第二个,回车。</p><h3 id="备份_C_盘文件(可选)">备份 C 盘文件(可选)<a class="headerlink" href="#备份_C_盘文件(可选)"></a></h3><p>看下自己的 C 盘有没有重要文件,一般就是桌面和下载中的文件,考虑转移一下。</p><h3 id="硬盘分区(可选)">硬盘分区(可选)<a class="headerlink" href="#硬盘分区(可选)"></a></h3><p>对于新的机器,或者整个硬盘数据可清除的情况,可通过桌面上的 DG 硬盘分区对硬盘分好区。</p><p>选择好硬盘,选择上方的快速分区,注意分区表类型选择 GUID,分区数目自定义,其他的推荐默认就好,确定:</p><p><img src="https://img.imql.life/illustrations/029cdb1d2d876cd9bfef31fe3a4d5e43.png" alt="硬盘分区.png"></p><h3 id="安装">安装<a class="headerlink" href="#安装"></a></h3><p>可直接双击镜像文件安装,之后的步骤同从 U 盘启动安装,也可选择桌面上的 EIX 系统安装进行安装。</p><p>左侧选择版本,右侧选择系统盘(注意在 PE 中,系统盘不一定为 C 盘,请以实际系统盘盘符为准),点击一键恢复,确认:</p><p><img src="https://img.imql.life/illustrations/e758d8f09dd77849f717584cb7501028.png" alt="映像恢复.png"></p><p><img src="https://img.imql.life/illustrations/a9b33b1f88c7bd6d55f8378fb8422796.png" alt="确认.png"></p><p>恢复中,等待即可:</p><p><img src="https://img.imql.life/illustrations/68727d4dde125f490731c14479a478f8.png" alt="恢复中.png"></p><h2 id="开箱体验(OOBE)">开箱体验(OOBE)<a class="headerlink" href="#开箱体验(OOBE)"></a></h2><p>OOBE(Out-of-box experience),即开箱体验,它是在安装完 Windows 后要做的第一件事,以下为 Windows 10/11 的演示。</p><h3 id="Windows_10">Windows 10<a class="headerlink" href="#Windows_10"></a></h3><p>区域设置:</p><p><img src="https://img.imql.life/illustrations/636f11fbfb89df7a200a2b92831bcd31.png" alt="中国-Windows10.png"></p><p>输入法:</p><p><img src="https://img.imql.life/illustrations/f8a23fb85343e708d90578d6e2c1db03.png" alt="微软拼音-Windows10.png"></p><p>添加第二种键盘布局:</p><p><img src="https://img.imql.life/illustrations/bd35ce68c412ee4892259d4601fefbbf.png" alt="跳过-Windows10.png"></p><p>连接到网络:</p><p><img src="https://img.imql.life/illustrations/5c6b490484d59323a0976ecd76fe13f1.png" alt="我没有Internet连接-Windows10.png"></p><p>创建用户:</p><p><img src="https://img.imql.life/illustrations/ede5bc55603a1f2edd16b88467222dbd.png" alt="创建用户-Windows10.png"></p><p>设置密码:</p><p><img src="https://img.imql.life/illustrations/80012c16a042425c5f33e73258b878f4.png" alt="设置密码-Windows10.png"></p><p>隐私设置:</p><p><img src="https://img.imql.life/illustrations/3a4159666f7c865f3f9f292c553d34b7.png" alt="隐私设置-Windows10.png"></p><p>微软小娜:</p><p><img src="https://img.imql.life/illustrations/ee22686f9625f35d54d9cf4a54aaf1d0.png" alt="微软小娜-Windows10.png"></p><p>即将完毕:</p><p><img src="https://img.imql.life/illustrations/2d2c4b4a076df19700550c3aa6ed0de9.png" alt="即将完毕-Windows10.png"></p><h3 id="Windows_11">Windows 11<a class="headerlink" href="#Windows_11"></a></h3><p>区域设置:</p><p><img src="https://img.imql.life/illustrations/879a8b90862a7faff41b039465cf284d.png" alt="中国-Windows11.png"></p><p>输入法:</p><p><img src="https://img.imql.life/illustrations/48589410744e3f64b74e2ec561aebbc7.png" alt="微软拼音-Windows11.png"></p><p>添加第二种键盘布局:</p><p><img src="https://img.imql.life/illustrations/f59062d113ced36eb48b81ede44fed9c.png" alt="跳过-Windows11.png"></p><p>连接到网络:</p><p><img src="https://img.imql.life/illustrations/ecf65979b73b2cc241bcbc2164fc1c91.png" alt="我没有Internet连接-Windows11.png"></p><p>创建用户:</p><p><img src="https://img.imql.life/illustrations/16c2362c562f02be73d8c2bf7ac06755.png" alt="创建用户-Windows11.png"></p><p>设置密码:</p><p><img src="https://img.imql.life/illustrations/ce308ded8ccab4749155e9afcec5cdff.png" alt="设置密码-Windows11.png"></p><p>隐私设置:</p><p><img src="https://img.imql.life/illustrations/87c952585eb17fa9da1a90659b098e5b.png" alt="隐私设置-Windows11.png"></p><p>即将完毕:</p><p><img src="https://img.imql.life/illustrations/fb2d5aaadd76b64678e7cba22445e38a.png" alt="即将完毕-Windows11.png"></p>]]></content>
<categories>
<category> PC </category>
</categories>
<tags>
<tag> Windows </tag>
</tags>
</entry>
<entry>
<title>Windows PowerShell</title>
<link href="/2022/03/19/Windows_PowerShell/"/>
<url>/2022/03/19/Windows_PowerShell/</url>
<content type="html"><![CDATA[<p><a href="https://github.com/PowerShell/PowerShell">Powershell</a>——微软拥抱开源的又一力作。</p><span id="more"></span><h2 id="前言">前言<a class="headerlink" href="#前言"></a></h2><p>基于 .NET Framework,2006 年 11 月,Windows PowerShell 1.0 作为可选组件出现在 Windows Server 2008 上,到 2016 年 8 月,Windows PowerShell 5.1 在 Windows 10 周年更新和 Windows Server 2016 中发布,一直到现在,Windows PowerShell 仍然停留在 5.1,如下图,这是为何?</p><p><img src="https://img.imql.life/illustrations/f0bd31264a4123e055441e3074f98dd7.png" alt="Windows_PowerShell.png"></p><p>其实微软在这么长的时间里并没有闲着,就在 2018 年 1 月,基于 .NET Core 2.0 构建的开源软件 PowerShell 6.0 发布。</p><p>.NET Core,即 .NET Framework 的子集,原来,微软这又是要在开源世界开辟自己的空间了。</p><p>如今的 PowerShell 已来到了 7,一个跨平台的任务自动化解决方案,算是真正诞生了,不过我们今天不是要来讲 PowerShell,而是要讲 Windows PowerShell。</p><h2 id="Windows_PowerShell_美化">Windows PowerShell 美化<a class="headerlink" href="#Windows_PowerShell_美化"></a></h2><p>一直以来,Windows 的图形化界面深入人心。在参加工作前,本人对其命令行界面的认识一直停留在 CMD 这个黑乎乎的窗口,而且我也几乎认为这个黑乎乎的窗口什么用也没有,工作后,发现 CMD 还是比较有用的,但是和 Linux 上的 bash 、zsh 和 fish 相比,就显得相形见绌了,至于 Windows PowerShell,我一直是将其与 CMD 画等号的。</p><p>微软的又一开源软件——Windows Terminal 的出现让我重新去看待 Windows 的命令行界面,去了解和使用 Windows PowerShell。</p><p>如下图,Windows Terminal 让 Windows PowerShell 看起来顺眼了一些,但仍然不够,类似于 bash 、zsh 和 fish,PowerShell 也有自己的 oh-my-xxx 项目——<a href="https://github.com/JanDeDobbeleer/oh-my-posh">oh-my-posh</a>。</p><p><img src="https://img.imql.life/illustrations/559cef53152f46e7df50f7da185e92bb.png" alt="Windows_Terminal.png"></p><h3 id="安装_oh_my_posh">安装 oh-my-posh<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup><a class="headerlink" href="#安装_oh_my_posh"></a></h3><ol><li>利用 PowerShell 命令安装:</li></ol><figure class="highlight powershell"><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">Install-Module</span> <span class="built_in">oh</span><span class="literal">-my-posh</span> <span class="literal">-Scope</span> CurrentUser</span><br></pre></td></tr></table></figure><ol start="2"><li>提示需要 NuGet,回车以安装并导入:</li></ol><p><img src="https://img.imql.life/illustrations/2857dad2e859dd791a7781d464e71d12.png" alt="需要NuGet.png"></p><ol start="3"><li>输入 Y 以确定从“PSGallery”安装模块:</li></ol><p><img src="https://img.imql.life/illustrations/04e98fe12f8276d06f666db93fdeb2cb.png" alt="确认.png"></p><h3 id="安装_Nerd_Fonts_Hack">安装 <strong>Nerd Fonts(Hack)</strong><a class="headerlink" href="#安装_Nerd_Fonts_Hack"></a></h3><p><a href="https://github.com/ryanoasis/nerd-fonts/releases/">前往 Nerd Fonts 发布页面</a>,我下载的是 v2.1.0 的 Hack 字体。</p><p>下载好后解压,这里有许多版本的 Hack,要选 Windows Compatible 的, 我就装个 Hack Regular Nerd Font Complete Windows Compatible 吧,直接双击安装即可。</p><h3 id="设置字体">设置字体<a class="headerlink" href="#设置字体"></a></h3><p>重新进入 Windows PowerShell,找到 Windows PowerShell 的字体设置,如下图,选择 Hack NF,保存。</p><p><img src="https://img.imql.life/illustrations/d27c853079204309f601c3d19b0a19db.png" alt="字体.png"></p><h3 id="安装_posh_git">安装 posh-git<a class="headerlink" href="#安装_posh_git"></a></h3><p>利用 PowerShell 命令安装:</p><figure class="highlight powershell"><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">Install-Module</span> posh<span class="literal">-git</span> <span class="literal">-Scope</span> CurrentUser</span><br></pre></td></tr></table></figure><p>同样输入 Y 以确定从“PSGallery”安装模块。</p><h3 id="编辑_PowerShell_配置文件">编辑 PowerShell 配置文件<a class="headerlink" href="#编辑_PowerShell_配置文件"></a></h3><p>记事本打开配置文件:</p><figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">notepad.exe <span class="variable">$PROFILE</span></span><br></pre></td></tr></table></figure><p>还不存在此文件,选择创建:</p><p><img src="https://img.imql.life/illustrations/90db2c3f829eb7bbe9e68ad17d63d20f.png" alt="PROFILE.png"></p><p>编辑配置文件:</p><figure class="highlight diff"><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="addition">+Import-Module posh-git</span></span><br><span class="line"><span class="addition">+Import-Module oh-my-posh</span></span><br><span class="line"><span class="addition">+Set-PoshPrompt -Theme clean-detailed</span></span><br></pre></td></tr></table></figure><div class="note info flat"><p>以上<code>-Theme</code>后面指定自己喜欢的主题,<a href="https://ohmyposh.dev/docs/themes">主题列表见此</a>。</p></div><h3 id="设置_PowerShell_执行策略">设置 PowerShell 执行策略<sup class="footnote-ref"><a href="#fn2" id="fnref2">[2]</a></sup><a class="headerlink" href="#设置_PowerShell_执行策略"></a></h3><p>一般此时重新进入 Windows PowerShell 就能看到已经美化好了,但是结果是:</p><p><img src="https://img.imql.life/illustrations/f107ea7bc2a09ef8e8340886a0a4ce40.png" alt="Execution_Policies.png"></p><p>以上红字提示的参阅地址中有解决办法,原来默认的执行策略为 Restricted,如下图。</p><p><img src="https://img.imql.life/illustrations/370d106359bc6d0dfe2016c361e5bf83.png" alt="Restricted.png"></p><p>我们设置执行策略为 RemoteSigned:</p><figure class="highlight powershell"><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">Set-ExecutionPolicy</span> <span class="literal">-ExecutionPolicy</span> RemoteSigned</span><br></pre></td></tr></table></figure><p>再重新进入 Windows PowerShell(一开始需要进行导入,可能有点慢),美化完成。</p><h2 id="参考-5">参考<a class="headerlink" href="#参考-5"></a></h2><ul><li><a href="https://www.bilibili.com/video/BV1jQ4y1Y7mG">2021 年打开 Powershell 的正确姿势:)</a></li><li><a href="https://www.bilibili.com/video/BV12u411Z7Zo">配置一个漂亮的 Windows Powershell (1)</a></li></ul><hr class="footnotes-sep"><section class="footnotes"><ol class="footnotes-list"><li id="fn1" class="footnote-item"><p><a href="https://ohmyposh.dev/docs/">在 Windows 上 安装 Oh My Posh</a> <a href="#fnref1" class="footnote-backref">↩︎</a></p></li><li id="fn2" class="footnote-item"><p><a href="https://docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-5.1">about_Execution_Policies</a> <a href="#%E8%AE%BE%E7%BD%AE-PowerShell-%E6%89%A7%E8%A1%8C%E7%AD%96%E7%95%A5-2">↩</a> <a href="#fnref2" class="footnote-backref">↩︎</a></p></li></ol></section>]]></content>
<categories>
<category> Windows PowerShell </category>
</categories>
</entry>
<entry>
<title>JPG、PNG 和 SVG</title>
<link href="/2022/01/03/JPG_PNG_and_SVG/"/>
<url>/2022/01/03/JPG_PNG_and_SVG/</url>
<content type="html"><![CDATA[<p>What is the difference between JPG,PNG and SVG?</p><span id="more"></span><h2 id="JPG_Joint_Photographic_Experts_Group">JPG(Joint Photographic Experts Group)<a class="headerlink" href="#JPG_Joint_Photographic_Experts_Group"></a></h2><h3 id="Advantages">Advantages<a class="headerlink" href="#Advantages"></a></h3><ul><li>Widespread use</li><li>Quick loading time</li><li>Full color spectrum</li></ul><h3 id="Disadvantages">Disadvantages<a class="headerlink" href="#Disadvantages"></a></h3><ul><li>Lossy compression</li><li>Doesn’s support transparencies and animations</li><li>No layers</li></ul><h2 id="PNG_Portable_Network_Graphics">PNG(Portable Network Graphics)<a class="headerlink" href="#PNG_Portable_Network_Graphics"></a></h2><h3 id="Advantages-2">Advantages<a class="headerlink" href="#Advantages-2"></a></h3><ul><li>Lossless compressions</li><li>Supports (semi)-transparency and alpha channel</li><li>Full color spectrum</li></ul><h3 id="Disadvantages-2">Disadvantages<a class="headerlink" href="#Disadvantages-2"></a></h3><ul><li>Not suitable for print</li><li>Requires more memory space</li><li>Animations are not possible</li></ul><h2 id="SVG_Scalable_Vector_Graphics">SVG(Scalable Vector Graphics)<a class="headerlink" href="#SVG_Scalable_Vector_Graphics"></a></h2><ul><li>SVG can be created in any text editor or code editor.</li><li>SVG can be designed & exported from drawing software.</li><li>SVG can be rendered into any size.</li><li>SVG are very sharp,they are not pixelated.</li><li>SVG are small and easy to render (When Simple).</li><li>SVG works only with 2 dimensional images.</li><li>SVG is not ideal for very detailed images.</li></ul><h2 id="参考">参考<a class="headerlink" href="#参考"></a></h2><ul><li><a href="https://www.youtube.com/watch?v=tbfguZBDHPE">JPG v PNG v SVG | what are the differences? which is the best to use?</a></li></ul>]]></content>
<categories>
<category> 设计 </category>
</categories>
</entry>
<entry>
<title>建立个人云服务(四)</title>
<link href="/2021/11/11/Building_Personal_Cloud_Services_4/"/>
<url>/2021/11/11/Building_Personal_Cloud_Services_4/</url>
<content type="html"><![CDATA[<p>腾讯云的这个 1h2g 无忧实例,一个月 15 元还是贵了点,计划 22 年 1 月 25 日到期之后就不续费了,还是新用户最划算。</p><span id="more"></span><h2 id="双十一活动">双十一活动<a class="headerlink" href="#双十一活动"></a></h2><p>腾讯云在双十一推出智惠云集活动,下图这个轻量应用服务器实在是太香了,可是我已经不符合要求了,于是邀请来一位符合条件的小伙伴来买,我们两共用,买的时候镜像还是选择 Ubuntu 18.04。</p><p><img src="https://img.imql.life/illustrations/fd110a6c26dacb1ced81a21294246264.jpeg" alt="智惠云集活动.jpg"></p><h2 id="迁移_Code_Server">迁移 Code Server<a class="headerlink" href="#迁移_Code_Server"></a></h2><p>趁此机会直接升级下 Code Server,下载安装最新版本的安装包,再安装 Caddy,具体安装方式和<a href="https://blog.ql-isaac.cn/2021/09/08/Building_Personal_Cloud_Services(1)/#code-server">之前</a>完全一样。</p><p>code-server 所有的用户数据都在某一目录下<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup>。我们 SSH 连接无忧实例,将该目录打包压缩得到 code-server.tar.gz:</p><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"><span class="built_in">cd</span> ~/.local/share/</span><br><span class="line">tar -zcf code-server.tar.gz code-server</span><br></pre></td></tr></table></figure><p>SSH 连接新买的轻量实例,保险起见,将新装的 code-server 用户数据目录备份一下:</p><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 class="built_in">cd</span> ~/.local/share/</span><br><span class="line">tar -zcf code-server.tar.gz.bak code-server</span><br><span class="line"><span class="built_in">rm</span> -rf code-server</span><br></pre></td></tr></table></figure><p>SFTP 上传以上 code-server.tar.gz(上传到目录 share 下面)。</p><p>解压缩:</p><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">tar -zxf code-server.tar.gz</span><br></pre></td></tr></table></figure><p>无需重启服务,直接登录 code-server,就会发现之前无忧实例中的设置和配置都迁移过来了(如果你已经登录,直接刷新应该也是没问题的)。</p><h2 id="迁移_frps">迁移 frps<a class="headerlink" href="#迁移_frps"></a></h2><p>参考<a href="https://blog.ql-isaac.cn/2021/10/13/Building_Personal_Cloud_Services(3)/#%E5%AE%89%E8%A3%85-frps">当时的安装方式</a>,迁移方式其实很简单:直接将目录 frp_0.37.1_linux_amd64 转移过来,复制里面的 frps.service 到指定路径下,启用并启动服务。</p><p>经过测试,发现 frps.service 启动不起来,查看下日志发现权限不足:</p><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">journalctl -u frps.service</span><br></pre></td></tr></table></figure><figure class="highlight latex"><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">Nov 11 22:03:28 VM-16-11-ubuntu systemd[1]: Started Frp Server Service.</span><br><span class="line">Nov 11 22:03:28 VM-16-11-ubuntu systemd[28411]: frps.service: Failed to execute command: Permission denied</span><br><span class="line">Nov 11 22:03:28 VM-16-11-ubuntu systemd[28411]: frps.service: Failed at step EXEC spawning /home/ubuntu/frp<span class="built_in">_</span>0.37.1<span class="built_in">_</span>linux<span class="built_in">_</span>amd64/frps: Permission denied</span><br><span class="line">Nov 11 22:03:28 VM-16-11-ubuntu systemd[1]: frps.service: Main process exited, code=exited, status=203/EXEC</span><br><span class="line">Nov 11 22:03:28 VM-16-11-ubuntu systemd[1]: frps.service: Failed with result 'exit-code'.</span><br><span class="line">Nov 11 22:03:33 VM-16-11-ubuntu systemd[1]: frps.service: Service hold-off time over, scheduling restart.</span><br><span class="line">Nov 11 22:03:33 VM-16-11-ubuntu systemd[1]: frps.service: Scheduled restart job, restart counter is at 1.</span><br><span class="line">Nov 11 22:03:33 VM-16-11-ubuntu systemd[1]: Stopped Frp Server Service.</span><br></pre></td></tr></table></figure><p>问题出在转移 frp_0.37.1_linux_amd64 这里,我是直接将无忧实例的以上目录下载下来,再上传到轻量实例中的,这种方式使上传之后的目录权限变为 775,文件权限变为 666,即所有的文件都是没有执行权限的。我们给命令 frps 赋予恰当的权限后重启 frps.service 就没问题了:</p><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"><span class="built_in">chmod</span> 755 frps</span><br><span class="line">sudo systemctl restart frps.service</span><br></pre></td></tr></table></figure><hr class="footnotes-sep"><section class="footnotes"><ol class="footnotes-list"><li id="fn1" class="footnote-item"><p><a href="https://github.com/cdr/code-server/blob/main/docs/upgrade.md">Upgrade</a> <a href="#fnref1" class="footnote-backref">↩︎</a></p></li></ol></section>]]></content>
<categories>
<category> 建立个人云服务 </category>
<category> Code Server </category>
<category> frp </category>
</categories>
<tags>
<tag> Ubuntu </tag>
</tags>
</entry>
<entry>
<title>建立个人云服务(三)</title>
<link href="/2021/10/13/Building_Personal_Cloud_Services_3/"/>
<url>/2021/10/13/Building_Personal_Cloud_Services_3/</url>
<content type="html"><![CDATA[<p>上回说到,我辛辛苦苦白忙活了一趟后发现配置太低服务根本跑不起来,奈何高配置的又太贵,于是决定买个树莓派玩玩,搞个自建服务器,但前提是需要内网穿透。</p><span id="more"></span><h2 id="内网穿透">内网穿透<a class="headerlink" href="#内网穿透"></a></h2><p>字面理解,想必大家已经猜到内网穿透是干嘛的了。自己有一台服务器,如何才能向互联网提供服务呢,对于一般个人来说,唯一的方法就是内网穿透,而相应的方案稍微查一查也能发现有许多,我选择的是开源软件——<a href="https://github.com/fatedier/frp">frp</a>搭配腾讯云无忧实例的方案。</p><p>简单说下原理,frp 分为服务端(frps)和客户端(frpc)两部分,frps 部署在腾讯云无忧实例中,frpc 部署在自建服务器中,启动本地服务后,frp 可以将本地服务的端口映射到无忧实例的某一端口,这样,客户端和无忧实例的端口通信就相当于与本地服务的端口通信。</p><h2 id="安装_frps">安装 frps<a class="headerlink" href="#安装_frps"></a></h2><p>首先是去 <a href="https://github.com/fatedier/frp/releases">frp 发布页面</a>下载最新的安装包,这里有许多的版本,我们 SSH 连接无忧实例执行<code>uname -m</code>查看其硬件平台,是 x86_64,则应该下载 amd64 版本的,如下图。</p><p><img src="https://img.imql.life/illustrations/2fe215c8b285eb3d5b59abe9f10d85dd.png" alt="下载frp.png"></p><p>下载完毕后上传到无忧实例家目录下。</p><p>解压缩到家目录:</p><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">tar -zxvf ~/frp_0.37.1_linux_amd64.tar.gz -C ~</span><br></pre></td></tr></table></figure><p>编辑 frps 配置文件:</p><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">vim ~/frp_0.37.1_linux_amd64/frps.ini</span><br></pre></td></tr></table></figure><p>默认 frps 绑定的端口是 7000,我们需要再设定一下 Token 认证<a href="#%E5%8F%82%E8%80%83">[1]</a>,要不然我们的内网穿透服务对任何人都是可用的。为此,追加下面的内容。</p><figure class="highlight diff"><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">[common]</span><br><span class="line">bind_port = 7000</span><br><span class="line"><span class="addition">+authentication_method = token</span></span><br><span class="line"><span class="addition">+token = <一串字符></span></span><br></pre></td></tr></table></figure><p>启动 frps:</p><figure class="highlight plaintext"><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">cd ~/frp_0.37.1_linux_amd64</span><br><span class="line">./frps -c ./frps.ini</span><br></pre></td></tr></table></figure><p>以这种方式启动的话,你会发现你干不了其他事,按<code>ctrl+c</code>的话程序也会退出。我们可以使用<code>nohup</code>让其在后台运行,同时错误日志会重定向到 frps.log 中,方便查看:</p><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">nohup</span> ./frps -c ./frps.ini > frps.log 2>&1 &</span><br></pre></td></tr></table></figure><div class="note warning flat"><p>后台运行后,如果你是通过 SSH 连接的无忧实例,不要直接叉掉窗口,这样 frps 仍会停止运行,这里需要执行<code>exit</code>注销掉当前会话,再叉掉窗口才行。</p></div><p>是的,现在 frps 的确是在后台运行了,可是万一无忧实例重启了怎么办,还要执行一下上面的命令。Linux 系统工具——Systemd 是最终的解决之道,刚好在目录 frp_0.37.1_linux_amd64 下有一个 systemd 目录,作者已经给我们提供了现成的配置文件,只需修改一二。</p><p>编辑 frps.service:</p><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"><span class="built_in">cd</span> systemd</span><br><span class="line">vim frps.service</span><br></pre></td></tr></table></figure><figure class="highlight diff"><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">[Unit]</span><br><span class="line">Description=Frp Server Service</span><br><span class="line">After=network.target</span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line">Type=simple</span><br><span class="line"><span class="deletion">-User=nobody</span></span><br><span class="line"><span class="addition">+User=ubuntu</span></span><br><span class="line">Restart=on-failure</span><br><span class="line">RestartSec=5s</span><br><span class="line"><span class="deletion">-ExecStart=/usr/bin/frps -c /etc/frp/frps.ini</span></span><br><span class="line"><span class="addition">+ExecStart=/home/ubuntu/frp_0.37.1_linux_amd64/frps -c /home/ubuntu/frp_0.37.1_linux_amd64/frps.ini</span></span><br><span class="line">LimitNOFILE=1048576</span><br><span class="line"></span><br><span class="line">[Install]</span><br><span class="line">WantedBy=multi-user.target</span><br></pre></td></tr></table></figure><p>复制 frps.service 到指定目录(没有请自建):</p><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">sudo <span class="built_in">cp</span> ~/frp_0.37.1_linux_amd64/systemd/frps.service /usr/lib/systemd/system</span><br></pre></td></tr></table></figure><p>启用并启动服务:</p><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">sudo systemctl <span class="built_in">enable</span> --now frps</span><br></pre></td></tr></table></figure><h2 id="安装_frpc">安装 frpc<a class="headerlink" href="#安装_frpc"></a></h2><p>SSH 连接树莓派 4B,同样执行<code>uname -m</code>,是 armv71,应该下载 arm 版本的,如下图。</p><p><img src="https://img.imql.life/illustrations/afebe5b19b96bc63da7252986399798a.png" alt="arm.png"></p><p>上传到树莓派、解压,编辑 frpc 配置文件。</p><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">vim ~/Document/frp_0.37.1_linux_arm/frpc.ini</span><br></pre></td></tr></table></figure><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">[common]</span><br><span class="line"><span class="deletion">-server_addr = 127.0.0.1</span></span><br><span class="line"><span class="addition">+server_addr = <无忧实例的公网IP></span></span><br><span class="line">server_port = 7000</span><br><span class="line"><span class="addition">+authentication_method = token</span></span><br><span class="line"><span class="addition">+token = <一串字符></span></span><br><span class="line"></span><br><span class="line">[ssh]</span><br><span class="line">type = tcp</span><br><span class="line">local_ip = 127.0.0.1</span><br><span class="line">local_port = 22</span><br><span class="line">remote_port = 6000</span><br></pre></td></tr></table></figure><div class="note info flat"><p>[common] 部分对应 frps 的 [common] 部分,注意 token 要保持一致。[ssh] 部分表示的就是本地 SSH 的 22 端口与无忧实例的 6000 端口的映射关系。关于 frp 的更多使用,可见<a href="https://gofrp.org/">官方中文文档</a></p></div><p>也是需要后台随操作系统启动运行,同理,编辑 frpc.service:</p><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">vim ~/Document/frp_0.37.1_linux_arm/systemd/frpc.service</span><br></pre></td></tr></table></figure><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">[Unit]</span><br><span class="line">Description=Frp Client Service</span><br><span class="line">After=network.target</span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line">Type=simple</span><br><span class="line"><span class="deletion">-User=nobody</span></span><br><span class="line"><span class="addition">+User=pi</span></span><br><span class="line">Restart=on-failure</span><br><span class="line">RestartSec=5s</span><br><span class="line"><span class="deletion">-ExecStart=/usr/bin/frpc -c /etc/frp/frpc.ini</span></span><br><span class="line"><span class="deletion">-ExecReload=/usr/bin/frpc reload -c /etc/frp/frpc.ini</span></span><br><span class="line"><span class="addition">+ExecStart=/home/pi/Document/frp_0.37.1_linux_arm/frpc -c /home/pi/Document/frp_0.37.1_linux_arm/frpc.ini</span></span><br><span class="line"><span class="addition">+ExecReload=/home/pi/Document/frp_0.37.1_linux_arm/frpc reload -c /home/pi/Document/frp_0.37.1_linux_arm/frpc.ini</span></span><br><span class="line">LimitNOFILE=1048576</span><br><span class="line"></span><br><span class="line">[Install]</span><br><span class="line">WantedBy=multi-user.target</span><br></pre></td></tr></table></figure><p>复制 frpc.service 到指定路径下:</p><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">sudo <span class="built_in">cp</span> ~/Document/frp_0.37.1_linux_arm/systemd/frpc.service /usr/lib/systemd/system</span><br></pre></td></tr></table></figure><p>启用并启动服务:</p><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">sudo systemctl <span class="built_in">enable</span> --now frpc</span><br></pre></td></tr></table></figure><h2 id="验证">验证<a class="headerlink" href="#验证"></a></h2><p>以上 frps 和 frpc 都安装上后,默认是已经将树莓派的 SSH 服务的 22 端口映射到了无忧实例的 6000 端口。我在任何一台联网的机器上,都可以执行以下命令或者使用 SSH 连接工具去连接我的树莓派。</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh -p 6000 pi@<无忧实例的公网IP></span><br></pre></td></tr></table></figure><ol><li><a href="https://github.com/fatedier/frp#authenticating-the-client">Authenticating the Client</a> <a href="#fnref1">↩︎</a></li></ol>]]></content>
<categories>
<category> 建立个人云服务 </category>
</categories>
<tags>
<tag> frp </tag>
<tag> Raspberry Pi OS </tag>
</tags>
</entry>
<entry>
<title>建立个人云服务(二)</title>
<link href="/2021/10/03/Building_Personal_Cloud_Services_2/"/>
<url>/2021/10/03/Building_Personal_Cloud_Services_2/</url>
<content type="html"><![CDATA[<p>工作的机会,接触到 <a href="https://www.atlassian.com/">Atlassian 公司</a>旗下的多款软件产品,虽然不是开源的,虽然不是免费的,但是好用啊,无论是对个人还是企业来说。</p><span id="more"></span><h2 id="下载_Jira_Software">下载 Jira Software<a class="headerlink" href="#下载_Jira_Software"></a></h2><p>Jira Software 是 <a href="https://www.atlassian.com/">Atlassian 公司</a> 出品的问题管理与协同工具,被广泛应用于缺陷跟踪、客户服务、需求收集、流程审批、任务跟踪、项目跟踪和敏捷管理等工作领域。</p><p>Jira Software 有两种部署方式:云平台和自建。云平台方式就是 Atlassian 官方提供全套云服务,你只需要注册账号通过浏览器使用即可,但是这种方式在国内体验并不好,出于个人自学的目的,我选择自建方式。</p><p>在<a href="https://www.atlassian.com/software/jira/download-archives">官方下载页面</a>,选择下载最新的长期支持版:</p><p><img src="https://img.imql.life/illustrations/65f8f94574f6fd2f3688aa1e47b7b836.png" alt="长期支持版.png"></p><p>这里选择 TAR.GZ 格式的,如下图,这种格式需要进行手动安装,下载完成后使用 SFTP 上传到无忧实例家目录下的 Atlassian 下。</p><p><img src="https://img.imql.life/illustrations/7792f9b2c82db4e01567949a48983505.png" alt="tar.gz.png"></p><p>这里有安装手册,如下图,官方的文档写得非常好,只是需要一点英文基础。</p><p><img src="https://img.imql.life/illustrations/0c27dabc33ed2177879d05053b27f6b6.png" alt="安装手册.png"></p><h2 id="下载_Confluence">下载 Confluence<a class="headerlink" href="#下载_Confluence"></a></h2><p>Confluence 是 <a href="https://www.atlassian.com/">Atlassian 公司</a> 出品的知识管理与协同软件,可以用于构建企业 wiki。</p><p>Confluence 同样有两种部署方式:云平台和自建,我们还是选择自建。</p><p>在<a href="https://www.atlassian.com/software/confluence/download-archives">官方下载页面</a>,也是选择下载 TAR.GZ 格式的最新长期支持版,然后上传到无忧实例家目录下的 Atlassian 下。</p><p><img src="https://img.imql.life/illustrations/7e74763a9a501ba7d4a4a1c4786bdcdf.png" alt="confluence.png"></p><h2 id="下载安装_Jdk8">下载安装 Jdk8<a class="headerlink" href="#下载安装_Jdk8"></a></h2><p>前往<a href="https://www.oracle.com/java/technologies/downloads/#java8">官方下载地址</a>,也是下载 TAR.GZ 格式的,如下图,这里需要登录才能下载,没有账号就注册一下。</p><p><img src="https://img.imql.life/illustrations/f4a232930b3cae52e1b0c8f8a2833a13.png" alt="jdk8.png"></p><p>下载完成后,使用 root 用户登录无忧实例,如果确认密码是正确的还是登不上,那可能是 SSH 没开启 root 远程登录,百度一下即可。登录上之后创建目录,如下。</p><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">mkdir</span> /usr/lib/jdk</span><br></pre></td></tr></table></figure><p>上传刚刚下好的 Jdk 到以上创建目录下,再解压到此目录下。</p><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">tar -zxvf jdk-8u301-linux-x64.tar.gz -C /usr/lib/jdk</span><br></pre></td></tr></table></figure><p>再换成 ubuntu 用户登录,这是平常使用的用户,编辑 .bashrc。</p><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">vim ~/.bashrc</span><br></pre></td></tr></table></figure><p>在文件的末尾,空一格,追加下面内容:</p><figure class="highlight plaintext"><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">#Set Oracle Jdk environment</span><br><span class="line">export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_301</span><br><span class="line">export JRE_HOME=${JAVA_HOME}/jre</span><br><span class="line">export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib</span><br><span class="line">export PATH=${JAVA_HOME}/bin:$PATH</span><br></pre></td></tr></table></figure><p>使环境变量马上生效:</p><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">source</span> ~/.bashrc</span><br></pre></td></tr></table></figure><p>执行如下命令,输出版本信息,表明 Jdk 安装成功。</p><p><img src="https://img.imql.life/illustrations/d8531eece3cf36ada075b344f91a6f24.png" alt="安装成功.png"></p><h2 id="下载安装配置_MySQL5_7">下载安装配置 MySQL5.7<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup><a class="headerlink" href="#下载安装配置_MySQL5_7"></a></h2><p>分别执行以下命令下载 MySQL APT 并安装:</p><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">wget https://repo.mysql.com/mysql-apt-config_0.8.19-1_all.deb</span><br><span class="line">sudo dpkg -i mysql-apt-config_0.8.19-1_all.deb</span><br></pre></td></tr></table></figure><p>选择第一个回车,之后可以选择版本,也是选择第一个 mysql-5.7,回车,回到了上一级,移动到最底下,即选择 Ok,回车:</p><p><img src="https://img.imql.life/illustrations/e1108b3336a9b2c9f56e4c009db37b1d.png" alt="回车.png"></p><p>使用以下命令更新 MySQL APT 存储库中的包信息。</p><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">sudo apt-get update</span><br></pre></td></tr></table></figure><p>执行以下命令安装 MySQL,安装过程中会要求输入 root 数据库用户的密码。</p><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">sudo apt-get install mysql-server</span><br></pre></td></tr></table></figure><p>安装完成后,服务是已经启动的,可执行以下命令查看。</p><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">systemctl status mysql</span><br></pre></td></tr></table></figure><p>编辑 my.cnf:</p><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">sudo vim /etc/mysql/my.cnf</span><br></pre></td></tr></table></figure><p>空一行,追加以下内容:</p><figure class="highlight plaintext"><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></pre></td><td class="code"><pre><span class="line">[mysqld]</span><br><span class="line">character-set-server=utf8mb4</span><br><span class="line">collation-server=utf8mb4_bin</span><br><span class="line">default-storage-engine=INNODB</span><br><span class="line">max_allowed_packet=256M</span><br><span class="line">transaction-isolation=READ-COMMITTED</span><br><span class="line">binlog_format=row</span><br><span class="line">log-bin-trust-function-creators = 1</span><br><span class="line">optimizer_switch = derived_merge=off</span><br><span class="line">innodb_default_row_format=DYNAMIC</span><br><span class="line">innodb_large_prefix=ON</span><br><span class="line">innodb_file_format=Barracuda</span><br><span class="line">innodb_log_file_size=2G</span><br></pre></td></tr></table></figure><p>重启 MySQL:</p><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">sudo service mysql stop</span><br><span class="line">sudo service mysql start</span><br></pre></td></tr></table></figure><p>以 root(不是操作系统的 root)登入 MySQL,密码就是上面设定的:</p><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">mysql -u root -p</span><br></pre></td></tr></table></figure><p>这里可以看到 MySQL 的具体版本:</p><p><img src="https://img.imql.life/illustrations/5cc8eec7cb7f6a1f9ada3e041418edab.png" alt="具体版本.png"></p><p>分别执行以下 SQL,创建数据库用户 jira 和 confluence,数据库 jiradb 和 confluencedb。</p><figure class="highlight sql"><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"><span class="keyword">CREATE</span> <span class="keyword">USER</span> jira IDENTIFIED <span class="keyword">by</span> <span class="string">'<jira的密码>'</span>;</span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">USER</span> confluence IDENTIFIED <span class="keyword">by</span> <span class="string">'<confluence的密码>'</span>;</span><br><span class="line"><span class="keyword">CREATE</span> DATABASE jiradb <span class="type">CHARACTER</span> <span class="keyword">SET</span> utf8mb4 <span class="keyword">COLLATE</span> utf8mb4_bin;</span><br><span class="line"><span class="keyword">CREATE</span> DATABASE confluence <span class="type">CHARACTER</span> <span class="keyword">SET</span> utf8mb4 <span class="keyword">COLLATE</span> utf8mb4_bin;</span><br></pre></td></tr></table></figure><p>分别执行以下 SQL,授予数据库用户 jira 和 confluence 相应权限。</p><figure class="highlight sql"><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"><span class="keyword">GRANT</span> <span class="keyword">SELECT</span>,<span class="keyword">INSERT</span>,<span class="keyword">UPDATE</span>,<span class="keyword">DELETE</span>,<span class="keyword">CREATE</span>,<span class="keyword">DROP</span>,<span class="keyword">REFERENCES</span>,<span class="keyword">ALTER</span>,INDEX <span class="keyword">on</span> jiradb.<span class="operator">*</span> <span class="keyword">TO</span> <span class="string">'jira'</span>@<span class="string">'%'</span> IDENTIFIED <span class="keyword">BY</span> <span class="string">'<自己设定的jira的密码>'</span>;</span><br><span class="line"><span class="keyword">GRANT</span> <span class="keyword">ALL</span> PRIVILEGES <span class="keyword">ON</span> confluencedb.<span class="operator">*</span> <span class="keyword">TO</span> <span class="string">'confluence'</span>@<span class="string">'%'</span> IDENTIFIED <span class="keyword">BY</span> <span class="string">'<自己设定的confluence的密码>'</span>;</span><br></pre></td></tr></table></figure><p>最后使权限生效:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">flush privileges;</span><br></pre></td></tr></table></figure><p>退出 MySQL:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">exit</span><br></pre></td></tr></table></figure><h2 id="下载_MySQL_JDBC_Drive">下载 MySQL JDBC Drive<a class="headerlink" href="#下载_MySQL_JDBC_Drive"></a></h2><p>了解到要想使用 confluence,官方推荐的 JDBC driver 是 5.1 版本的<sup class="footnote-ref"><a href="#fn2" id="fnref2">[2]</a></sup>,于是前往 <a href="https://downloads.mysql.com/archives/c-j/">MySQL 官方地址下载该版本的 JDBC driver</a>,如下图,注意选择 Platform Independent,即与平台无关。</p><p><img src="https://img.imql.life/illustrations/133c55674d4f32b2768c1429ecb75dbf.png" alt="Platform-Independent.png"></p><p>下载完成后直接解压到当前文件夹,我们只需要里面的 jar 文件,如下图,先将其上传到无忧实例家目录下的 Atlassian 下。</p><p><img src="https://img.imql.life/illustrations/7a2c81761f087ce0523ea43e895da22d.png" alt="jar.png"></p><p>Jira 也可以使用 5.1 版本的 JDBC driver<sup class="footnote-ref"><a href="#fn3" id="fnref3">[3]</a></sup>,那就不用再下了。</p><h2 id="安装_Jira_Software">安装 Jira Software<sup class="footnote-ref"><a href="#fn4" id="fnref4">[4]</a></sup><a class="headerlink" href="#安装_Jira_Software"></a></h2><h3 id="准备">准备<a class="headerlink" href="#准备"></a></h3><ol><li>创建安装目录:</li></ol><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">mkdir</span> ~/Atlassian/jirasoftware</span><br></pre></td></tr></table></figure><ol start="2"><li>解压压缩包到安装目录:</li></ol><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">tar -xzf ~/Atlassian/atlassian-jira-software-8.13.11.tar.gz -C ~/Atlassian/jirasoftware</span><br></pre></td></tr></table></figure><ol start="3"><li>复制下载好的 MySQL JDBC Drive 到相应目录:</li></ol><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">cp</span> ~/Atlassian/mysql-connector-java-5.1.49.jar ~/Atlassian/jirasoftware/atlassian-jira-software-8.13.11-standalone/lib</span><br></pre></td></tr></table></figure><ol start="4"><li>创建 Jira Software 的家目录,这是应用产生的数据的存放之处:</li></ol><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">mkdir</span> ~/Atlassian/jirasoftware/jirasoftware-home</span><br></pre></td></tr></table></figure><ol start="5"><li>创建了家目录,就要告诉 Jira Software 家目录在哪儿,同样是编辑 .bashrc,在文件的末尾空一格,追加下面内容:</li></ol><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">export JIRA_HOME=~/Atlassian/jirasoftware/jirasoftware-home</span><br></pre></td></tr></table></figure><h3 id="使用_Candy_代理_Jira_Software">使用 Candy 代理 Jira Software<a class="headerlink" href="#使用_Candy_代理_Jira_Software"></a></h3><p>注释掉无代理连接器:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">#本行为~/Atlassian/jirasoftware/atlassian-jira-software-8.13.11-standalone/conf/server.xml的第17行(随着Jira Software的不断更新,本行对应在你的server.yml中不一定是第17行,请以实际情况为准)</span><br><span class="line"><Server port="8005" shutdown="SHUTDOWN"></span><br><span class="line"> <Listener className="org.apache.catalina.startup.VersionLoggerListener"/></span><br><span class="line"> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on"/></span><br><span class="line"> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/></span><br><span class="line"> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/></span><br><span class="line"> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/></span><br><span class="line"></span><br><span class="line"> <Service name="Catalina"></span><br><span class="line"> <!--</span><br><span class="line"> <span class="comment">==============================================================================================================</span></span><br><span class="line"> DEFAULT - Direct connector with no proxy for unproxied access to Jira.</span><br><span class="line"></span><br><span class="line"> If using a http/https proxy, comment out this connector.</span><br><span class="line"> <span class="comment">==============================================================================================================</span></span><br><span class="line"> --></span><br><span class="line"></span><br><span class="line"> <!-- Relaxing chars because of JRASERVER-67974 --></span><br><span class="line"><span class="deletion">- <Connector port="8080" relaxedPathChars="[]|" relaxedQueryChars="[]|{}^\`"<>"</span></span><br><span class="line"><span class="deletion">- maxThreads="150" minSpareThreads="25" connectionTimeout="20000" enableLookups="false"</span></span><br><span class="line"><span class="deletion">- maxHttpHeaderSize="8192" protocol="HTTP/1.1" useBodyEncodingForURI="true" redirectPort="8443"</span></span><br><span class="line"><span class="deletion">- acceptCount="100" disableUploadTimeout="true" bindOnInit="false"/></span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">#本行为~/Atlassian/jirasoftware/atlassian-jira-software-8.13.11-standalone/conf/server.xml的第17行(随着Jira Software的不断更新,本行对应在你的server.yml中不一定是第17行,请以实际情况为准)</span><br><span class="line"><Server port="8005" shutdown="SHUTDOWN"></span><br><span class="line"> <Listener className="org.apache.catalina.startup.VersionLoggerListener"/></span><br><span class="line"> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on"/></span><br><span class="line"> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/></span><br><span class="line"> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/></span><br><span class="line"> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/></span><br><span class="line"></span><br><span class="line"> <Service name="Catalina"></span><br><span class="line"> <!--</span><br><span class="line"> <span class="comment">==============================================================================================================</span></span><br><span class="line"> DEFAULT - Direct connector with no proxy for unproxied access to Jira.</span><br><span class="line"></span><br><span class="line"> If using a http/https proxy, comment out this connector.</span><br><span class="line"> <span class="comment">==============================================================================================================</span></span><br><span class="line"> --></span><br><span class="line"></span><br><span class="line"> <!-- Relaxing chars because of JRASERVER-67974 --></span><br><span class="line"><span class="addition">+ <!--</span></span><br><span class="line"><span class="addition">+ <Connector port="8080" relaxedPathChars="[]|" relaxedQueryChars="[]|{}^\`"<>"</span></span><br><span class="line"><span class="addition">+ maxThreads="150" minSpareThreads="25" connectionTimeout="20000" enableLookups="false"</span></span><br><span class="line"><span class="addition">+ maxHttpHeaderSize="8192" protocol="HTTP/1.1" useBodyEncodingForURI="true" redirectPort="8443"</span></span><br><span class="line"><span class="addition">+ acceptCount="100" disableUploadTimeout="true" bindOnInit="false"/></span></span><br><span class="line"><span class="addition">+ --></span></span><br></pre></td></tr></table></figure><p>要使用 Candy 代理,需要将 HTTPS 代理连接器放开,同时设置端口为 8081(8080 已经用于本系列第一篇中的 code-server 服务了),代理域名设为 <a href="http://proj.ql-isaac.cn">proj.ql-isaac.cn</a>:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">#本行为~/Atlassian/jirasoftware/atlassian-jira-software-8.13.11-standalone/conf/server.xml的第62行(随着Jira Software的不断更新,本行对应在你的server.yml中不一定是第62:行,请以实际情况为准)</span><br><span class="line"> <!--</span><br><span class="line"> <span class="comment">==============================================================================================================</span></span><br><span class="line"> HTTPS - Proxying Jira via Apache or Nginx over HTTPS</span><br><span class="line"></span><br><span class="line"> If you're proxying traffic to Jira over HTTPS, uncomment the below connector and comment out the others.</span><br><span class="line"> Ensure the proxyName and proxyPort are updated with the appropriate information if necessary as per the docs.</span><br><span class="line"></span><br><span class="line"> See the following for more information:</span><br><span class="line"></span><br><span class="line"> Apache - https://confluence.atlassian.com/x/PTT3MQ</span><br><span class="line"> nginx - https://confluence.atlassian.com/x/DAFmGQ</span><br><span class="line"> <span class="comment">==============================================================================================================</span></span><br><span class="line"> --></span><br><span class="line"></span><br><span class="line"><span class="deletion">- <!--</span></span><br><span class="line"><span class="deletion">- <Connector port="8080" relaxedPathChars="[]|" relaxedQueryChars="[]|{}^\`"<>"</span></span><br><span class="line"><span class="deletion">- maxThreads="150" minSpareThreads="25" connectionTimeout="20000" enableLookups="false"</span></span><br><span class="line"><span class="deletion">- maxHttpHeaderSize="8192" protocol="HTTP/1.1" useBodyEncodingForURI="true" redirectPort="8443"</span></span><br><span class="line"><span class="deletion">- acceptCount="100" disableUploadTimeout="true" bindOnInit="false" secure="true" scheme="https"</span></span><br><span class="line"><span class="deletion">- proxyName="<subdomain>.<domain>.com" proxyPort="443"/></span></span><br><span class="line"><span class="deletion">- --></span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">#本行为~/Atlassian/jirasoftware/atlassian-jira-software-8.13.11-standalone/conf/server.xml的第62行(随着Jira Software的不断更新,本行对应在你的server.yml中不一定是第62行,请以实际情况为准)</span><br><span class="line"> <!--</span><br><span class="line"> <span class="comment">==============================================================================================================</span></span><br><span class="line"> HTTPS - Proxying Jira via Apache or Nginx over HTTPS</span><br><span class="line"></span><br><span class="line"> If you're proxying traffic to Jira over HTTPS, uncomment the below connector and comment out the others.</span><br><span class="line"> Ensure the proxyName and proxyPort are updated with the appropriate information if necessary as per the docs.</span><br><span class="line"></span><br><span class="line"> See the following for more information:</span><br><span class="line"></span><br><span class="line"> Apache - https://confluence.atlassian.com/x/PTT3MQ</span><br><span class="line"> nginx - https://confluence.atlassian.com/x/DAFmGQ</span><br><span class="line"> <span class="comment">==============================================================================================================</span></span><br><span class="line"> --></span><br><span class="line"></span><br><span class="line"><span class="addition">+ <Connector port="8081" relaxedPathChars="[]|" relaxedQueryChars="[]|{}^\`"<>"</span></span><br><span class="line"><span class="addition">+ maxThreads="150" minSpareThreads="25" connectionTimeout="20000" enableLookups="false"</span></span><br><span class="line"><span class="addition">+ maxHttpHeaderSize="8192" protocol="HTTP/1.1" useBodyEncodingForURI="true" redirectPort="8443"</span></span><br><span class="line"><span class="addition">+ acceptCount="100" disableUploadTimeout="true" bindOnInit="false" secure="true" scheme="https"</span></span><br><span class="line"><span class="addition">+ proxyName="proj.ql-isaac.cn" proxyPort="443"/></span></span><br></pre></td></tr></table></figure><p>编辑 Caddyfile,空一行,追加以下内容,重启 Caddy 服务:</p><figure class="highlight plaintext"><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">proj.ql-isaac.cn {</span><br><span class="line"> reverse_proxy 127.0.0.1:8081</span><br><span class="line">}</span><br></pre></td></tr></table></figure><div class="note info flat"><p>编辑 Caddyfile 和重启 Caddy 服务请见<a href="https://blog.ql-isaac.cn/2021/09/08/Building_Personal_Cloud_Services(1)/#code-server%5B1%5D%5B2%5D">本系列第一篇</a></p></div><p>启动 Jira:</p><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"><span class="built_in">cd</span> ~/Atlassian/jirasoftware/atlassian-jira-software-8.13.11-standalone/bin</span><br><span class="line">./start-jira.sh</span><br></pre></td></tr></table></figure><h3 id="设置_Jira_Software">设置 Jira Software<a class="headerlink" href="#设置_Jira_Software"></a></h3><p>现在,可以通过域名公网访问了,还需要完成最后几步,先将语言设置成中文,如下图。</p><p><img src="https://img.imql.life/illustrations/28607436351f6cce43ffe29dfead1d08.png" alt="language.png"></p><p>选择第二个,下一步:</p><p><img src="https://img.imql.life/illustrations/0f855596601f710d2aeedbc560e6e36b.png" alt="第二个.png"></p><p>选择“其他数据库”,设置数据库,密码就是上面自己设定的,设置好后可以点击测试连接,如下图,提示成功后下一步。</p><p><img src="https://img.imql.life/illustrations/da064fd03bb21779e6dd0f6df9b6364e.png" alt="测试连接成功.png"></p><p>心头一震,响应失败了:</p><p><img src="https://img.imql.life/illustrations/87276e62216bd8b1bf295476c2594f52.png" alt="无法处理此请求.png"></p><p>马上看了一下资源使用情况,如下图,好家伙,看来这 1h2g 的配置完全不够啊。</p><p><img src="https://img.imql.life/illustrations/8d0f8a7fd4ea6587215386e8e189ff14.png" alt="不堪重负.png"></p><p>等了许久,一直都显示的满负荷,去 TencentCloud Lighthouse 的监控页面看了一下,监控数据都接收不到,看来是死机了。</p><p>看了一下轻量无忧计划 2h4g 的费用,告辞,本次搭建失败。后面考虑自建服务器吧,玩玩树莓派?</p><hr class="footnotes-sep"><section class="footnotes"><ol class="footnotes-list"><li id="fn1" class="footnote-item"><p><a href="https://confluence.atlassian.com/adminjiraserver0813/connecting-jira-applications-to-mysql-5-7-1027137456.html">Connecting Jira applications to MySQL 5.7</a> <a href="#fnref1" class="footnote-backref">↩︎</a></p></li><li id="fn2" class="footnote-item"><p><a href="https://confluence.atlassian.com/doc/database-jdbc-drivers-171742.html">Database JDBC Drivers</a> <a href="#fnref2" class="footnote-backref">↩︎</a></p></li><li id="fn3" class="footnote-item"><p><a href="https://confluence.atlassian.com/adminjiraserver0813/supported-platforms-1027137429.html">Supported platforms</a> <a href="#fnref3" class="footnote-backref">↩︎</a></p></li><li id="fn4" class="footnote-item"><p><a href="https://confluence.atlassian.com/adminjiraserver0813/installing-jira-applications-on-linux-from-archive-file-1027137443.html">Installing Jira applications on Linux from Archive File</a> <a href="#fnref4" class="footnote-backref">↩︎</a></p></li></ol></section>]]></content>
<categories>
<category> 建立个人云服务 </category>
</categories>
<tags>
<tag> Ubuntu </tag>
<tag> JDK </tag>
<tag> Jira Software </tag>
<tag> Confluence </tag>
<tag> MySQL </tag>
<tag> MySQL Connector/J </tag>
</tags>
</entry>
<entry>
<title>我的第一个 npm 包?</title>
<link href="/2021/09/15/My_First_Npm_Package/"/>
<url>/2021/09/15/My_First_Npm_Package/</url>
<content type="html"><![CDATA[<p>npm,即 Node Package Manager,是随同 NodeJS 一起安装的包管理工具,本质是一个软件注册表。</p><span id="more"></span><p>不可告人的缘由,如下图,听说 jsdelivr 对 npm 上的文件限度会大一些,于是决定将我博文的 Gifs 发布到 npm 上,这就成为了我的第一个 npm 包。</p><p><img src="https://img.imql.life/illustrations/50c694e1f3352263471584aa0643638b.png" alt="20MB.png"></p><p>注册自己的 npm 账号:</p><p><img src="https://img.imql.life/illustrations/d6e44478fa235568a8f4ea82b1431323.png" alt="注册.png"></p><p>认证一下刚刚填写的邮箱:</p><p><img src="https://img.imql.life/illustrations/867ecb175942dd3dfa992edcec69d5ac.png" alt="Continue.png"></p><p>进入终端,SSH 方式克隆自己的 Gifs 远程仓库到本地:</p><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">git <span class="built_in">clone</span> [email protected]:isaac-ql/post-gifs-1.git</span><br></pre></td></tr></table></figure><div class="note info flat"><p>以上命令中@后面的域名为博主自己设置的别名,具体情况可见 <a href="https://www.imql.life/2021/08/22/Git_for_Windows_2/">Git for Windows(2)</a>。</p></div><p>执行以下命令添加 npm 用户,需要输入自己刚刚注册好的 npm 用户名、密码和邮箱。</p><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">npm adduser --registry https://registry.npmjs.org</span><br></pre></td></tr></table></figure><figure class="highlight plaintext"><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">Username: ql-isaac</span><br><span class="line">Password: <密码></span><br><span class="line">Email: (this IS public) [email protected]</span><br><span class="line">Logged in as ql-isaac on https://registry.npmjs.org/.</span><br></pre></td></tr></table></figure><p>此时如果你前往自己的账户,可注意到自动生成了一个 Token:</p><p><img src="https://img.imql.life/illustrations/1b32c28b470879e6c97730061f7de675.png" alt="Token.png"></p><div class="note info flat"><p>此 Token 的值记录在用户文件夹下的 .npmrc 中。</p></div><p>接着执行如下命令进行初始化。</p><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">npm init</span><br></pre></td></tr></table></figure><p>依次填写信息,回车确认:</p><p><img src="https://img.imql.life/illustrations/bd907e84b56eb84b754c15b4370fae13.png" alt="初始化" title="初始化"></p><p>执行如下命令,“稍稍”等待一会,Gifs 就被发布到 npm 上去了。</p><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">npm publish --registry https://registry.npmjs.org</span><br></pre></td></tr></table></figure><p>每次有新的 Gif 需要发布,都需要执行以上命令进行全量的发布,非常难受。这里可以利用 GitHub Actions 自动进行发布,我们只需将新的 Gif 推送到自己的 Gifs 远程仓库即可。</p><p>前往 npm 账户下,到达 Tokens 页面,选择 Generate New Token,输入密码,填写 Name 为 GitHub Actions,选择 Type 为 Automation,生成,如下图,复制生成的 Token,最好是先记到密码本中,以便发布其他的 npm 包时复用。</p><p><img src="https://img.imql.life/illustrations/539495dd87572f3b1b169b4b4e17394a.png" alt="image.png"></p><p>前往 Gifs 远程仓库,点击 Settings,点击 Secrets,再点击 New repository secret,填写 Name 为 NPM_TOKEN,右键粘贴以上 Token 为 Secret,点击 Add secret。</p><p>新建 GitHub Actions 文件:</p><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">vim .github/workflows/autopublish.yml</span><br></pre></td></tr></table></figure><figure class="highlight yaml"><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></pre></td><td class="code"><pre><span class="line"><span class="attr">name:</span> <span class="string">autopublish</span></span><br><span class="line"><span class="attr">on:</span></span><br><span class="line"> <span class="attr">push:</span></span><br><span class="line"> <span class="attr">branches:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">main</span></span><br><span class="line"></span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line"> <span class="attr">post-gifs-1:</span></span><br><span class="line"> <span class="attr">runs-on:</span> <span class="string">ubuntu-latest</span></span><br><span class="line"> <span class="attr">steps:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">uses:</span> <span class="string">actions/checkout@v3</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">uses:</span> <span class="string">actions/setup-node@v3</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">node-version:</span> <span class="string">"12.14.0"</span></span><br><span class="line"> <span class="attr">registry-url:</span> <span class="string">https://registry.npmjs.org/</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">run:</span> <span class="string">npm</span> <span class="string">publish</span></span><br><span class="line"> <span class="attr">env:</span></span><br><span class="line"> <span class="attr">NODE_AUTH_TOKEN:</span> <span class="string">${{secrets.NPM_TOKEN}}</span></span><br></pre></td></tr></table></figure><p>添加新的 Gif 后执行以下命令提交到本地仓库。</p><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">git add .</span><br><span class="line">git commit -m <span class="string">"xxxx"</span></span><br></pre></td></tr></table></figure><p>增加 npm 包版本号(最后一位版本号加一):</p><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">npm version patch</span><br></pre></td></tr></table></figure><p>推送到远程仓库:</p><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">git push</span><br></pre></td></tr></table></figure><p>不多时,便可看到 GitHub Actions 执行成功,前往 npm 账户下 Packages 页面,可看到我的第一个 npm 包的版本号变为 1.0.1。</p>]]></content>
<categories>
<category> NPM </category>
</categories>
</entry>
<entry>
<title>建立个人云服务(一)</title>
<link href="/2021/09/08/Building_Personal_Cloud_Services_1/"/>
<url>/2021/09/08/Building_Personal_Cloud_Services_1/</url>
<content type="html"><![CDATA[<p>静态网站的弊端就是不能随时随地的更新,这是我一直以来的痛。</p><span id="more"></span><h2 id="Codespaces">Codespaces<a class="headerlink" href="#Codespaces"></a></h2><p>Codespaces 是 GitHub 推出的在线编辑器,简单点说,就是可以实现将你本地的以 VsCode 为核心的开发环境迁移到云端,这样你只需要使用浏览器就可以随时随地进行开发,还可以多人协作。</p><p>目前这一云服务还不能免费使用,但是有一部分功能可以免费使用,那就是升级版的代码浏览编辑功能,请看下图。</p><p><img src="https://img.imql.life/illustrations/42521cac27e2ed0e5f75bd3274f75d06.png" alt="代码浏览编辑.png"></p><p>以<a href="https://github.com/ql-isaac/hexoblog">我的仓库</a>为例,在仓库页面,按下 <code>.</code>之后,天啊,这不就是 Web 版 VsCode 吗?</p><p><img src="https://img.imql.life/illustrations/6c78b410e2f10ad8c9821cc900eb9151.png" alt="hexoblog.png"></p><p>再结合 GitHub Actions,这不就实现了在线写博客了吗?</p><p>可是我突然又发现了另外一个痛点,这写完博客不能 <code>hexo s</code>预览怎么办?也不能升级主题什么的,到头来还是要在本地环境写博客预览发布。</p><h2 id="Code_Server">Code Server<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup><a class="headerlink" href="#Code_Server"></a></h2><p>我抓住网页端 VsCode 这一关键词,果然搜到了这个开源项目 <a href="https://github.com/cdr/code-server">code-server</a>,那么,我之前买的腾讯云无忧实例就有用武之地了。</p><p>SSH 方式登录实例,我的实例是 Ubuntu 18.04 的,执行如下命令,其中 $VERSION 替换为版本号。</p><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">curl -fOL https://github.com/cdr/code-server/releases/download/v<span class="variable">$VERSION</span>/code-server_<span class="variable">$VERSION_amd64</span>.deb</span><br></pre></td></tr></table></figure><p>发现根本下不动,正常正常。其实以上命令就是下载那个 deb 包,于是直接在仓库 Releases 页面下载然后上传到实例中,下载速度还不赖。</p><p>上传完成后,就是安装了,安装命令如下。</p><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">sudo dpkg -i code-server_<span class="variable">$VERSION_amd64</span>.deb</span><br></pre></td></tr></table></figure><p>最后启用并启动服务,其中 $USER 替换为你自己的用户名,这个各位自定义即可。</p><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">sudo systemctl <span class="built_in">enable</span> --now code-server@<span class="variable">$USER</span></span><br></pre></td></tr></table></figure><p>现在,就可以访问本地 8080 端口了,此时如果你以为也可以通过实例的公网 IP 加端口访问到 code-server 就大错特错了。我一开始也是这么以为,在实例控制台放行了端口还是不行,原来目前只是本地运行,要想暴露在公网,需要使用 HTTPS,code-server 的官方文档提供给了几种解决办法,我使用的是 Caddy,它类似于 Nginx,但相比之下它最大的一个特点是能帮你自动申请域名的数字证书。</p><p>首先是到自己的域名服务商那里添加一个 A 记录,主机记录就填 dev,记录值填实例的公网 IP,接着就是安装 Caddy,依次执行以下命令。</p><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">sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https</span><br><span class="line">curl -1sLf <span class="string">'https://dl.cloudsmith.io/public/caddy/stable/cfg/gpg/gpg.155B6D79CA56EA34.key'</span> | sudo apt-key add -</span><br><span class="line">curl -1sLf <span class="string">'https://dl.cloudsmith.io/public/caddy/stable/cfg/setup/config.deb.txt?distro=debian&version=any-version'</span> | sudo <span class="built_in">tee</span> -a /etc/apt/sources.list.d/caddy-stable.list</span><br><span class="line">sudo apt update</span><br><span class="line">sudo apt install caddy</span><br></pre></td></tr></table></figure><p>接着执行如下命令编辑 Caddyfile。</p><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">sudo vim /etc/caddy/Caddyfile</span><br></pre></td></tr></table></figure><p>删除原来的内容,进行如下配置。</p><figure class="highlight plaintext"><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">dev.ql-isaac.cn {</span><br><span class="line"> reverse_proxy 127.0.0.1:8080</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>最后重启 Caddy 服务:</p><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">sudo systemctl reload caddy</span><br></pre></td></tr></table></figure><p>这时,就可以通过域名公网访问了:</p><p><img src="https://img.imql.life/illustrations/6b12700e9b9a8d18ae35952048354a5f.png" alt="公网访问.png"></p><p>以上的密码可以打开 config.yaml 查看:</p><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">cat</span> ~/.config/code-server/config.yaml</span><br></pre></td></tr></table></figure><p>或者自己设定密码,$USER 替换为你自己的用户名:</p><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">vim ~/.config/code-server/config.yaml</span><br><span class="line">sudo systemctl restart code-server@<span class="variable">$USER</span></span><br></pre></td></tr></table></figure><p>手机端也可以用:</p><p><img src="https://img.imql.life/illustrations/034e78ef8dd87a82865fb412df6d8a82.jpeg" alt="手机端" title="手机端"></p><hr class="footnotes-sep"><section class="footnotes"><ol class="footnotes-list"><li id="fn1" class="footnote-item"><p><a href="https://github.com/cdr/code-server/blob/main/docs/guide.md#using-lets-encrypt-with-caddy">code-server 指导</a> <a href="#fnref1" class="footnote-backref">↩︎</a></p></li></ol></section>]]></content>
<categories>
<category> 建立个人云服务 </category>
</categories>
<tags>
<tag> Ubuntu </tag>
<tag> Code Server </tag>
</tags>
</entry>
<entry>
<title>Windows 10 封装实践</title>
<link href="/2021/08/29/The_Practice_of_Windows_10_Encapsulation/"/>
<url>/2021/08/29/The_Practice_of_Windows_10_Encapsulation/</url>
<content type="html"><![CDATA[<p>制作一个属于自己的操作系统镜像,想想就是一件很有意义的事情!</p><span id="more"></span><h2 id="准备工作">准备工作<a class="headerlink" href="#准备工作"></a></h2><ol><li>准备一个 U 盘,将优启通、Easy Sysprep5、Windows 10 (business edition) ISO 镜像和 Dism++ 等放进去;</li><li>使用优启通制作 PE(选择生成 ISO 的制作方式);</li></ol><p><img src="https://img.imql.life/illustrations/ab9578864fe04b0991428e43c6cab603.png" alt="生成ISO" title="生成ISO"></p><ol start="3"><li>安装 VMware pro 15。下载<a href="https://www.52pojie.cn/thread-1026907-1-1.html">学习版</a>,安装步骤不多说了。</li></ol><h2 id="创建系统封装环境">创建系统封装环境<a class="headerlink" href="#创建系统封装环境"></a></h2><ol><li>创建新的虚拟机;</li></ol><p><img src="https://img.imql.life/illustrations/f848e367cb39d41907e0cdec5c6a0fb8.png" alt="创建新的虚拟机" title="创建新的虚拟机"></p><ol start="2"><li>选择典型;</li></ol><p><img src="https://img.imql.life/illustrations/fdbbd160fa14f876b09a4cf53954ee88.png" alt="典型" title="典型"></p><ol start="3"><li>选择安装程序光盘映像文件(iso),选择在准备工作中制作好的 ISO;</li></ol><p><img src="https://img.imql.life/illustrations/7407030df93e801b00a22366e1575bb1.png" alt="安装程序光盘映像文件" title="安装程序光盘映像文件"></p><ol start="4"><li>选择客户机操作系统,按图选择即可;</li></ol><p><img src="https://img.imql.life/illustrations/9fa1d34992d5d69174446c19ca0d516b.png" alt="选择客户机操作系统" title="选择客户机操作系统"></p><ol start="5"><li>命名虚拟机。注意默认虚拟机文件的存放位置是用户文件夹下,建议改到非 C 盘;</li></ol><p><img src="https://img.imql.life/illustrations/a95e6ac3da4fbd28a3d1e45ab265697a.png" alt="命名虚拟机" title="命名虚拟机"></p><ol start="6"><li>指定磁盘容量,考虑到会封装许多软件,容量调大些,比如 100G;</li></ol><p><img src="https://img.imql.life/illustrations/6ae8d8a0326de4d0827e74f0f7a30acb.png" alt="指定磁盘容量" title="指定磁盘容量"></p><ol start="7"><li>完成。</li></ol><p><img src="https://img.imql.life/illustrations/43639e80781b9c051723a090801814d9.png" alt="完成" title="完成"></p><h2 id="安装_Windows_10-2">安装 Windows 10<a class="headerlink" href="#安装_Windows_10-2"></a></h2><p>开启此虚拟机,意外发生了:</p><p><img src="https://img.imql.life/illustrations/9df2d0504e42aca52db109158687b897.png" alt="意外发生了" title="意外发生了"></p><p>百度到了办法,先关一下机,点击编辑虚拟机设置,在高级中,固件类型选择 BIOS,确定,再开启虚拟机:</p><p><img src="https://img.imql.life/illustrations/5f1d7b69b4695dc3691eaeb2b1374b96.png" alt="固件类型" title="固件类型"></p><p>选择第二个进入 PE:</p><p><img src="https://img.imql.life/illustrations/ac4dceb69070ad31f183283d043ae7e8.png" alt="第二个" title="第二个"></p><p>挂载 U 盘,选择准备好的 U 盘,我这里显示的是已经挂载好了的状态:</p><p><img src="https://img.imql.life/illustrations/978f2590503a9001f0c1bb93e080c672.png" alt="挂载U盘" title="挂载U盘"></p><p>桌面上,双击 DG 硬盘分区,选择 100G 的虚拟硬盘,即我们上面分配的,点击快速分区,设置成一个分区就行:</p><p><img src="https://img.imql.life/illustrations/be78f84051e9b04ef95d6e73c15ac5ca.png" alt="快速分区" title="快速分区"></p><p>再双击桌面中的 EIX 系统安装,左侧已经自动识别到我们 U 盘上的镜像,选择 Windows 10 专业版,右侧则是刚刚创建的那个分区,单击选择上,点击一键恢复:</p><p><img src="https://img.imql.life/illustrations/7e56df19ac9491762d18dba33978e8cd.png" alt="EIX系统安装" title="EIX系统安装"></p><p>这里将“恢复完成后自动运行万能驱动”勾掉,确认,等待重启:</p><p><img src="https://img.imql.life/illustrations/ec174dbfb0529bdda0d3c2acd5bc93cb.png" alt="勾掉" title="勾掉"></p><h2 id="进入审核模式">进入审核模式<a class="headerlink" href="#进入审核模式"></a></h2><p>重启之后就到了这个熟悉的流程(OOBE):</p><p><img src="https://img.imql.life/illustrations/aeebdc8e9356d346ca64a7e275a233b3.png" alt="OOBE" title="OOBE"></p><p>不要着急点是,这里要按<code>Ctrl</code>+<code>Shift</code>+<code>F3</code>进入审核模式,刚进入是这样的:</p><p><img src="https://img.imql.life/illustrations/c314b46361f31829113995a58571ad86.png" alt="审核模式" title="审核模式"></p><p>注意不要点确定,点了就又退回到 OOBE 了,这里点取消:</p><p><img src="https://img.imql.life/illustrations/091c55bb3c6cd07f62381625b979b851.png" alt="取消" title="取消"></p><h2 id="系统调整">系统调整<a class="headerlink" href="#系统调整"></a></h2><div class="note primary flat"><p>以下调整带有本人倾向,仅供参考,请根据实际需要进行调整。</p></div><ol><li>系统激活,这个就不多说了;</li><li>系统更新;</li><li>桌面图标设置。我习惯将“计算机”和“控制面板”显示出来;</li></ol><p><img src="https://img.imql.life/illustrations/29bbad8eae0d02d7197f31a80a6a8a35.png" alt="桌面图标设置.png"></p><ol start="5"><li>颜色偏爱设置。默认 Windows 模式改为浅色,透明效果打开,选择从我的背景自动选取一种主题色;</li></ol><p><img src="https://img.imql.life/illustrations/438909f09b272910da69be93dbb48928.png" alt="颜色" title="颜色"></p><ol start="6"><li>显示搜索图标。感觉搜索框太占地方了;</li></ol><p><img src="https://img.imql.life/illustrations/796322da21fefa25863f20e04cc1c133.png" alt="显示搜索图标" title="显示搜索图标"></p><ol start="7"><li>装上 Telnet 客户端。这样可以在 CMD 中使用<code>telnet</code>检测目标主机 TCP 端口是否开启;</li></ol><p><img src="https://img.imql.life/illustrations/9221f04d76d71714659ac05ecea1a8ad.png" alt="Telnet 客户端" title="Telnet 客户端"></p><ol start="8"><li>显示文件扩展名,这个必设;</li></ol><p><img src="https://img.imql.life/illustrations/ae57ed8954b6190968a0e9577801a913.png" alt="文件扩展名" title="文件扩展名"></p><ol start="9"><li>最后使用 Dism++ 对系统进行优化。</li></ol><p><img src="https://img.imql.life/illustrations/500e590ebc88c017ecc5960ea6f94998.png" alt="任务栏时钟精确到秒" title="任务栏时钟精确到秒"></p><p><img src="https://img.imql.life/illustrations/e09c672f3314f4f0a9a04f72c4a1671b.png" alt="桌面壁纸质量调整" title="桌面壁纸质量调整"></p><p><img src="https://img.imql.life/illustrations/17c97d5257e30f6f2db3644a81ebbe9a.png" alt="打开资源管理器时显示此电脑" title="打开资源管理器时显示此电脑"></p><p><img src="https://img.imql.life/illustrations/57d0a19cd8dbd1e7c7e2a0ec571162f3.png" alt="最小化时显示完整路径" title="最小化时显示完整路径"></p><h2 id="预装软件">预装软件<a class="headerlink" href="#预装软件"></a></h2><div class="note primary flat"><p>以下为个人认为必装的软件,请根据实际需要安装。</p></div><ol><li><a href="https://code.visualstudio.com/">前往官网下载 Visual Studio Code</a>,安装,建议勾上如图的选项;</li></ol><p><img src="https://img.imql.life/illustrations/93c9fe7332e3d211e15f8a3ab2215c6a.png" alt="VSCode" title="VSCode"></p><ol start="3"><li><a href="https://pcmanager.microsoft.com/">前往官网下载微软电脑管家</a>,快速安装即可;</li><li><a href="https://im.qq.com/pcqq">前往官网下载 QQ</a>,立即安装即可;</li><li><a href="https://www.wegame.com.cn/">前往官网下载 WeGame 客户端</a>,立即安装即可;</li><li><a href="https://www.epicgames.com/site/zh-CN/home">前往官网下载 Epic Games 客户端</a>,下一步即可;</li><li><a href="https://store.steampowered.com/">前往官网下载 Steam 客户端</a>,下一步即可。</li></ol><h2 id="系统清理">系统清理<a class="headerlink" href="#系统清理"></a></h2><p>使用微软电脑管家清理优化一下。</p><p><img src="https://img.imql.life/illustrations/7ba529df528b7429c47a1c9e97c85071.png" alt="清理优化" title="清理优化"></p><h2 id="拍摄快照">拍摄快照<a class="headerlink" href="#拍摄快照"></a></h2><p>在开始封装前拍摄一个快照,如下图,快照名称就为当天的日期,这样以后可以恢复进行再封装。</p><p><img src="https://img.imql.life/illustrations/27784d2982d6c7c084eed8916f771c2a.png" alt="拍摄快照" title="拍摄快照"></p><h2 id="ES5_封装">ES5 封装<a class="headerlink" href="#ES5_封装"></a></h2><p>运行 U 盘中的 Easy Sysprep5,点击设置,图中标记处自定义一下,其他地方根据需要设置,对于个人的话其他默认就行,点击封装、确定,等待上方提示完毕,重启进入 PE 执行第二阶段。</p><p><img src="https://img.imql.life/illustrations/6e9d574dab30c84e3c67e23e7392761d.png" alt="开始封装" title="开始封装"></p><p>重点来了!点击重启之后请不停按<code>F2</code>,直到进入 BIOS:</p><p><img src="https://img.imql.life/illustrations/168f77860f007b9f0a7dbf142544f80f.png" alt="进入BIOS" title="进入BIOS"></p><p>重点没玩,左右键移动到“Boot”,然后让“CD-ROM Drive”往上移动两格,<code>F10</code>保存退出:</p><p><img src="https://img.imql.life/illustrations/9f7e53ace77a35acd3ff7ca2ef25ad3b.png" alt="调整启动顺序" title="调整启动顺序"></p><p>还没完,<code>F10</code>保存退出后按两次回车,到这里也是选择第二个:</p><p><img src="https://img.imql.life/illustrations/837a5cd6eb6a369c6266edae31ac5672.png" alt="第二个" title="第二个"></p><p>再次运行 Easy Sysprep5,点击设置,优化栏里全不勾选,不需要:</p><p><img src="https://img.imql.life/illustrations/4775d8dae786c58c59fbc236e4864547.png" alt="全不勾选" title="全不勾选"></p><p>部署栏里,我按下图设置的,供参考。</p><p><img src="https://img.imql.life/illustrations/a6cca17af3b10e0c8f3bc0926b8f20a5.png" alt="部署栏" title="部署栏"></p><p>系统栏里,我按下图设置的,供参考。</p><p><img src="https://img.imql.life/illustrations/b460472421d3662aff519b5beef0e662.png" alt="系统栏" title="系统栏"></p><p>用户栏里,我按下图设置的,供参考。</p><p><img src="https://img.imql.life/illustrations/b32019d14311704a2a8f8190c171dd09.png" alt="用户栏" title="用户栏"></p><p>其他栏中,有如图的注意,最后点击封装,确定,等待镜像备份完毕,此镜像即为封装好的镜像。</p><p><img src="https://img.imql.life/illustrations/b15516504c127717d85fe60ab3ab37cc.png" alt="其他栏" title="其他栏"></p><p>镜像备份完毕后重启,不用进行任何操作,部署中,即立即安装刚封装好的镜像,如下图。</p><p><img src="https://img.imql.life/illustrations/de9a6e1046ee9515a960bf28cc3af6f2.png" alt="部署" title="部署"></p>]]></content>
<categories>
<category> PC </category>
</categories>
<tags>
<tag> VMware Workstation </tag>
<tag> Windows </tag>
<tag> 优启通 </tag>
<tag> Easy Sysprep </tag>
</tags>
</entry>
<entry>
<title>Git for Windows(2)</title>
<link href="/2021/08/22/Git_for_Windows_2/"/>
<url>/2021/08/22/Git_for_Windows_2/</url>
<content type="html"><![CDATA[<p>来记录一下 Git for Windows 的使用。</p><span id="more"></span><h2 id="创建_GitHub_小号后">创建 GitHub 小号后<a class="headerlink" href="#创建_GitHub_小号后"></a></h2><p>不可告人的缘由,我需要另外创建一个 GitHub 小号(<a href="https://github.com/isaac-ql">isaac-ql</a>),创建完账号后,就应该是去绑定个人电脑的 SSH key,我想当然的以为可以复用建博客时生成的 SSH key,结果 GitHub 给我了这个提示:</p><p><img src="https://img.imql.life/illustrations/16c8a802260e992d0ff628fdcc524a92.png" alt="Key_is_already_in_use.png"></p><p>好吧,看来是不能复用。百度一番后,解决办法如下:</p><ol><li>右键,点击 Git Bash Here,执行以下命令,生成另外一对公钥与私钥,不能与之前的重名:</li></ol><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">ssh-keygen -t rsa -f ~/.ssh/<自定义 SSH key 文件名></span><br></pre></td></tr></table></figure><ol start="2"><li>将公钥添加到自己的小号里,不多说了;</li><li>进入 .ssh 文件夹(在用户文件夹下),新建文件 config(注意 config 是完整文件名),编辑:</li></ol><figure class="highlight diff"><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="addition">+Host github.com</span></span><br><span class="line"><span class="addition">+ HostName github.com</span></span><br><span class="line"><span class="addition">+ PreferredAuthentications publickey</span></span><br><span class="line"><span class="addition">+ IdentityFile ~/.ssh/id_rsa</span></span><br><span class="line"><span class="addition">+Host <自定义别名></span></span><br><span class="line"><span class="addition">+ HostName github.com</span></span><br><span class="line"><span class="addition">+ PreferredAuthentications publickey</span></span><br><span class="line"><span class="addition">+ IdentityFile ~/.ssh/<自定义 SSH key 文件名></span></span><br></pre></td></tr></table></figure><ol start="3"><li>以后在以 SSH 方式克隆 GitHub 小号时,将原来的地址@后面的域名改为以上的自定义别名即可。</li></ol><h2 id="HTTP_方式克隆加速">HTTP 方式克隆加速<a class="headerlink" href="#HTTP_方式克隆加速"></a></h2><p>如下图,<code>git clone</code>很慢怎么办?</p><p><img src="https://img.imql.life/illustrations/f8ab0b02f0dd8b5d1265183d6a4c2356.png" alt="克隆很慢.png"></p><p>请那啥之后设置代理(我使用的代理软件是 Clash):</p><ol><li>要那啥,此处省略一百个字;</li><li>右键,点击 Git Bash Here,依次执行以下命令;</li></ol><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">export</span> https_proxy=http://127.0.0.1:<代理端口></span><br></pre></td></tr></table></figure><div class="note info flat"><p>以上命令是设置环境变量,只在当前终端中有效,也可以执行以下命令修改配置以一直生效:</p><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">git config --global https.proxy http://127.0.0.1:<代理端口></span><br></pre></td></tr></table></figure></div><ol start="3"><li>打开 Clash 的全局代理;</li><li>起飞,还没开始截图就克隆完毕了。</li></ol><p><img src="https://img.imql.life/illustrations/1cb928d6f24e5305fbed61da090326c0.png" alt="起飞.png"></p>]]></content>
<categories>
<category> Git for Windows </category>
</categories>
</entry>
<entry>
<title>什么是 GitHub?</title>
<link href="/2021/08/14/What_is_GitHub/"/>
<url>/2021/08/14/What_is_GitHub/</url>
<content type="html"><![CDATA[<p>“hub”,乃中心之意,当你看了我的另外一篇<a href="https://www.ql-isaac.cn/2020/01/24/What_is_Git/">《什么是 Git》</a>,对 Git 已经熟悉一些的时候,就会自然明白"GitHub"的含义。</p><span id="more"></span><h2 id="git_commit_规范化">git commit 规范化<a class="headerlink" href="#git_commit_规范化"></a></h2><h3 id="命令格式">命令格式<a class="headerlink" href="#命令格式"></a></h3><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">git commit -m <span class="string">"<emoji代码> <type>(<scope>): <subject>"</span></span><br></pre></td></tr></table></figure><h3 id="emoji_代码">emoji 代码<a class="headerlink" href="#emoji_代码"></a></h3><p><a href="https://gitmoji.dev/">这里有一套约定俗成的 emoji 使用规范</a>,常用的如下表:</p><table><thead><tr><th>emoji</th><th>emoji 代码</th><th>commit 说明</th></tr></thead><tbody><tr><td>🎨 (调色板)</td><td><code>:art:</code></td><td>改进代码结构/代码格式</td></tr><tr><td>⚡️ (闪电) /🐎 (赛马)</td><td><code>:zap:</code>/<code>:racehorse:</code></td><td>提升性能</td></tr><tr><td>🔥 (火焰)</td><td><code>:fire:</code></td><td>移除代码或文件</td></tr><tr><td>🐛 (bug)</td><td><code>:bug:</code></td><td>修复 bug</td></tr><tr><td>🚑 (急救车)</td><td><code>:ambulance:</code></td><td>重要补丁</td></tr><tr><td>✨ (火花)</td><td><code>:sparkles:</code></td><td>引入新功能</td></tr><tr><td>📝 (备忘录)</td><td><code>:memo:</code></td><td>撰写文档</td></tr><tr><td>🚀 (火箭)</td><td><code>:rocket:</code></td><td>部署功能</td></tr><tr><td>💄 (口红)</td><td><code>:lipstick:</code></td><td>更新 UI 和样式文件</td></tr><tr><td>🎉 (庆祝)</td><td><code>:tada:</code></td><td>初次提交</td></tr><tr><td>✅ (白色复选框)</td><td><code>:white_check_mark:</code></td><td>更新测试</td></tr><tr><td>🔒 (锁)</td><td><code>:lock:</code></td><td>修复安全问题</td></tr><tr><td>🍎 (苹果)</td><td><code>:apple:</code></td><td>修复 macOS 下的问题</td></tr><tr><td>🐧 (企鹅)</td><td><code>:penguin:</code></td><td>修复 Linux 下的问题</td></tr><tr><td>🏁 (旗帜)</td><td><code>:checkered_flag:</code></td><td>修复 Windows 下的问题</td></tr><tr><td>🤖(机器人)</td><td><code>:robot:</code></td><td>修复 Android 下的问题</td></tr><tr><td>🍏 (绿苹果)</td><td><code>:green_apple:</code></td><td>修复 iOS 下的问题</td></tr><tr><td>🔖 (书签)</td><td><code>:bookmark:</code></td><td>发行/版本标签</td></tr><tr><td>🚨 (警车灯)</td><td><code>:rotating_light:</code></td><td>移除 linter 警告</td></tr><tr><td>🚧 (施工)</td><td><code>:construction:</code></td><td>工作进行中</td></tr><tr><td>👷 (工人)</td><td><code>:construction_worker:</code></td><td>添加 CI 构建系统</td></tr><tr><td>💚 (绿心)</td><td><code>:green_heart:</code></td><td>修复 CI 构建问题</td></tr><tr><td>⬆️ (上升箭头)</td><td><code>:arrow_up:</code></td><td>升级依赖</td></tr><tr><td>⬇️ (下降箭头)</td><td><code>:arrow_down:</code></td><td>降级依赖</td></tr><tr><td>📌 (图钉)</td><td><code>:pushpin:</code></td><td>将依赖项固定到特定版本</td></tr><tr><td>📈 (上升趋势图)</td><td><code>:chart_with_upwards_trend:</code></td><td>添加分析或跟踪代码</td></tr><tr><td>♻️ (回收)</td><td><code>:recycle:</code></td><td>重构代码</td></tr><tr><td>🐳 (鲸鱼)</td><td><code>:whale:</code></td><td>Docker 相关工作</td></tr><tr><td>🌐 (带子午线的地球仪)</td><td><code>:globe_with_meridians:</code></td><td>国际化与本地化</td></tr><tr><td>➕ (加号)</td><td><code>:heavy_plus_sign:</code></td><td>增加一个依赖</td></tr><tr><td>➖ (减号)</td><td><code>:heavy_minus_sign:</code></td><td>减少一个依赖</td></tr><tr><td>🔧 (扳手)</td><td><code>:wrench:</code></td><td>修改配置文件</td></tr><tr><td>🔨 (锤子)</td><td><code>:hammer:</code></td><td>重大重构</td></tr><tr><td>✏️ (铅笔)</td><td><code>:pencil2:</code></td><td>修复 typo</td></tr><tr><td>💩 (粑粑…)</td><td><code>:poop:</code></td><td>写了辣鸡代码需要优化</td></tr><tr><td>⏪ (倒带)</td><td><code>:rewind:</code></td><td>恢复更改</td></tr><tr><td>🔀 (交叉向右的箭头)</td><td><code>:twisted_rightwards_arrows:</code></td><td>合并分支</td></tr><tr><td>📦 (包裹)</td><td><code>:package:</code></td><td>更新编译的文件或包</td></tr><tr><td>👽 (外星人)</td><td><code>:alien:</code></td><td>由于外部 API 更改而更新代码</td></tr><tr><td>🚚 (货车)</td><td><code>:truck:</code></td><td>移动或者重命名文件</td></tr><tr><td>📄 (正面朝上的页面)</td><td><code>:page_facing_up:</code></td><td>增加或更新许可证书</td></tr><tr><td>💥 (爆炸)</td><td><code>:boom:</code></td><td>引入突破性的变化</td></tr><tr><td>🍱 (铅笔)</td><td><code>:bento:</code></td><td>增加或更新资源</td></tr><tr><td>👌 (OK 手势)</td><td><code>:ok_hand:</code></td><td>由于代码审查更改而更新代码</td></tr><tr><td>♿️ (轮椅)</td><td><code>:wheelchair:</code></td><td>改善无障碍交互</td></tr><tr><td>💡 (灯泡)</td><td><code>:bulb:</code></td><td>给代码添加注释</td></tr><tr><td>🍻 (啤酒)</td><td><code>:beers:</code></td><td>醉醺醺地写代码…</td></tr><tr><td>💬 (消息气泡)</td><td><code>:speech_balloon:</code></td><td>更新文本文档</td></tr><tr><td>🗃 (卡片文件盒)</td><td><code>:card_file_box:</code></td><td>执行与数据库相关的更改</td></tr><tr><td>🔊 (音量大)</td><td><code>:loud_sound:</code></td><td>增加日志</td></tr><tr><td>🔇 (静音)</td><td><code>:mute:</code></td><td>移除日志</td></tr><tr><td>👥 (轮廓中的半身像)</td><td><code>:busts_in_silhouette:</code></td><td>增加贡献者</td></tr><tr><td>🚸 (孩童通行)</td><td><code>:children_crossing:</code></td><td>优化用户体验、可用性</td></tr><tr><td>🏗 (建筑建造)</td><td><code>:building_construction:</code></td><td>结构变动</td></tr><tr><td>📱 (iPhone)</td><td><code>:iphone:</code></td><td>做响应式设计</td></tr><tr><td>🤡 (小丑脸)</td><td><code>:clown_face:</code></td><td>嘲弄事物(直译,这个没明白)</td></tr><tr><td>🥚 (鸡蛋)</td><td><code>:egg:</code></td><td>增加彩蛋</td></tr><tr><td>🙈 (看不见邪恶)</td><td><code>:see_no_evil:</code></td><td>增加或更改 gitignore</td></tr><tr><td>📸 (照相机闪光灯)</td><td><code>:camera_flash:</code></td><td>增加或更新截图</td></tr><tr><td>⚗️ (蒸馏器)</td><td><code>:alembic:</code></td><td>尝试新东西</td></tr><tr><td>🔍 (放大镜)</td><td><code>:mag:</code></td><td>SEO 优化</td></tr><tr><td>☸️ (船的方向盘)</td><td><code>:wheel_of_dharma:</code></td><td>关于 Kubernetes 的工作</td></tr><tr><td>🏷 (标签)</td><td><code>:label:</code></td><td>增加类型(FLow、Typescript)</td></tr></tbody></table><h3 id="type">type<a class="headerlink" href="#type"></a></h3><p>用于说明 commit 的类别,有下表所示的可选项:</p><table><thead><tr><th>类别</th><th>含义</th></tr></thead><tbody><tr><td><code>feat</code></td><td>新功能(feature)</td></tr><tr><td><code>fix/to</code></td><td>修复 bug,可以是 QA 发现的 BUG,也可以是研发自己发现的 BUG。<code>fix</code>:产生 diff 并自动修复此问题,适用于一次提交直接修复问题。 <code>to</code>:只产生 diff 不自动修复此问题,适用于多次提交,最终修复问题提交时使用 fix</td></tr><tr><td><code>docs</code></td><td>文档(documentation)</td></tr><tr><td><code>style</code></td><td>格式(不影响代码运行的变动)</td></tr><tr><td><code>refactor</code></td><td>重构(即不是新增功能,也不是修改 bug 的代码变动)</td></tr><tr><td><code>perf</code></td><td>优化相关,比如提升性能、体验</td></tr><tr><td><code>test</code></td><td>增加测试</td></tr><tr><td><code>chore</code></td><td>构建过程或辅助工具的变动</td></tr><tr><td><code>revert</code></td><td>回滚到上一个版本</td></tr><tr><td><code>merge</code></td><td>代码合并</td></tr><tr><td><code>sync</code></td><td>同步主线或分支的 Bug</td></tr></tbody></table><h3 id="scope">scope<a class="headerlink" href="#scope"></a></h3><p>用于说明 commit 影响的范围,比如数据层、控制层、视图层等等,scope 可以省略。如果 commit 影响了不止一个 scope,可以使用<code>*</code>。</p><h3 id="subject">subject<a class="headerlink" href="#subject"></a></h3><p>这个就是 commit 的说明了,不超过 50 个字符,结尾不加标点符号。</p><h3 id="示例">示例<a class="headerlink" href="#示例"></a></h3><p>某次提交:</p><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">git commit -m <span class="string">":art: style: 格式修改"</span></span><br></pre></td></tr></table></figure><p>GitHub 上的效果图:</p><p><img src="https://img.imql.life/illustrations/2f86183c15ea9fb3551e9ebc8e9898cf.png" alt="提交示例" title="提交示例"></p><h2 id="Fork">Fork<a class="headerlink" href="#Fork"></a></h2><p>GitHub 是一个宝库,每当发现一个有趣的仓库,我们不仅仅会去点一个 Star(收藏)或 Watch(关注),我们还会去 Fork 一下该开源仓库:</p><p><img src="https://img.imql.life/illustrations/520d3e0bd0b460d45064eff773cb72c8.png" alt="Fork" title="Fork"></p><p>这样,该仓库会被克隆一份成为自己的仓库:</p><p><img src="https://img.imql.life/illustrations/9a1c2edb10035cba981168383170791b.png" alt="自己的仓库" title="自己的仓库"></p><p>之后原仓库是不断有作者在更新,自己的仓库也想获得这些更新怎么办?其实很简单,如下图,这里正是在提示你原仓库的 main 分支已经超前了 13 次提交。</p><p><img src="https://img.imql.life/illustrations/8db197fb2c48e4314982940bc343fd17.png" alt="upstream" title="upstream"></p><p>我们只需要点击右侧的 Fetch upstream 从原仓库进行拉取,这样自己这边的仓库也是最新的了。</p><p><img src="https://img.imql.life/illustrations/4947b1eb819e76189076e269fd844d65.png" alt="fetch" title="fetch"></p><h2 id="GitHub_Actions">GitHub Actions<a class="headerlink" href="#GitHub_Actions"></a></h2>]]></content>
<categories>
<category> Git 和 GitHub 从入门到实践 </category>
</categories>
</entry>
<entry>
<title>Git for Windows(1)</title>
<link href="/2021/01/03/Git_for_Windows_1/"/>
<url>/2021/01/03/Git_for_Windows_1/</url>
<content type="html"><![CDATA[<p>来记录一下 Git for Windows 的使用。</p><span id="more"></span><p>每次打开 VS Code 时右下角总提示这个,还是更新一下吧,直接点击更新 GIT。</p><p><img src="https://img.imql.life/illustrations/fb328d651f90b0b7d5b1ed17a769ad1b.png" alt="更新GIT.png"></p><p>原来是跳转到 Git 官网。</p><p><img src="https://img.imql.life/illustrations/49642368a8b49a9e27a6140151119c56.png" alt="Git官网.png"></p><p>这里会跳转到 IE 浏览器,呵呵,赶紧到 Windows 的所有设置-应用-默认应用中把 Web 浏览器设置成 Microsoft Edge 再打开 Git 官网。</p><p><img src="https://img.imql.life/illustrations/ad6888a2fea387856d8baa033dc53ac7.png" alt="Microsoft-Edge.png"></p><p>常规操作:下载,双击安装。</p><p><img src="https://img.imql.life/illustrations/08bb2e08290e40db3eb9e69936fa637a.png" alt="下载安装.png"></p><p>Only show new option,嗯,很人性化!好评!</p><p><img src="https://img.imql.life/illustrations/11235d61743499c09ee4213e948bac64.png" alt="Only-show-new-option.png"></p><p>勾选第二个,以后用<code>git init</code>初始化仓库时默认分支名就为 main 了。</p><div class="note info flat"><p>由于某些原因,2020 年 10 月 1 日,GitHub 将启用 main 作为默认分支名,master 将成为历史!</p></div><p><img src="https://img.imql.life/illustrations/fb85638f9e675246e96c768a2e0508fe.png" alt="main.png"></p><p>这个直接 Next,默认即可。</p><p><img src="https://img.imql.life/illustrations/9889adc45794ac4f9332a62f87c57626.png" alt="默认.png"></p><p>credential helper,凭据帮助器?这是个什么玩意儿?star 一下这个<a href="https://github.com/microsoft/Git-Credential-Manager-Core">cross-platform version of the Git Credential Manager</a>先,有时间看看(虽然看不懂)。</p><p><img src="https://img.imql.life/illustrations/820471caf59fe166a007826c487eca93.png" alt="credential-helper.png"></p><p>实验性的选项:允许在 Git Bash 窗口中运行原生控制台程序,如 Node 或 Python,而不使用 winpty,但它仍然有已知的 bug,不勾选。</p><p><img src="https://img.imql.life/illustrations/a0638f800a6f973846264a1c6c3574b8.png" alt="实验性的选项.png"></p><p>安装中:</p><p><img src="https://img.imql.life/illustrations/99ff20fbaedc4a6c0c745f6b75a46b20.png" alt="安装中.png"></p><p>完成:</p><p><img src="https://img.imql.life/illustrations/9bca4345653a15db144629de460eb41a.png" alt="完成.png"></p><p>Release Notes:</p><p><img src="https://img.imql.life/illustrations/78ac6dacbde953b924dec8b941e39491.png" alt="Release_Notes.png"></p>]]></content>
<categories>
<category> Git for Windows </category>
</categories>
</entry>
<entry>
<title>我的主页</title>
<link href="/2020/09/26/My_homepage_with_Butterfly/"/>
<url>/2020/09/26/My_homepage_with_Butterfly/</url>
<content type="html"><![CDATA[<p>简洁却不简单,是一直以来我对博客的核心需求,NexT 主题侧重简洁,<a href="https://butterfly.js.org/">Butterfly 主题</a>则侧重不简单,Butterfly 主题的博客我决定作为自己的主页。</p><span id="more"></span><div class="note success flat"><p>本文对于文件(代码)变动的描述方式为第一行说明本行为相关文件的哪一行(如果没有这行描述,则本行即为第一行),<code>-</code>指删掉改行,<code>+</code>指增加改行(如果你是直接复制此行,请注意删掉<code>+</code>和上下文对齐)。另外,本文对于文件(代码)变动的描述只针对当时的文件(代码)版本,请根据实际情况决定对自己的相应文件(代码)进行变动。</p></div><h2 id="搭建">搭建<a class="headerlink" href="#搭建"></a></h2><div class="note success flat"><p>本部分参照<a href="https://blog.imql.life/2020/01/24/My_HexoBlog_with_NexT(1)/">我的博客的诞生(一)</a>进行。</p></div><p>登录 <a href="https://github.com/">GitHub</a>,新建一个公开仓库,仓库名设定为我的主页域名,即 www.imql.life。</p><p>登录 <a href="https://gitee.com/">Gitee</a>,新建一个公开仓库,仓库名也是设定为我的主页域名,即 www.imql.life。</p><p>再新建文件夹 www,作为<博客构建目录>,进入<博客构建目录>,进入终端,执行<code>hexo init</code>进行初始化。</p><p>安装 Git 插件:</p><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">npm install --save hexo-deployer-git</span><br></pre></td></tr></table></figure><p>编辑 Hexo 的配置文件:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.yml的第102行(随着Hexo的不断更新,本行对应在你的_config.yml中不一定是第102行,请以实际情况为准)</span><br><span class="line"># Deployment</span><br><span class="line">## Docs: https://hexo.io/docs/one-command-deployment</span><br><span class="line">deploy:</span><br><span class="line"><span class="deletion">- type: ''</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.yml的第102行(随着Hexo的不断更新,本行对应在你的_config.yml中不一定是第102行,请以实际情况为准)</span><br><span class="line"># Deployment</span><br><span class="line">## Docs: https://hexo.io/docs/one-command-deployment</span><br><span class="line">deploy:</span><br><span class="line"><span class="addition">+ type: git</span></span><br><span class="line"><span class="addition">+ repo:</span></span><br><span class="line"><span class="addition">+ github: [email protected]:ql-isaac/www.imql.life.git,master</span></span><br><span class="line"><span class="addition">+ gitee: [email protected]:ql-isaac/www.imql.life.git,master</span></span><br></pre></td></tr></table></figure><p>在终端输入 <code>hexo g -d</code>,回车,进行博客的最终操作——生成静态文件后立即部署到仓库中。</p><p>之后就是部署至 Vercel 和 Webify,实现境内境外双线部署。</p><h2 id="Hexo_的个性化设置和配置">Hexo 的个性化设置和配置<a class="headerlink" href="#Hexo_的个性化设置和配置"></a></h2><div class="note success flat"><p>本部分参考<a href="https://blog.imql.life/2020/01/24/My_HexoBlog_with_NexT(2)/#Hexo-%E7%9A%84%E4%B8%AA%E6%80%A7%E5%8C%96%E8%AE%BE%E7%BD%AE%E5%92%8C%E9%85%8D%E7%BD%AE">我的博客的诞生(二)的相应部分</a>进行。</p></div><h3 id="Butterfly_主题的下载和设置">Butterfly 主题的下载和设置<a class="headerlink" href="#Butterfly_主题的下载和设置"></a></h3><p>在<博客构建目录>下进入终端,输入如下命令,等待 Butterfly 下载到当前文件夹下 themes 下 butterfly 下。</p><figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone <span class="literal">-b</span> master https://github.com/jerryc127/hexo<span class="literal">-theme-butterfly</span>.git themes/butterfly</span><br></pre></td></tr></table></figure><p>下载完成后,编辑 Hexo 的配置文件:</p><figure class="highlight powershell"><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 class="comment"># 本行为<博客构建目录>\_config.yml的第97行(随着Hexo的不断更新,本行对应在你的_config.yml中不一定是第97行,请以实际情况为准)</span></span><br><span class="line"><span class="comment"># Extensions</span></span><br><span class="line"><span class="comment">## Plugins: https://hexo.io/plugins/</span></span><br><span class="line"><span class="comment">## Themes: https://hexo.io/themes/</span></span><br><span class="line"><span class="literal">-theme</span>: landscape</span><br></pre></td></tr></table></figure><figure class="highlight powershell"><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 class="comment"># 本行为<博客构建目录>\_config.yml的第97行(随着Hexo的不断更新,本行对应在你的_config.yml中不一定是第97行,请以实际情况为准)</span></span><br><span class="line"><span class="comment"># Extensions</span></span><br><span class="line"><span class="comment">## Plugins: https://hexo.io/plugins/</span></span><br><span class="line"><span class="comment">## Themes: https://hexo.io/themes/</span></span><br><span class="line">+theme: butterfly</span><br></pre></td></tr></table></figure><h3 id="配置博客基本信息">配置博客基本信息<a class="headerlink" href="#配置博客基本信息"></a></h3><p>编辑 Hexo 的配置文件,个性化配置自己的站点信息:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.yml的第4行(随着Hexo的不断更新,本行对应在你的_config.yml中不一定是第4行,请以实际情况为准)</span><br><span class="line"># Site</span><br><span class="line"><span class="deletion">-title: Hexo</span></span><br><span class="line"><span class="deletion">-subtitle: ''</span></span><br><span class="line"><span class="deletion">-description: ''</span></span><br><span class="line"><span class="deletion">-keywords:</span></span><br><span class="line"><span class="deletion">-author: John Doe</span></span><br><span class="line"><span class="deletion">-language: en</span></span><br><span class="line">timezone: ''</span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.yml的第4行(随着Hexo的不断更新,本行对应在你的_config.yml中不一定是第4行,请以实际情况为准)</span><br><span class="line"># Site</span><br><span class="line"><span class="addition">+title: IMQL.LIFE</span></span><br><span class="line"><span class="addition">+subtitle: It's a beautiful day!</span></span><br><span class="line"><span class="addition">+description: 一尘不染不是不再有尘埃,而是尘埃让它飞扬,我自做我的阳光。</span></span><br><span class="line"><span class="addition">+keywords: 学习与生活</span></span><br><span class="line"><span class="addition">+author: ql</span></span><br><span class="line"><span class="addition">+language: zh-CN</span></span><br><span class="line">timezone:</span><br></pre></td></tr></table></figure><h3 id="配置永久链接">配置永久链接<a class="headerlink" href="#配置永久链接"></a></h3><p>配置永久链接为年月日加文章标题的英文翻译:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line"># 本行为<博客构建目录>\_config.yml的第13行(随着Hexo的不断更新,本行对应在你的_config.yml中不一定是第13行,请以实际情况为准)</span><br><span class="line"># URL</span><br><span class="line">## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'</span><br><span class="line"><span class="deletion">-url: http://yoursite.com</span></span><br><span class="line">root: /</span><br><span class="line"><span class="deletion">-permalink: :year/:month/:day/:title/</span></span><br><span class="line">permalink_defaults:</span><br><span class="line">pretty_urls:</span><br><span class="line"> trailing_index: true # Set to false to remove trailing 'index.html' from permalinks</span><br><span class="line"> trailing_html: true # Set to false to remove trailing '.html' from permalinks</span><br></pre></td></tr></table></figure><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line"># 本行为<博客构建目录>\_config.yml的第13行(随着Hexo的不断更新,本行对应在你的_config.yml中不一定是第13行,请以实际情况为准)</span><br><span class="line"># URL</span><br><span class="line">## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'</span><br><span class="line"><span class="addition">+url: https://www.imql.life</span></span><br><span class="line">root: /</span><br><span class="line"><span class="addition">+permalink: :year/:month/:day/:trans/</span></span><br><span class="line">permalink_defaults:</span><br><span class="line">pretty_urls:</span><br><span class="line"> trailing_index: true # Set to false to remove trailing 'index.html' from permalinks</span><br><span class="line"> trailing_html: true # Set to false to remove trailing '.html' from permalinks</span><br></pre></td></tr></table></figure><h3 id="更换默认的_Markdown_渲染器">更换默认的 Markdown 渲染器<a class="headerlink" href="#更换默认的_Markdown_渲染器"></a></h3><p>同<a href="https://blog.imql.life/2020/01/24/My_HexoBlog_with_NexT(2)/#%E6%9B%B4%E6%8D%A2%E9%BB%98%E8%AE%A4%E7%9A%84-Markdown-%E6%B8%B2%E6%9F%93%E5%99%A8-1">我的博客的诞生(二)中的步骤</a>。</p><h2 id="Butterfly_的个性化设置与配置">Butterfly 的个性化设置与配置<a class="headerlink" href="#Butterfly_的个性化设置与配置"></a></h2><h3 id="安装_pug_渲染插件">安装 pug 渲染插件<a class="headerlink" href="#安装_pug_渲染插件"></a></h3><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">npm install hexo-renderer-pug</span><br></pre></td></tr></table></figure><h3 id="创建新主题配置文件">创建新主题配置文件<a class="headerlink" href="#创建新主题配置文件"></a></h3><p>为便于对主题配置文件的管理,自 Hexo v5.0.0 开始,可以在<博客构建目录>下新建一个文件 _config.<theme>.yml,此处即为 _config.butterfly.yml,然后把旧主题配置文件 _config.yml 的內容复制到 _config.butterfly.yml 去。</p><h3 id="开启菜单">开启菜单<a class="headerlink" href="#开启菜单"></a></h3><p>编辑 Butterfly 的配置文件:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第8行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第8行,请以实际情况为准)</span><br><span class="line">menu:</span><br><span class="line"><span class="deletion">- # Home: / || fas fa-home</span></span><br><span class="line"><span class="deletion">- # Archives: /archives/ || fas fa-archive</span></span><br><span class="line"><span class="deletion">- # Tags: /tags/ || fas fa-tags</span></span><br><span class="line"><span class="deletion">- # Categories: /categories/ || fas fa-folder-open</span></span><br><span class="line"><span class="deletion">- # List||fas fa-list:</span></span><br><span class="line"><span class="deletion">- # Music: /music/ || fas fa-music</span></span><br><span class="line"><span class="deletion">- # Movie: /movies/ || fas fa-video</span></span><br><span class="line"><span class="deletion">- # Link: /link/ || fas fa-link</span></span><br><span class="line"><span class="deletion">- # About: /about/ || fas fa-heart</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第8行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第8行,请以实际情况为准)</span><br><span class="line">menu:</span><br><span class="line"><span class="addition">+ 首页: / || fas fa-home</span></span><br><span class="line"><span class="addition">+ 标签: /tags/ || fas fa-tags</span></span><br><span class="line"><span class="addition">+ 分类: /categories/ || fas fa-folder-open</span></span><br><span class="line"><span class="addition">+ 归档: /archives/ || fas fa-archive</span></span><br><span class="line"><span class="addition">+ 阅读: /books/ || fas fa-book</span></span><br><span class="line"><span class="addition">+ 电影: /movies/ || fas fa-video</span></span><br><span class="line"><span class="addition">+ 游戏: /games/ || fas fa-gamepad</span></span><br><span class="line"><span class="addition">+ 友链: /link/ || fas fa-link</span></span><br><span class="line"><span class="addition">+ #关于: /about/ || fas fa-heart</span></span><br></pre></td></tr></table></figure><h4 id="添加标签和分类页面">添加标签和分类页面<a class="headerlink" href="#添加标签和分类页面"></a></h4><p>在<博客构建目录>下进入终端,执行如下命令。</p><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 new page tags</span><br></pre></td></tr></table></figure><p>编辑生成的 <a href="http://index.md">index.md</a>:</p><figure class="highlight diff"><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"><span class="comment">---</span></span><br><span class="line"><span class="deletion">-title: tags</span></span><br><span class="line">date: 2020-09-19 17:09:59</span><br><span class="line"><span class="comment">---</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"><span class="comment">---</span></span><br><span class="line"><span class="addition">+title: 标签</span></span><br><span class="line">date: 2020-09-19 17:09:59</span><br><span class="line"><span class="addition">+type: tags</span></span><br><span class="line"><span class="addition">+top_img: <自己图床的地址></span></span><br><span class="line"><span class="comment">---</span></span><br></pre></td></tr></table></figure><p>以上 top_img 指定的为标签页大图:</p><p><img src="https://img.imql.life/illustrations/8cfc21eec6f76a7c8582db082540b7ac.png" alt="标签页大图.png"></p><p>在<博客构建目录>下进入终端,执行如下命令。</p><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 new page categories</span><br></pre></td></tr></table></figure><p>编辑生成的 <a href="http://index.md">index.md</a>:</p><figure class="highlight diff"><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"><span class="comment">---</span></span><br><span class="line"><span class="deletion">-title: categories</span></span><br><span class="line">date: 2020-09-19 17:13:54</span><br><span class="line"><span class="comment">---</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"><span class="comment">---</span></span><br><span class="line"><span class="addition">+title: 分类</span></span><br><span class="line">date: 2020-09-19 17:13:54</span><br><span class="line"><span class="addition">+type: categories</span></span><br><span class="line"><span class="addition">+top_img: <自己图床的地址></span></span><br><span class="line"><span class="comment">---</span></span><br></pre></td></tr></table></figure><p>以上 top_img 指定的为分类页大图:</p><p><img src="https://img.imql.life/illustrations/b400416f5f46e026a538d15a88055c28.png" alt="分类页大图·.png"></p><p>编辑文章模板文件(为<博客构建目录>下 scaffolds 下 <a href="http://post.md">post.md</a>):</p><figure class="highlight diff"><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"><span class="comment">---</span></span><br><span class="line">title: {{ title }}</span><br><span class="line">date: {{ date }}</span><br><span class="line">tags:</span><br><span class="line"><span class="addition">+categories:</span></span><br><span class="line"><span class="comment">---</span></span><br></pre></td></tr></table></figure><h4 id="加入豆瓣页面">加入豆瓣页面<a class="headerlink" href="#加入豆瓣页面"></a></h4><p>在<博客构建目录>下进入终端,输入如下命令安装插件 hexo-butterfly-douban。</p><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">npm install --save hexo-douban</span><br></pre></td></tr></table></figure><p>编辑 Hexo 的配置文件:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line"># 本行为<博客构建目录>\_config.yml的第110行(随着Hexo的不断更新,本行对应在你的_config.yml中不一定是第110行,请以实际情况为准</span><br><span class="line"><span class="addition">+douban:</span></span><br><span class="line"><span class="addition">+ id: <豆瓣ID></span></span><br><span class="line"><span class="addition">+ builtin: true</span></span><br><span class="line"><span class="addition">+ book:</span></span><br><span class="line"><span class="addition">+ title: <书籍页面的标题></span></span><br><span class="line"><span class="addition">+ quote: <开头的引言></span></span><br><span class="line"><span class="addition">+ meta: true</span></span><br><span class="line"><span class="addition">+ comments: true</span></span><br><span class="line"><span class="addition">+ top_img: <自己图床的地址></span></span><br><span class="line"><span class="addition">+ aside: true</span></span><br><span class="line"><span class="addition">+ movie:</span></span><br><span class="line"><span class="addition">+ title: <电影页面的标题></span></span><br><span class="line"><span class="addition">+ quote: <开头的引言></span></span><br><span class="line"><span class="addition">+ meta: true</span></span><br><span class="line"><span class="addition">+ comments: true</span></span><br><span class="line"><span class="addition">+ top_img: <自己图床的地址></span></span><br><span class="line"><span class="addition">+ aside: true</span></span><br><span class="line"><span class="addition">+ game:</span></span><br><span class="line"><span class="addition">+ title: <游戏页面的标题></span></span><br><span class="line"><span class="addition">+ quote: <开头的引言></span></span><br><span class="line"><span class="addition">+ meta: true</span></span><br><span class="line"><span class="addition">+ comments: true</span></span><br><span class="line"><span class="addition">+ top_img: <自己图床的地址></span></span><br><span class="line"><span class="addition">+ aside: true</span></span><br><span class="line"><span class="addition">+ timeout: 10000</span></span><br></pre></td></tr></table></figure><p>以上 book 下的 top_img 指定的为书籍页大图:</p><p><img src="https://img.imql.life/illustrations/8589ba146ea06bc3c2505203ab938dfc.png" alt="书籍页大图.png"></p><p>以上 movie 下的 top_img 指定的为电影页大图:</p><p><img src="https://img.imql.life/illustrations/852b0ebd1ba57be61ab0953eef56e0e8.png" alt="电影页大图.png"></p><p>以上 game 下的 top_img 指定的为游戏页大图:</p><p><img src="https://img.imql.life/illustrations/e95d255dc90008cca56d87dedcc6650d.png" alt="游戏页大图.png"></p><h4 id="添加友链页面">添加友链页面<a class="headerlink" href="#添加友链页面"></a></h4><p>在<博客构建目录>下进入终端,执行如下命令。</p><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 new page <span class="built_in">link</span></span><br></pre></td></tr></table></figure><p>编辑生成的 <a href="http://index.md">index.md</a>:</p><figure class="highlight diff"><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"><span class="comment">---</span></span><br><span class="line"><span class="deletion">-title: links</span></span><br><span class="line">date: 2020-09-19 17:16:16</span><br><span class="line"><span class="comment">---</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"><span class="comment">---</span></span><br><span class="line"><span class="addition">+title: 友情链接</span></span><br><span class="line">date: 2020-09-19 17:16:16</span><br><span class="line"><span class="addition">+type: link</span></span><br><span class="line"><span class="addition">+top_img: <自己图床的地址></span></span><br><span class="line"><span class="comment">---</span></span><br></pre></td></tr></table></figure><p>以上 top_img 指定的为友链页大图:</p><p><img src="https://img.imql.life/illustrations/64a77dec96d7f57a7951687100086580.png" alt="友链页大图.png"></p><h3 id="代码块设置">代码块设置<a class="headerlink" href="#代码块设置"></a></h3><p>编辑 Butterfly 的配置文件:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第25行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第25行,请以实际情况为准)</span><br><span class="line"><span class="deletion">-highlight_theme: light # darker / pale night / light / ocean / mac / mac light / false</span></span><br><span class="line">highlight_copy: true # copy button</span><br><span class="line">highlight_lang: true # show the code language</span><br><span class="line">highlight_shrink: false # true: shrink the code blocks / false: expand the code blocks | none: expand code blocks and hide the button</span><br><span class="line">highlight_height_limit: false # unit: px</span><br><span class="line">code_word_wrap: false</span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第25行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第25行,请以实际情况为准)</span><br><span class="line"><span class="addition">+highlight_theme: mac light # darker / pale night / light / ocean / mac / mac light / false</span></span><br><span class="line">highlight_copy: true # copy button</span><br><span class="line">highlight_lang: true # show the code language</span><br><span class="line">highlight_shrink: false # true: shrink the code blocks / false: expand the code blocks | none: expand code blocks and hide the button</span><br><span class="line">highlight_height_limit: false # unit: px</span><br><span class="line">code_word_wrap: false</span><br></pre></td></tr></table></figure><div class="note info flat"><p>以上设置为个人偏好,请查看<a href="https://butterfly.js.org/posts/4aa8abbe/#%E4%BB%A3%E7%A2%BC">主题文档相应说明</a>确定自己的偏好。</p></div><h3 id="添加社交链接">添加社交链接<a class="headerlink" href="#添加社交链接"></a></h3><p>编辑 Butterfly 的配置文件,个性化添加自己的社交链接:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第40行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第40行,请以实际情况为准)</span><br><span class="line"># social settings (社交圖標設置)</span><br><span class="line"># formal:</span><br><span class="line"># icon: link || the description</span><br><span class="line">social:</span><br><span class="line"><span class="deletion">- # fab fa-github: https://github.com/xxxxx || Github</span></span><br><span class="line"><span class="deletion">- # fas fa-envelope: mailto:[email protected] || Email</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第40行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第40行,请以实际情况为准)</span><br><span class="line"># social settings (社交圖標設置)</span><br><span class="line"># formal:</span><br><span class="line"># icon: link || the description</span><br><span class="line">social:</span><br><span class="line"><span class="addition">+ fab fa-github: https://github.com/ql-isaac || Github</span></span><br><span class="line"><span class="addition">+ fas fa-envelope: mailto:[email protected] || Email</span></span><br></pre></td></tr></table></figure><h3 id="添加搜索功能">添加搜索功能<a class="headerlink" href="#添加搜索功能"></a></h3><p>在<博客构建目录>下进入终端,输入如下命令安装 hexo-generator-search。</p><figure class="highlight diff"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install --save hexo-generator-search</span><br></pre></td></tr></table></figure><p>开启搜索功能:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第56行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第56行,请以实际情况为准)</span><br><span class="line"># Local search</span><br><span class="line">local_search:</span><br><span class="line"><span class="deletion">- enable: false</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第56行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第56行,请以实际情况为准)</span><br><span class="line"># Local search</span><br><span class="line">local_search:</span><br><span class="line"><span class="addition">+ enable: true</span></span><br></pre></td></tr></table></figure><h3 id="配置站点图标">配置站点图标<a class="headerlink" href="#配置站点图标"></a></h3><p>编辑 Butterfly 的配置文件:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第81行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第81行,请以实际情况为准)</span><br><span class="line"># Favicon(網站圖標)</span><br><span class="line"><span class="deletion">-favicon: /img/favicon.png</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第81行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第81行,请以实际情况为准)</span><br><span class="line"># Favicon(網站圖標)</span><br><span class="line"><span class="addition">+favicon: <自己图床的地址或者本地地址></span></span><br></pre></td></tr></table></figure><p>效果图:</p><p><img src="https://img.imql.life/illustrations/5d5bfc40223d95d43dcb60e34a1f7baa.png" alt="配置站点图标.png"></p><h3 id="头像">头像<a class="headerlink" href="#头像"></a></h3><p>编辑 Butterfly 的配置文件:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第84行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第84行,请以实际情况为准)</span><br><span class="line"># Avatar (頭像)</span><br><span class="line">avatar:</span><br><span class="line"><span class="deletion">- img: https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png</span></span><br><span class="line"> effect: false</span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第84行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第84行,请以实际情况为准)</span><br><span class="line"># Avatar (頭像)</span><br><span class="line">avatar:</span><br><span class="line"><span class="addition">+ img: <自己图床的地址或者本地地址></span></span><br><span class="line"> effect: false</span><br></pre></td></tr></table></figure><h3 id="首页大图">首页大图<a class="headerlink" href="#首页大图"></a></h3><p>编辑 Butterfly 的配置文件:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第92行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第92行,请以实际情况为准)</span><br><span class="line"># The banner image of home page</span><br><span class="line"><span class="deletion">-index_img:</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第92行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第92行,请以实际情况为准)</span><br><span class="line"># The banner image of home page</span><br><span class="line"><span class="addition">+index_img: <自己图床的地址或者本地地址></span></span><br></pre></td></tr></table></figure><p>效果图:</p><p><img src="https://img.imql.life/illustrations/73f6966c1b87d4895427cceb0bde2dc6.png" alt="首页大图.png"></p><h3 id="归档页大图">归档页大图<a class="headerlink" href="#归档页大图"></a></h3><p>编辑 Butterfly 的配置文件:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第98行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第98行,请以实际情况为准)</span><br><span class="line"># The banner image of archive page</span><br><span class="line"><span class="deletion">-archive_img:</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第98行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第98行,请以实际情况为准)</span><br><span class="line"># The banner image of archive page</span><br><span class="line"><span class="addition">+archive_img: <自己图床的地址或者本地地址></span></span><br></pre></td></tr></table></figure><p>效果图:</p><p><img src="https://img.imql.life/illustrations/c43550a57fd45d6a77b2c5a783f0bef0.png" alt="归档页大图.png"></p><h3 id="子标签页大图">子标签页大图<a class="headerlink" href="#子标签页大图"></a></h3><p>编辑 Butterfly 的配置文件:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第101行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第101行,请以实际情况为准)</span><br><span class="line"># If the banner of tag page not setting, it will show the top_img</span><br><span class="line"># note: tag page, not tags page (子標籤頁面的 top_img)</span><br><span class="line"><span class="deletion">-tag_img:</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第101行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第101行,请以实际情况为准)</span><br><span class="line"># If the banner of tag page not setting, it will show the top_img</span><br><span class="line"># note: tag page, not tags page (子標籤頁面的 top_img)</span><br><span class="line"><span class="addition">+tag_img: <自己图床的地址或者本地地址></span></span><br></pre></td></tr></table></figure><p>效果图:</p><p><img src="https://img.imql.life/illustrations/4aa33945e9f402d954d91b1d5867dc06.png" alt="子标签页大图.png"></p><div class="note warning flat"><p>注意和标签页大图的区分。</p></div><h3 id="子分类页大图">子分类页大图<a class="headerlink" href="#子分类页大图"></a></h3><p>编辑 Butterfly 的配置文件:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第110行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第110行,请以实际情况为准)</span><br><span class="line"># If the banner of category page not setting, it will show the top_img</span><br><span class="line"># note: category page, not categories page (子分類頁面的 top_img)</span><br><span class="line"><span class="deletion">-category_img:</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第110行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第110行,请以实际情况为准)</span><br><span class="line"># If the banner of category page not setting, it will show the top_img</span><br><span class="line"># note: category page, not categories page (子分類頁面的 top_img)</span><br><span class="line"><span class="addition">+category_img: <自己图床的地址或者本地地址></span></span><br></pre></td></tr></table></figure><p>效果图:</p><p><img src="https://img.imql.life/illustrations/e1ff9df28df8b6c12e2c652266f45241.png" alt="子分类页大图.png"></p><div class="note warning flat"><p>注意和分类页大图的区分。</p></div><h3 id="启用_404_页面">启用 404 页面<a class="headerlink" href="#启用_404_页面"></a></h3><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第136行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第136行,请以实际情况为准)</span><br><span class="line"># A simple 404 page</span><br><span class="line">error_404:</span><br><span class="line"><span class="deletion">- enable: false</span></span><br><span class="line"> subtitle: 'Page Not Found'</span><br><span class="line"> background: https://i.loli.net/2020/05/19/aKOcLiyPl2JQdFD.png</span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第136行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第136行,请以实际情况为准)</span><br><span class="line"># A simple 404 page</span><br><span class="line">error_404:</span><br><span class="line"><span class="addition">+ enable: true</span></span><br><span class="line"> subtitle: 'Page Not Found'</span><br><span class="line"> background: https://i.loli.net/2020/05/19/aKOcLiyPl2JQdFD.png</span><br></pre></td></tr></table></figure><div class="note info flat"><p>本地预览时,访问出错的网站是不会跳到 404 页面的。如需本地预览,<a href="http://localhost:4000/404.html">请直接访问</a>。</p></div><h3 id="文章信息显示">文章信息显示<a class="headerlink" href="#文章信息显示"></a></h3><p>编辑 Butterfly 的配置文件:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line"># 本行为<博客构建目录>\_config.butterfly.yml的第142行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第142行,请以实际情况为准)</span><br><span class="line">post_meta:</span><br><span class="line"> page: # Home Page</span><br><span class="line"> date_type: created # created or updated or both 主頁文章日期是創建日或者更新日或都顯示</span><br><span class="line"> date_format: date # date/relative 顯示日期還是相對日期</span><br><span class="line"> categories: true # true or false 主頁是否顯示分類</span><br><span class="line"><span class="deletion">- tags: false # true or false 主頁是否顯示標籤</span></span><br><span class="line"> label: true # true or false 顯示描述性文字</span><br><span class="line"> post:</span><br><span class="line"> date_type: both # created or updated or both 文章頁日期是創建日或者更新日或都顯示</span><br><span class="line"> date_format: date # date/relative 顯示日期還是相對日期</span><br><span class="line"> categories: true # true or false 文章頁是否顯示分類</span><br><span class="line"> tags: true # true or false 文章頁是否顯示標籤</span><br><span class="line"> label: true # true or false 顯示描述性文字</span><br></pre></td></tr></table></figure><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line"># 本行为<博客构建目录>\_config.butterfly.yml的第142行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第142行,请以实际情况为准)</span><br><span class="line">post_meta:</span><br><span class="line"> page: # Home Page</span><br><span class="line"> date_type: created # created or updated or both 主頁文章日期是創建日或者更新日或都顯示</span><br><span class="line"> date_format: date # date/relative 顯示日期還是相對日期</span><br><span class="line"> categories: true # true or false 主頁是否顯示分類</span><br><span class="line"><span class="addition">+ tags: true # true or false 主頁是否顯示標籤</span></span><br><span class="line"> label: true # true or false 顯示描述性文字</span><br><span class="line"> post:</span><br><span class="line"> date_type: both # created or updated or both 文章頁日期是創建日或者更新日或都顯示</span><br><span class="line"> date_format: date # date/relative 顯示日期還是相對日期</span><br><span class="line"> categories: true # true or false 文章頁是否顯示分類</span><br><span class="line"> tags: true # true or false 文章頁是否顯示標籤</span><br><span class="line"> label: true # true or false 顯示描述性文字</span><br></pre></td></tr></table></figure><div class="note info flat"><p>以上设置为个人偏好,请查看<a href="https://butterfly.js.org/posts/4aa8abbe/#%E6%96%87%E7%AB%A0meta%E9%A1%AF%E7%A4%BA">主题文档相应说明</a>确定自己的偏好。</p></div><h3 id="开启字数统计和阅读时间">开启字数统计和阅读时间<a class="headerlink" href="#开启字数统计和阅读时间"></a></h3><p>在<博客构建目录>下进入终端,输入如下命令安装插件 hexo-wordcount。</p><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">npm install --save hexo-wordcount</span><br></pre></td></tr></table></figure><p>编辑 Butterfly 的配置文件:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第156行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第156行,请以实际情况为准)</span><br><span class="line"># wordcount (字數統計)</span><br><span class="line">wordcount:</span><br><span class="line"><span class="deletion">- enable: false</span></span><br><span class="line"> post_wordcount: true</span><br><span class="line"> min2read: true</span><br><span class="line"> total_wordcount: true</span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第156行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第156行,请以实际情况为准)</span><br><span class="line"># wordcount (字數統計)</span><br><span class="line">wordcount:</span><br><span class="line"><span class="addition">+ enable: true</span></span><br><span class="line"> post_wordcount: true</span><br><span class="line"> min2read: true</span><br><span class="line"> total_wordcount: true</span><br></pre></td></tr></table></figure><h3 id="关闭主页文章节选">关闭主页文章节选<a class="headerlink" href="#关闭主页文章节选"></a></h3><p>编辑 Butterfly 的配置文件:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第163行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第163行,请以实际情况为准)</span><br><span class="line"># Display the article introduction on homepage</span><br><span class="line"># 1: description</span><br><span class="line"># 2: both (if the description exists, it will show description, or show the auto_excerpt)</span><br><span class="line"># 3: auto_excerpt (default)</span><br><span class="line"># false: do not show the article introduction</span><br><span class="line"><span class="comment">index_post_content:</span></span><br><span class="line"><span class="deletion">- method: 3</span></span><br><span class="line"> length: 500 # if you set method to 2 or 3, the length need to config</span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第163行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第163行,请以实际情况为准)</span><br><span class="line"># Display the article introduction on homepage</span><br><span class="line"># 1: description</span><br><span class="line"># 2: both (if the description exists, it will show description, or show the auto_excerpt)</span><br><span class="line"># 3: auto_excerpt (default)</span><br><span class="line"># false: do not show the article introduction</span><br><span class="line"><span class="comment">index_post_content:</span></span><br><span class="line"><span class="addition">+ method: false</span></span><br><span class="line"> length: 500 # if you set method to 2 or 3, the length need to config</span><br></pre></td></tr></table></figure><h3 id="文章打賞">文章打賞<a class="headerlink" href="#文章打賞"></a></h3><p>在你每篇文章的結尾,添加打賞按鈕和相应收款二维码。编辑 Butterfly 的配置文件:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第187行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第187行,请以实际情况为准)</span><br><span class="line"># Sponsor/reward</span><br><span class="line">reward:</span><br><span class="line"><span class="deletion">- enable: false</span></span><br><span class="line"> QR_code:</span><br><span class="line"><span class="deletion">- # - img: /img/wechat.jpg</span></span><br><span class="line"><span class="deletion">- # link:</span></span><br><span class="line"><span class="deletion">- # text: wechat</span></span><br><span class="line"><span class="deletion">- # - img: /img/alipay.jpg</span></span><br><span class="line"><span class="deletion">- # link:</span></span><br><span class="line"><span class="deletion">- # text: alipay</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第187行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第187行,请以实际情况为准)</span><br><span class="line"># Sponsor/reward</span><br><span class="line">reward:</span><br><span class="line"><span class="addition">+ enable: true</span></span><br><span class="line"> QR_code:</span><br><span class="line"><span class="addition">+ - img: <自己微信赞赏码的地址></span></span><br><span class="line"><span class="addition">+ link:</span></span><br><span class="line"><span class="addition">+ text: WeChat</span></span><br><span class="line"><span class="addition">+ - img: <自己支付宝收钱码的地址></span></span><br><span class="line"><span class="addition">+ link:</span></span><br><span class="line"><span class="addition">+ text: Alipay</span></span><br></pre></td></tr></table></figure><h3 id="集成在线编辑">集成在线编辑<a class="headerlink" href="#集成在线编辑"></a></h3><p>编辑 Butterfly 的配置文件:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第198行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第198行,请以实际情况为准)</span><br><span class="line"># Post edit</span><br><span class="line"># Easily browse and edit blog source code online.</span><br><span class="line">post_edit:</span><br><span class="line"><span class="deletion">- enable: false</span></span><br><span class="line"> # url: https://github.com/user-name/repo-name/edit/branch-name/subdirectory-name/</span><br><span class="line"> # For example: https://github.com/jerryc127/butterfly.js.org/edit/main/source/</span><br><span class="line"><span class="deletion">- url:</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第198行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第198行,请以实际情况为准)</span><br><span class="line"># Post edit</span><br><span class="line"># Easily browse and edit blog source code online.</span><br><span class="line">post_edit:</span><br><span class="line"><span class="addition">+ enable: true</span></span><br><span class="line"> # url: https://github.com/user-name/repo-name/edit/branch-name/subdirectory-name/</span><br><span class="line"> # For example: https://github.com/jerryc127/butterfly.js.org/edit/main/source/</span><br><span class="line"><span class="addition">+ url: https://github.dev/ql-isaac/www#</span></span><br></pre></td></tr></table></figure><h3 id="开启图片描述">开启图片描述<a class="headerlink" href="#开启图片描述"></a></h3><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第212行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第212行,请以实际情况为准)</span><br><span class="line"># figcaption (圖片描述文字)</span><br><span class="line"><span class="deletion">-photofigcaption: false</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第212行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第212行,请以实际情况为准)</span><br><span class="line"># figcaption (圖片描述文字)</span><br><span class="line"><span class="addition">+photofigcaption: true</span></span><br></pre></td></tr></table></figure><h3 id="上一篇下一篇">上一篇下一篇<a class="headerlink" href="#上一篇下一篇"></a></h3><p>每篇文章结束,都有上一篇下一篇的提示,默认下一篇是旧文章,上一篇是新文章,我们设置成下一篇是新文章,上一篇是旧文章。编辑 Butterfly 的配置文件:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第215行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第215行,请以实际情况为准)</span><br><span class="line"># post_pagination (分頁)</span><br><span class="line"># value: 1 || 2 || false</span><br><span class="line"># 1: The 'next post' will link to old post</span><br><span class="line"># 2: The 'next post' will link to new post</span><br><span class="line"># false: disable pagination</span><br><span class="line"><span class="deletion">-post_pagination: 1</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第215行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第215行,请以实际情况为准)</span><br><span class="line"># post_pagination (分頁)</span><br><span class="line"># value: 1 || 2 || false</span><br><span class="line"># 1: The 'next post' will link to old post</span><br><span class="line"># 2: The 'next post' will link to new post</span><br><span class="line"># false: disable pagination</span><br><span class="line"><span class="addition">+post_pagination: 2</span></span><br></pre></td></tr></table></figure><h3 id="开启文章锚点">开启文章锚点<a class="headerlink" href="#开启文章锚点"></a></h3><p>当浏览文章时,文章链接会根据标题进行更新,方便我们对文章内容进行准确的引用。编辑 Butterfly 的配置文件:</p><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第222行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第222行,请以实际情况为准)</span><br><span class="line"># anchor</span><br><span class="line"># when you scroll in post, the URL will update according to header id.</span><br><span class="line"><span class="deletion">-anchor: false</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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"># 本行为<博客构建目录>\_config.butterfly.yml的第222行(随着Butterfly的不断更新,本行对应在你的_config.butterfly.yml中不一定是第222行,请以实际情况为准)</span><br><span class="line"># anchor</span><br><span class="line"># when you scroll in post, the URL will update according to header id.</span><br><span class="line"><span class="addition">+anchor: true</span></span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 我的博客 </category>
</categories>
<tags>
<tag> Hexo </tag>
<tag> Butterfly </tag>
</tags>
</entry>
<entry>
<title>Oracle 数据库从入门到精通(一)</title>
<link href="/2020/02/29/Oracle_Database_Learning_1/"/>
<url>/2020/02/29/Oracle_Database_Learning_1/</url>
<content type="html"><![CDATA[<p>Oracle 数据库,又名 Oracle RDBMS,或简称 Oracle。是<a href="https://baike.baidu.com/item/%E7%94%B2%E9%AA%A8%E6%96%87%E5%85%AC%E5%8F%B8/430115">甲骨文公司</a>的一款<a href="https://baike.baidu.com/item/%E5%85%B3%E7%B3%BB%E6%95%B0%E6%8D%AE%E5%BA%93%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/11032386">关系型数据库管理系统</a>。它是在数据库领域一直处于领先地位的产品。可以说 Oracle 数据库是目前世界上最流行的关系型数据库管理系统之一,系统可移植性好、使用方便、功能强,适用于各类大、中、小微机环境。它是一种高效率的、可靠性好的、适应高吞吐量的数据库方案。</p><span id="more"></span><h2 id="下载">下载<a class="headerlink" href="#下载"></a></h2><p>访问官方<a href="https://www.oracle.com/database/technologies/oracle-database-software-downloads.html">Oracle Database 11g Release 2 下载地址</a>下载即可,注意有两个压缩包,下好后分别右键解压到当前目录,这样就得到了安装文件夹 database。</p><h2 id="Windows_中的安装(试验)">Windows 中的安装(试验)<a class="headerlink" href="#Windows_中的安装(试验)"></a></h2><ol><li>打开 database 文件夹,双击 setup.exe 安装,刚开始有一个如下图的错误,解决办法是编辑 database 下的 stage 下的 cvu 下的 cvu_prereq.xml,在 <CERTIFIED_SYSTEMS></CERTIFIED_SYSTEMS> 间的最后位置添加以下代码,保存并关闭,重新安装即可。</li></ol><p><img src="https://img.imql.life/illustrations/9cbcbb0ab24cfeedc4b7d32bfc081831.png" alt="错误.png"></p><figure class="highlight xml"><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="tag"><<span class="name">OPERATING_SYSTEM</span> <span class="attr">RELEASE</span>=<span class="string">"6.2"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">VERSION</span> <span class="attr">VALUE</span>=<span class="string">"3"</span>/></span></span><br><span class="line"> <span class="tag"><<span class="name">ARCHITECTURE</span> <span class="attr">VALUE</span>=<span class="string">"64-bit"</span>/></span></span><br><span class="line"> <span class="tag"><<span class="name">NAME</span> <span class="attr">VALUE</span>=<span class="string">"Windows 10"</span>/></span></span><br><span class="line"> <span class="tag"><<span class="name">ENV_VAR_LIST</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">ENV_VAR</span> <span class="attr">NAME</span>=<span class="string">"PATH"</span> <span class="attr">MAX_LENGTH</span>=<span class="string">"1023"</span> /></span></span><br><span class="line"> <span class="tag"></<span class="name">ENV_VAR_LIST</span>></span></span><br><span class="line"><span class="tag"></<span class="name">OPERATING_SYSTEM</span>></span></span><br></pre></td></tr></table></figure><ol start="2"><li>不更新,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/d6b6503cc911bf779b12b11719b12c3c.png" alt="不更新.png"></p><ol start="3"><li>直接下一步;</li></ol><p><img src="https://img.imql.life/illustrations/f936ba2a2bc3f42c21a57ae2ac23fc48.png" alt="创建.png"></p><ol start="4"><li>选择服务器类,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/28ec4b944c432fdc60e75a76a4865d43.png" alt="服务器类.png"></p><ol start="5"><li>直接下一步;</li></ol><p><img src="https://img.imql.life/illustrations/87d9077b6eaaae1bed20505c4303b1da.png" alt="单实例.png"></p><ol start="6"><li>选择高级安装,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/7adddb02e30eec83574055d9d2f180b7.png" alt="高级安装.png"></p><ol start="7"><li>默认即可,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/23feb2079402e442f37ce4d318fe2856.png" alt="语言.png"></p><ol start="8"><li>就选择企业版,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/591002452978b5655e39c274030db687.png" alt="企业版.png"></p><ol start="9"><li>默认即可,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/c85f848a19cacab7ec849bb72985ef36.png" alt="默认即可.png"></p><ol start="10"><li>默认即可,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/847db7b0444b8f81ff9707e28b75fb44.png" alt="下一步.png"></p><ol start="11"><li>自定义 SID 的名称,不改,就默认也行;</li></ol><p><img src="https://img.imql.life/illustrations/4b1d62220097d1bb830920d7482fdb3c.png" alt="自定义SID的名称.png"></p><ol start="12"><li>使用 Unicode 字符集;</li></ol><p><img src="https://img.imql.life/illustrations/56e4a294745a787a266c6eb3ed295beb.png" alt="Unicode.png"></p><ol start="13"><li>勾选创建具有示例方案的数据库,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/4329a29ade7d592ce3f5137b55ba3fb5.png" alt="创建具有示例方案的数据库.png"></p><ol start="14"><li>默认即可,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/dbb8e5bc935e3780245f9c2878f8ece7.png" alt="过.png"></p><ol start="15"><li>默认即可,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/de14134acaa3ab65aa1cee353ae393f3.png" alt="再过.png"></p><ol start="16"><li>不启动自动备份,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/33013940fc50f3e69fb8c754253512be.png" alt="不自动备份.png"></p><ol start="17"><li>个人学习用,为了方便,选择对所有账户使用相同的口令(口令必须以字母开头),下一步;</li></ol><p><img src="https://img.imql.life/illustrations/699b540900965bb168f0b0ac50d26e1c.png" alt="设置口令.png"></p><ol start="18"><li>检查到错误,可以忽略,勾选全部忽略,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/86ad81fe84257e4d2c991fb94673af7f.png" alt="检查到错误.png"></p><ol start="19"><li>点击完成,等待;</li></ol><p><img src="https://img.imql.life/illustrations/e340fe1278d73b0d6499bd94755d29d4.png" alt="等待.png"></p><ol start="20"><li>点击口令管理;</li></ol><p><img src="https://img.imql.life/illustrations/eef8a835cd7c67259f844e24e97f5485.png" alt="口令管理.png"></p><ol start="21"><li>设置 SYS 用户密码为 change_on_install,设置 SYSTEM 用户密码为 manager,解锁 SCOTT 用户并设置密码为 tiger,解锁 SH 用户并设置密码为 sh;</li></ol><p><img src="https://img.imql.life/illustrations/a15ee76a72779bec7fbfdc002a7a2e16.png" alt="是.png"></p><ol start="22"><li>安装完成;</li></ol><p><img src="https://img.imql.life/illustrations/8e10647a76d84bb23da8848e1b4b2494.png" alt="完成.png"></p><h2 id="SQL_PLUS_的使用">SQL PLUS 的使用<a class="headerlink" href="#SQL_PLUS_的使用"></a></h2><h3 id="登录_SCOTT_用户">登录 SCOTT 用户<a class="headerlink" href="#登录_SCOTT_用户"></a></h3><p>命令行 CMD 里输入 sqlplus,输入 scott,再输入密码 tiger(不会回显),即可登录 SCOTT 用户。</p><p><img src="https://img.imql.life/illustrations/4d54a3a8888faa6127189fe4ae76b8d9.gif" alt="登录scott用户.gif"></p><h3 id="第一次查询">第一次查询<a class="headerlink" href="#第一次查询"></a></h3><p>数据库最重要的组成对象是表,登录上 SCOTT 用户后,首先通过以下命令查询一下该用户有哪些表吧。</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> TAB;</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/36d5ea105c5d84ba1c09fc4fb162902a.gif" alt="第一次查询.gif"></p><p>呃,查询结果显示得比较乱,有一个命令可以解决这个问题,如下,设置每行显示的数据长度,执行完这个命令后再查询一下 SCOTT 用户有哪些表看看。</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SET LINESIZE 100</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/8b704d98d4a5fe2aad78efc79cc3f91b.gif" alt="显示问题.gif"></p><p>呃,如果觉得 TNAME 列的数据所占的长度太长了,有一个命令可以解决这个问题,如下,设置 TNAME 列的数据所占的长度,执行完这个命令后再查询一下 SCOTT 用户有哪些表看看。</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">COL TNAME FOR A20</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/44c29b688c3275865e98d0a52d7845df.gif" alt="太长了.gif"></p><p>终于,能很舒服地查看到 SCOTT 用户下有四个表:BONUS、DEPT、EMP 和 SALGRADE。那么,再查询一下 DEPT 表吧。</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> DEPT;</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/1c7320f709ef054651820500f050fe0e.gif" alt="再查询一下DEPT表.gif"></p><h3 id="切换用户">切换用户<a class="headerlink" href="#切换用户"></a></h3><p>换个用户登录是怎样的命令?如下命令格式,其中<code>[]</code>表示可选内容,<code>|</code>表示多选一。</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">CONN[ECT] 用户名/密码 [AS SYSDBA|SYSUSER]</span><br></pre></td></tr></table></figure><p>登录 SYS 用户看看,由于 SYS 是超级管理员用户,命令如下:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">CONN SYS/change_on_install AS SYSDBA</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/e55c8364facc5b7fe8dda63121f2f9c6.png" alt="切换到sys用户.png"></p><p>登录 SYSTEM 用户看看,由于 SYSTEM 是普通管理员用户,命令如下:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">CONN SYSTEM/manager</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/ec9dee24372800541c77fbaa824c635f.png" alt="切换到system用户.png"></p><p>SYSTEM 用户和 SYS 用户都是管理员,应该是可以查询到 SCOTT 用户的 DEPT 表的,来试试。</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> DEPT;</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/78d43e0fa461a3da43e95cccdcb8afbf.png" alt="表或视图不存在.png"></p><p>来确认一下当前用户是否是管理员用户。</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SHOW USER</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/4891eca420ce091258299c8f4aa60bf9.png" alt="SHOWUSER.png"></p><p>这就奇怪了,难道不能查询到?原来,是需要在表前指定用户。</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> SCOTT.DEPT;</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/8123b6bd896f8c7d24a33dadacbb6563.png" alt="加用户名.png"></p><h2 id="SQL">SQL<a class="headerlink" href="#SQL"></a></h2><p>关系型数据库的理论诞生之后,世界上出现了许多的关系型数据库管理系统,熟悉了 A 关系型数据库管理系统后几乎还得重新学 B 关系型数据库管理系统,这很大程度上是由于每个关系型数据库管理系统都实现了自己的一套语言,语言只是一种工具,弄那么多套语言毫无意义,于是,SQL(Structured Query Language,即结构化查询语言)作为一个标准和一个功能强大的关系型数据库语言诞生了。</p><p>SQL 分为以下几类:</p><ul><li>DML(Data Manipulation Language,数据操作语言):数据查询(SELECT)、数据更新(UPDATE、INSERT 和 DELETE)和事务管理等。</li><li>DDL(Data Definition Language,数据定义语言):数据对象定义等(用户和数据表等)。</li><li>DCL(Data Control Language,数据控制语言):授权等。</li></ul><h2 id="SCOTT_的数据表分析">SCOTT 的数据表分析<a class="headerlink" href="#SCOTT_的数据表分析"></a></h2><p>在 Oracle 11g 以前 SCOTT 和其数据表等是会默认给用户提供的,如果在以上安装 Oracle 11g 的步骤 13 中未勾选创建具有示例方案的数据库,我们就需要手动执行一个脚本,该脚本在如下路径。</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">C:\app\ql\product\11.2.0\dbhome_1\RDBMS\ADMIN\scott.sql</span><br></pre></td></tr></table></figure><h3 id="部门信息表(DEPT">部门信息表(DEPT)<a class="headerlink" href="#部门信息表(DEPT"></a></h3><p>先切换回 SCOTT 用户:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">CONN SCOTT/tiger</span><br></pre></td></tr></table></figure><p>查询 DEPT</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> DEPT;</span><br></pre></td></tr></table></figure><p>查看数据表的结构的语法:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">DESC 数据表;</span><br></pre></td></tr></table></figure><p>查看 DEPT 的结构:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">DESC DEPT;</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/db27a795564e07a020bdcbb016eed049.png" alt="DEPT的结构.png"></p><p>DEPT 的结构解释:</p><table><thead><tr><th>字段</th><th>含义</th><th>类型</th><th>类型作用</th><th>说明</th></tr></thead><tbody><tr><td>DEPTNO</td><td>部门编号</td><td>NUMBER(2)</td><td>最多 2 位数字</td><td></td></tr><tr><td>DNAME</td><td>部门名称</td><td>VARCHAR2(14)</td><td>最多 14 位字符</td><td>3 位字符保存中文</td></tr><tr><td>LOC</td><td>部门位置</td><td>VARCHAR2(13)</td><td>最多 13 为字符</td><td></td></tr></tbody></table><h3 id="雇员信息表(EMP)">雇员信息表(EMP)<a class="headerlink" href="#雇员信息表(EMP)"></a></h3><p>查询 EMP:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> EMP;</span><br></pre></td></tr></table></figure><p>同样有显示问题,设置一行的长度为 150:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SET LINESIZE 150</span><br></pre></td></tr></table></figure><p>再查询 EMP:</p><p><img src="https://img.imql.life/illustrations/fe0de0c3ab6e8ec2b0b94357641e112c.png" alt="EMP.png"></p><p>查看 EMP 的结构:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DESC</span> EMP;</span><br></pre></td></tr></table></figure><p>EMP 的结构解释:</p><table><thead><tr><th>字段</th><th>含义</th><th>类型</th><th>类型作用</th><th>说明</th></tr></thead><tbody><tr><td>EMPNO</td><td>雇员编号</td><td>NUMBER(4)</td><td>最多 4 位数字</td><td></td></tr><tr><td>ENAME</td><td>雇员姓名</td><td>VARCHAR2(10)</td><td>最多 10 位字符</td><td></td></tr><tr><td>JOB</td><td>雇员职位</td><td>VARCHAR2(9)</td><td>最多 9 位字符</td><td></td></tr><tr><td>MGR</td><td>领导编号</td><td>NUMBER(4)</td><td>最多 4 位数字</td><td>领导本身也是雇员</td></tr><tr><td>HIREDATE</td><td>雇佣日期</td><td>DATE</td><td></td><td>包含日期和时间</td></tr><tr><td>SAL</td><td>基本工资</td><td>NUMBER(7,2)</td><td>小数位最多 2 位,整数位最多 5 位</td><td></td></tr><tr><td>COMM</td><td>佣金</td><td>NUMBER(7,2)</td><td>小数位最多 2 位,整数位最多 5 位</td><td>只有销售职位的雇员才会存在有佣金</td></tr><tr><td>DEPTNO</td><td>部门编号</td><td>NUMBER(2)</td><td>最多 2 位数字</td><td>雇员所在的部门编号</td></tr></tbody></table><h3 id="工资等级表(SALGRADE)">工资等级表(SALGRADE)<a class="headerlink" href="#工资等级表(SALGRADE)"></a></h3><p>查询 SALGRADE:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> SALGRADE;</span><br></pre></td></tr></table></figure><p>查看 SALGRADE 的结构:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DESC</span> SALGRADE;</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/d966bd263885c62ce5bbaf8911d60ef2.png" alt="SALGRADE.png"></p><p>SALGRADE 的结构解释:</p><table><thead><tr><th>字段</th><th>含义</th><th>类型</th><th>类型作用</th><th>说明</th></tr></thead><tbody><tr><td>GRADE</td><td>等级编号</td><td>NUMBER</td><td></td><td></td></tr><tr><td>LOSAL</td><td>此等级的最低工资</td><td>NUMBER</td><td></td><td></td></tr><tr><td>HISAL</td><td>此等级的最高工资</td><td>NUMBER</td><td></td><td></td></tr></tbody></table><h3 id="工资表(BONUS">工资表(BONUS)<a class="headerlink" href="#工资表(BONUS"></a></h3><p>BONUS 表没有数据,只有表结构。</p><p><img src="https://img.imql.life/illustrations/38c59b2a4f3f4be5ae359c04163b580b.png" alt="BONUS.png"></p><p>BONUS 的结构解释:</p><table><thead><tr><th>字段</th><th>含义</th><th>类型</th><th>类型作用</th><th>说明</th></tr></thead><tbody><tr><td>ENAME</td><td>雇员姓名</td><td>VARCHAR2(10)</td><td>最多 10 位字符</td><td></td></tr><tr><td>JOB</td><td>职位</td><td>VARCHAR2(9)</td><td>最多 9 位字符</td><td></td></tr><tr><td>SAL</td><td>基本工资</td><td>NUMBER</td><td></td><td></td></tr><tr><td>COMM</td><td>佣金</td><td>NUMBER</td><td></td><td></td></tr></tbody></table><h2 id="Linux_中的安装(正式)">Linux 中的安装(正式)<a class="headerlink" href="#Linux_中的安装(正式)"></a></h2><h3 id="软硬件检查">软硬件检查<a class="headerlink" href="#软硬件检查"></a></h3><ol><li>查看操作系统版本;</li></ol><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">cat</span> /etc/openEuler-release</span><br></pre></td></tr></table></figure><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">openEuler release 22.03 LTS</span><br></pre></td></tr></table></figure><ol start="2"><li>查看内存;</li></ol><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">free -m</span><br></pre></td></tr></table></figure><figure class="highlight plaintext"><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"> total used free shared buff/cache available</span><br><span class="line">Mem: 3380 244 2641 17 494 2768</span><br><span class="line">Swap: 4023 0 4023</span><br></pre></td></tr></table></figure><ol start="3"><li>查看共享内存;</li></ol><h2 id="参考-3">参考<a class="headerlink" href="#参考-3"></a></h2><ul><li><a href="https://www.bilibili.com/video/BV1NJ411M7fE?p=80">【李兴华带你玩编程】Oracle 数据库小白教程(bilibili)</a></li></ul>]]></content>
<categories>
<category> Oracle 数据库从入门到精通 </category>
</categories>
<tags>
<tag> VMware Workstation </tag>
<tag> Windows </tag>
<tag> Oracle Database </tag>
<tag> openEuler </tag>
</tags>
</entry>
<entry>
<title>C 从入门到精通(一)</title>
<link href="/2020/02/13/C_Learning_1/"/>
<url>/2020/02/13/C_Learning_1/</url>
<content type="html"><![CDATA[<p>任何比 C 语言更低级的语言,都不足以完整地抽象一个计算机系统,任何比 C 语言高级的语言,都可以用 C 语言实现。C 语言不像是被发明的,它更像是被发现的,它无可替代、精妙绝伦。</p><span id="more"></span><h2 id="C_语言的简单历史">C 语言的简单历史<a class="headerlink" href="#C_语言的简单历史"></a></h2><p>C 语言是从 B 语言发展而来,B 语言是从 BCPL 发展而来,BCPL 是从 FORTRAN 发展而来。C 语言于 1972 年 11 月问世,1973 年 3 月,第三版的 Unix 上出现了 C 语言的编译器,1973 年 11 月,第四版的 Unix 发布了,这个版本是完全用 C 语言重新写的,1978 年美国电话电报公司(AT&T)贝尔实验室正式发布 C 语言,1983 年美国国家标准局(American National Standards Institute,简称 ANSI)开始制定 C 语言标准,于 1989 年 12 月完成,并在 1990 年春天发布,称之为 ANSI C,有时也被称为 C89 或 C90。</p><h2 id="搭建学习环境">搭建学习环境<a class="headerlink" href="#搭建学习环境"></a></h2><h3 id="安装_VMware">安装 VMware<a class="headerlink" href="#安装_VMware"></a></h3><p>下载<a href="https://www.52pojie.cn/thread-1026907-1-1.html">学习版</a>,安装步骤不多说了,只是有一点建议,也是我装软件的原则:能不装 C 盘就别装 C 盘。</p><h3 id="下载系统镜像">下载系统镜像<a class="headerlink" href="#下载系统镜像"></a></h3><h3 id="安装系统镜像">安装系统镜像<a class="headerlink" href="#安装系统镜像"></a></h3><ol><li>VMware pro 15 安装完成后,启动,点击创建新的虚拟机;</li></ol><p><img src="https://img.imql.life/illustrations/bdd3b3ca87de97f11f1fd5d84ddca47b.png" alt="创建新的虚拟机.png"></p><ol start="2"><li>选择典型,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/94fb119b01d8f151a959257206833f7b.png" alt="典型.png"></p><ol start="3"><li>选择稍后安装操作系统,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/3f34c37ba95541e9b7fbc61b9c498517.png" alt="选择稍后安装操作系统.png"></p><ol start="4"><li>客户机操作系统选择 Linux,版本选择 Ubuntu 64 位,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/849fb489920b06a4591941b6235e3483.png" alt="选择客户机操作系统.png"></p><ol start="5"><li>虚拟机名称和位置自定义,下一步;</li></ol><p><img src="https://img.imql.life/illustrations/0fa2e7f7759bc95071eab1d410f8d626.png" alt="虚拟机名称和位置.png"></p><ol start="6"><li>磁盘容量自定义。我这里就设为 60GB,下一步,完成;</li></ol><p><img src="https://img.imql.life/illustrations/504cfe03f47b8e03c108ff78627587d9.png" alt="指定磁盘容量.png"></p><ol start="7"><li>点击编辑此虚拟机,将处理器数量设为 4(一般为自己实体机处理器数量的一半);</li></ol><p><img src="https://img.imql.life/illustrations/da14c2588af074aa0552701124bd915b.png" alt="处理器数量.png"></p><ol start="8"><li>点击 CD/DVD (SATA),选择使用 ISO 映像文件,浏览,选择 Ubuntu 18.04 LTS 系统的 ISO 映像文件,确定,点击开启此虚拟机,等待;</li></ol><p><img src="https://img.imql.life/illustrations/cf6bbb74420ac2bbc3e40514a1ebb6ac.png" alt="选择系统镜像.png"></p><ol start="9"><li>选择中文(简体),再选择安装 Ubuntu;</li></ol><p><img src="https://img.imql.life/illustrations/a165f5af1f5eaef9d5a2a9bb976386ea.png" alt="中文简体.png"></p><ol start="10"><li>继续;</li></ol><p><img src="https://img.imql.life/illustrations/a4e273d69d2010fc05e43d525f4afc9d.png" alt="继续.png"></p><ol start="11"><li>勾选最后一个,继续;</li></ol><p><img src="https://img.imql.life/illustrations/eaa2333743fdd2ba187c47d6f685cddd.png" alt="勾选.png"></p><ol start="12"><li>现在安装;</li></ol><p><img src="https://img.imql.life/illustrations/5ccb43a66ebba10c2af8a727cf9f58ad.png" alt="现在安装.png"></p><ol start="13"><li>继续;</li></ol><p><img src="https://img.imql.life/illustrations/67aebadcce5e1474d9a19b187bd87be7.png" alt="再次确认.png"></p><ol start="14"><li>在地图上点击,选择 shanghai,继续;</li></ol><p><img src="https://img.imql.life/illustrations/c943c41e7d8a04f30e059b382fd02d39.png" alt="shanghai.png"></p><ol start="15"><li>自定义信息,继续;</li></ol><p><img src="https://img.imql.life/illustrations/3800fe98cc5a9babd1451e6437ee8c23.png" alt="您是谁.png"></p><ol start="16"><li>等待;</li></ol><p><img src="https://img.imql.life/illustrations/9960b82099f9edbdff941c4e0d3031cd.png" alt="等待.png"></p><ol start="17"><li>现在重启;</li></ol><p><img src="https://img.imql.life/illustrations/e814011d1506368ff67286d6aabd502d.png" alt="现在重启.png"></p><ol start="18"><li>登录刚创建的用户。</li></ol><p><img src="https://img.imql.life/illustrations/6dfad214ddc8a6f8ea2d59b202a9ff1a.png" alt="登录.png"></p><h3 id="安装_VMware_Tools">安装 VMware Tools<a class="headerlink" href="#安装_VMware_Tools"></a></h3><p>可以安装上 VMware Tools 让我们拥有最佳的 Ubuntu 18.04 LTS 操作体验,如在实体机上一般。首先点击左上方的虚拟机,再点击安装 VMware Tools,这时会在桌面出现一个 DVD,接下来具体安装过程如下:</p><p><img src="https://img.imql.life/illustrations/9bab0a925cebe68b74f7592141deed1b.gif" alt="安装VMware_Tools.gif"></p><h3 id="设置阿里镜像">设置阿里镜像<a class="headerlink" href="#设置阿里镜像"></a></h3><ol><li>打开软件更新器;</li></ol><p><img src="https://img.imql.life/illustrations/1f5fb79fecda2f7ae58fbcba4b35a15d.png" alt="软件更新器.png"></p><ol start="2"><li>一般会有更新提示,先不更新,点击设置;</li></ol><p><img src="https://img.imql.life/illustrations/be75e3651a770a44228181049e5e75c0.png" alt="设置.png"></p><ol start="3"><li>点击 Ubuntu 软件,设置下载源;</li></ol><p><img src="https://img.imql.life/illustrations/77987e2e29d39570957a96d5c557db8d.png" alt="Ubuntu软件.png"></p><ol start="4"><li>点击其他站点,选择阿里云镜像站点,需要输入用户密码认证;</li></ol><p><img src="https://img.imql.life/illustrations/dbd1d45b4b7311bbfd5f6bd0a95844a4.png" alt="aliyun.png"></p><ol start="5"><li>重新载入可用软件包列表;</li></ol><p><img src="https://img.imql.life/illustrations/843befae927eedc1369e16327d16328f.png" alt="重新载入.png"></p><ol start="6"><li>现在和以后就可以高速安装更新或软件包了,点击立即安装;</li></ol><p><img src="https://img.imql.life/illustrations/b3d475122fc1b334f612e2a300f10925.png" alt="更新.png"></p><h3 id="美化自己的_Ubuntu_18_04_LTS">美化自己的 Ubuntu 18.04 LTS<a class="headerlink" href="#美化自己的_Ubuntu_18_04_LTS"></a></h3><ol><li>右键点击桌面,在终端打开,输入以下命令回车,输入用户密码安装 gnome-tweak-tool 软件包;</li></ol><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">sudo apt install gnome-tweak-tool</span><br></pre></td></tr></table></figure><ol start="2"><li>火狐浏览器访问 <a href="https://extensions.gnome.org">GNOME Shell Extensions</a>,点击安装该浏览器扩展;</li></ol><p><img src="https://img.imql.life/illustrations/24889d2bfb778b7f0fef180cd859c63c.png" alt="安装浏览器扩展.png"></p><ol start="3"><li>刷新一下浏览器,这时会有错误信息,右键点击桌面,在终端打开,输入以下命令回车,输入用户密码安装 chrome-gnome-shell 软件包,再刷新一下浏览器,错误消失了;</li></ol><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">sudo apt install chrome-gnome-shell</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/d06813e78e2fe7de02b2719e2e43b07a.png" alt="错误.png"></p><ol start="4"><li>分别点击两个 GNOME Shell 扩展:User Themes 和 Dash to Dock,将它们都开启(即安装);</li></ol><p><img src="https://img.imql.life/illustrations/4db5ab2832b8be76433957e22bd781bd.png" alt="两个扩展.png"></p><ol start="5"><li>在安装完 Dash to Dock 时,你会发现侧边栏消失了,相信这是大多数人想要的效果;</li></ol><p><img src="https://img.imql.life/illustrations/05694be5c960e35457c5811b46b5082b.png" alt="侧边栏消失了.png"></p><ol start="6"><li>打开优化;</li></ol><p><img src="https://img.imql.life/illustrations/5365e26e1df3fc989d4d089d7c4f4ccd.png" alt="优化.png"></p><ol start="7"><li>打开 Dash to Dock 的设置;</li></ol><p><img src="https://img.imql.life/illustrations/09ff045b6d861d6fdedf7dacf5ced7c8.png" alt="DashtoDock设置.png"></p><ol start="8"><li>打开智能隐藏的设置;</li></ol><p><img src="https://img.imql.life/illustrations/6688e712d1ecc3133ad840d7f4c59097.png" alt="智能隐藏的设置.png"></p><ol start="9"><li>勾选在全屏状态下启用,不勾选推压以显示…,调整显示超时时间为 0.2 秒,关闭窗口,此时,再打开火狐浏览器,当把鼠标移动到左侧,侧边栏自动显示,移走鼠标,侧边栏自动隐藏,相信这同样是大多数人想要的效果;</li></ol><p><img src="https://img.imql.life/illustrations/b4cbf2dc73364c714caf009b595339a8.png" alt="设置和调整.png"></p><p><img src="https://img.imql.life/illustrations/961dc24e9ae9b921ddb0e6a8e91e3809.gif" alt="智能隐藏.gif"></p><ol start="10"><li>打开火狐浏览器,进入<a href="https://www.gnome-look.org/p/1275087/">该网址</a>下载 McMojave 主题,等待,确定;</li></ol><p><img src="https://img.imql.life/illustrations/fb441f21ce4b1045578360f903f8ec13.png" alt="下载主题.png"></p><ol start="11"><li>提取到下载中,点击显示文件;</li></ol><p><img src="https://img.imql.life/illustrations/b0610ba5a33eb63d6f485977cb7aba05.png" alt="提取.png"></p><ol start="12"><li>右键,在终端打开;</li></ol><p><img src="https://img.imql.life/illustrations/c45e6931c61452732f18b74134ba6cbb.png" alt="右键.png"></p><ol start="13"><li>输入以下命令回车,输入用户密码,移动 Mojave-light 目录;</li></ol><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">sudo <span class="built_in">mv</span> Mojave-light/ /usr/share/themes/</span><br></pre></td></tr></table></figure><ol start="14"><li>打开优化,选择 Mojave-light 主题,就能看到效果了;</li></ol><p><img src="https://img.imql.life/illustrations/0b66d518605a2065cf71beb08c6cc2a5.gif" alt="更换主题.gif"></p><ol start="15"><li><a href="https://www.gnome-look.org/p/1305429/">进入该网址</a>,下载 McMojave-circle 图标,等待,确定;</li></ol><p><img src="https://img.imql.life/illustrations/e59a02cfceaa33027ff081ba8e184b5f.png" alt="下载图标.png"></p><ol start="16"><li>同上,提取到下载中,点击显示文件,右键,在终端打开,输入以下命令回车,输入用户密码,移动 McMojave-circle 目录;</li></ol><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">sudo <span class="built_in">mv</span> McMojave-circle/ /usr/share/icons/</span><br></pre></td></tr></table></figure><ol start="17"><li>打开优化,选择 McMojave-circle 图标,就能看到效果了;</li></ol><p><img src="https://img.imql.life/illustrations/a723f7f4dc2a57c51b5e1d156c785bd8.gif" alt="更换图标.gif"></p><ol start="18"><li>有一个地方忘记了,打开优化,选择 shell 为 Mojave-light;</li></ol><p><img src="https://img.imql.life/illustrations/4e0259728c9945df954e2985370167c1.gif" alt="更换shell.gif"></p><ol start="19"><li>可以在 Dash to Dock 设置中设置侧边栏的位置在底部;</li></ol><p><img src="https://img.imql.life/illustrations/0332e44f1bc1cc4fa5e4300ee1ecb0bf.png" alt="设置在底部.png"></p><ol start="20"><li>最后,在优化->窗口中,设置标题栏按钮在左边,右键桌面更换个壁纸,至此,美化算是告一段落了。</li></ol><h3 id="安装_build_essential_软件包和_Vim_文本编辑器">安装 build-essential 软件包和 Vim 文本编辑器<a class="headerlink" href="#安装_build_essential_软件包和_Vim_文本编辑器"></a></h3><p>右键点击桌面,在终端打开,输入以下命令回车,输入用户密码安装 build-essential 软件包。</p><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">sudo apt-get install build-essential</span><br></pre></td></tr></table></figure><p>再输入以下命令回车,输入用户密码安装 Vim 文本编辑器。</p><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">sudo apt-get install vim</span><br></pre></td></tr></table></figure><h2 id="注释">注释<a class="headerlink" href="#注释"></a></h2><p>如何注释应该是我们学习任何一门编程语言最先需要知道的,C 语言中有两种注释方式:</p><ul><li>以<code>/*</code>开始<code>*/</code>结束的块注释(block comment);</li><li>以<code>//</code>开始换行符结束的单行注释(line comment);</li></ul><h2 id="C_语言学习起步">C 语言学习起步<a class="headerlink" href="#C_语言学习起步"></a></h2><p>右键点击桌面,新建一个学习文件夹 C Learning,点开,再新建文件夹(一),再点开,再新建文件夹 20200404 ,再点开,右键,在终端打开。</p><h3 id="新建_hello_world_c_源文件、用_Vim_编辑并保存">新建 hello_world.c 源文件、用 Vim 编辑并保存<a class="headerlink" href="#新建_hello_world_c_源文件、用_Vim_编辑并保存"></a></h3><p>输入以下命令新建 hello_world.c 源文件并用 Vim 打开:</p><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">vim hello_world.c</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/7f105e0e9e6abf7660133a7e98e6105b.png" alt="hello_world.c.png"></p><p>按下 i 键进入插入模式,国际惯例,编写第一个程序:打印”Hello,World!“:</p><figure class="highlight c"><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 class="meta">#<span class="keyword">include</span> <span class="string"><stdio.h></span></span></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span>{</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"Hello,World!\n"</span>); <span class="comment">//print是打印的意思,f是format的简写,printf()函数的功能就是格式化输出</span></span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>按下 ESC 键进入一般模式,再按”SHIFT+;“(即输入英文的分号)进入命令模式,输入 wq 命令(write and quit),这样源文件就保存了。</p><p><img src="https://img.imql.life/illustrations/7df03374869b5d6300d42317e296651e.gif" alt="保存.gif"></p><h3 id="编译">编译<a class="headerlink" href="#编译"></a></h3><p>之后就是编译,输入以下命令回车执行(小技巧:打 hello_world.c 时,可以只打 h 再按 TAB 键,系统能自动匹配):</p><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">gcc hello_world.c</span><br></pre></td></tr></table></figure><p>输入以上命令后没有任何提示,别慌,这是正常的,在 Linux 中,没有消息就是好消息。可以输入以下命令(<code>ls -alF *</code>的别名)列出当前目录下有哪些文件和目录,./指的是当前目录,…/指的是上一级目录,hello_world.c 是刚刚保存的 C 源文件,那这个“a.out*”是什么呢?没错,就是刚刚编译出来的可执行文件( 星号表示该文件为可执行文件)。</p><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">ll</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/a261935a1fb2499da45d91cffd07057a.png" alt="a.out.png"></p><h3 id="运行">运行<a class="headerlink" href="#运行"></a></h3><p>有了可执行文件,就可以运行了,输入以下命令执行就能打印出“Hello,World!”了。</p><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">./a.out</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/cec2fc983f5766a56da78d26f96dbaee.png" alt="打印结果.png"></p><h3 id="小结">小结<a class="headerlink" href="#小结"></a></h3><p>以上就是 C 学习的起步内容,下面就开始正式的学习,会总是需要用到上面提到的新建并编辑保存、编译和运行的相关命令,还有一个小技巧,可以使用键盘的方向键上和下在历史命令中切换。</p><h2 id="做点计算">做点计算<a class="headerlink" href="#做点计算"></a></h2><p>范例:做点计算(新建 compute.c)</p><figure class="highlight c"><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"><span class="meta">#<span class="keyword">include</span> <span class="string"><stdio.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span>{</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"12+34=%d\n"</span>,<span class="number">12</span>+<span class="number">34</span>); <span class="comment">//%d为占位符,表示数据打印出来的格式应该是十进制整数的格式</span></span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">12+34=46</span><br></pre></td></tr></table></figure><p>除了做加法,当然还能做其他运算:</p><table><thead><tr><th>运算</th><th>运算符</th></tr></thead><tbody><tr><td>加</td><td>+</td></tr><tr><td>减</td><td>-</td></tr><tr><td>乘</td><td>*</td></tr><tr><td>除</td><td>/</td></tr><tr><td>取余数</td><td>%</td></tr><tr><td>括号</td><td>()</td></tr></tbody></table><h2 id="变量">变量<a class="headerlink" href="#变量"></a></h2><h3 id="变量类型">变量类型<a class="headerlink" href="#变量类型"></a></h3><p>C 语言是一种强类型的语言,所有的变量都必须有类型。</p><h3 id="变量定义">变量定义<a class="headerlink" href="#变量定义"></a></h3><p>变量定义的一般形式:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><类型名称> <变量名称>;</span><br></pre></td></tr></table></figure><p>范例:定义变量 price,存放价格的 int 型数据,定义变量 payment,存放支付金额的 int 型数据</p><figure class="highlight c"><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"><span class="type">int</span> price;</span><br><span class="line"><span class="type">int</span> payment;</span><br></pre></td></tr></table></figure><p>或</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> price,payment; <span class="comment">//可以在一行中定义多个同类型的变量,有逗号分隔</span></span><br></pre></td></tr></table></figure><h3 id="标识符">标识符<a class="headerlink" href="#标识符"></a></h3><p>标识符只能由字母、数字和下划线组成,数字不能出现在第一个字符的位置,标识符分为关键字,预定义标识符和用户自定义标识符,变量名称就属于用户自定义标识符。</p><h3 id="赋值运算符">赋值运算符<a class="headerlink" href="#赋值运算符"></a></h3><p>赋值也是一种运算,运算符为<code>=</code>,表示将右边的值复制一份赋给左边的变量,那么,这和数学中的等于号是一样的吗?当然不是,数学中的等于号表示的是相等的关系,C 语言也有表示相等关系的运算符,即<code>==</code>。</p><p>范例:使用赋值运算符初始化变量</p><figure class="highlight plaintext"><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">int price=56;</span><br><span class="line">int payment=100;</span><br></pre></td></tr></table></figure><p>或</p><figure class="highlight plaintext"><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">int price;</span><br><span class="line">int payment;</span><br><span class="line">price=56;</span><br><span class="line">payment=100;</span><br></pre></td></tr></table></figure><p>或</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">int price=56,payment=100;</span><br></pre></td></tr></table></figure><h3 id="用_scanf_函数初始化变量">用 scanf()函数初始化变量<a class="headerlink" href="#用_scanf_函数初始化变量"></a></h3><p>范例:定义 price 和 payment 并用 scanf() 函数初始化它们</p><figure class="highlight c"><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 class="type">int</span> price,payment;</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"请输入该商品价格(元):"</span>);</span><br><span class="line"><span class="built_in">scanf</span>(<span class="string">"%d"</span>,&price); <span class="comment">//scan是扫描的意思,f同样是format的简写,scanf()函数的功能就是格式化扫描,扫描什么?扫描字符呗,以回车为结束符(不计入输入中)将输入的字符以十进制整数的格式解析,&price的意思就是将解析出来的值复制一份赋给price</span></span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"请输入支付的金额(元):"</span>);</span><br><span class="line"><span class="built_in">scanf</span>(<span class="string">"%d"</span>,&payment); <span class="comment">//同上</span></span><br></pre></td></tr></table></figure><h3 id="变量的使用">变量的使用<a class="headerlink" href="#变量的使用"></a></h3><p>范例:找零(新建 change.c)</p><figure class="highlight c"><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></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><stdio.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span>{</span><br><span class="line"> <span class="type">int</span> price;</span><br><span class="line"> <span class="type">int</span> payment;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"请输入该商品价格(元):"</span>);</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&price); <span class="comment">//键盘输入的方式初始化price</span></span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"请输入支付的金额(元):"</span>);</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&payment); <span class="comment">//键盘输入的方式初始化payment</span></span><br><span class="line"> <span class="type">int</span> change=payment-price;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"找零(元):%d\n"</span>,change);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>运行结果:</p><p><img src="https://img.imql.life/illustrations/f4c0f3c4a63ce7fca095d6b31c118636.gif" alt="change.c.gif"></p><h3 id="没有初始化变量的后果">没有初始化变量的后果<a class="headerlink" href="#没有初始化变量的后果"></a></h3><p>范例:没有初始化 payment(修改 change.c)</p><figure class="highlight c"><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="meta">#<span class="keyword">include</span> <span class="string"><stdio.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span>{</span><br><span class="line"> <span class="type">int</span> price;</span><br><span class="line"> <span class="type">int</span> payment;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"请输入该商品价格(元):"</span>);</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&price); <span class="comment">//键盘输入的方式初始化price</span></span><br><span class="line"> <span class="type">int</span> change=payment-price;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"找零(元):%d\n"</span>,change);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>运行结果:</p><p><img src="https://img.imql.life/illustrations/bd8d24ad574370d6e0fcd433fa964575.gif" alt="没有初始化变量.gif"></p><p>什么!找零 2 亿多??!!原来,变量在没有初始化,也就是刚一定义时,其实就是有值的,可是这个值只有计算机知道,在发生意想不到的问题之前,我们应该时刻注意变量在定义后一定要初始化。</p><h2 id="常量">常量<a class="headerlink" href="#常量"></a></h2><h3 id="定义常量">定义常量<a class="headerlink" href="#定义常量"></a></h3><p>变量定义的一般形式:</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">const</span> <类型名称> <常量名称>; <span class="comment">//const是一个修饰符,是constant(常数)的简写,规定常量名称中的字母都为大写,这是命名规范</span></span><br></pre></td></tr></table></figure><h3 id="常量和变量的相同点和不同点">常量和变量的相同点和不同点<a class="headerlink" href="#常量和变量的相同点和不同点"></a></h3><p>相同点:常量和变量都需要初始化。</p><p>不同点:常量在初始化后不能再被修改而变量可以。</p><h3 id="常量的使用">常量的使用<a class="headerlink" href="#常量的使用"></a></h3><p>在找零程序中,该商品,比如说一本书,它的价格就是 56 元,没必要总是输入 56,于是我们可以这么写:</p><p>范例:使用常量(修改 change.c)</p><figure class="highlight c"><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="meta">#<span class="keyword">include</span> <span class="string"><stdio.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span>{</span><br><span class="line"> <span class="type">const</span> <span class="type">int</span> PRICE=<span class="number">56</span>;</span><br><span class="line"> <span class="type">int</span> payment;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"请输入支付的金额(元):"</span>);</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&payment); <span class="comment">//键盘输入的方式初始化payment</span></span><br><span class="line"> <span class="type">int</span> change=payment-PRICE;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"找零(元):%d\n"</span>,change);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>如果我们尝试去修改 PRICE 会如何?来试一下:</p><p>范例:尝试修改 PRICE(修改 change.c)</p><figure class="highlight c"><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></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><stdio.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span>{</span><br><span class="line"> <span class="type">const</span> <span class="type">int</span> PRICE=<span class="number">56</span>;</span><br><span class="line"> <span class="type">int</span> payment;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"请输入该商品价格(元):"</span>);</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&PRICE); <span class="comment">//尝试修改PRICE</span></span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"请输入支付的金额(元):"</span>);</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&payment); <span class="comment">//键盘输入的方式初始化payment</span></span><br><span class="line"> <span class="type">int</span> change=payment-PRICE;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"找零(元):%d\n"</span>,change);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>运行结果:</p><p><img src="https://img.imql.life/illustrations/94eedc4435b8ad27f619f9466d84258d.gif" alt="尝试修改PRICE.gif"></p><h2 id="浮点型">浮点型<a class="headerlink" href="#浮点型"></a></h2><p>美国人习惯用几英尺几英寸的方式描述自己的身高,如果遇到一个美国人告诉你他的身高为 5 英尺 7 英寸,他的身高应该是一米几呢?由于 1 英尺 = 12 英寸 = 0.3048 米,所以 5 英尺 7 英寸应该为 (5+7/12)*0.3048 米,即 1.7018 米。来写个程序:</p><p>范例:长度换算(新建 length_conversion.c)</p><figure class="highlight c"><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></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><stdio.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span>{</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"请分别输入身高的英尺和英寸,如5,7表示5英尺7英寸:"</span>);</span><br><span class="line"> <span class="type">int</span> foot; <span class="comment">//英尺</span></span><br><span class="line"> <span class="type">int</span> inch; <span class="comment">//英寸</span></span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d,%d"</span>,&foot,&inch);</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"身高是%f米\n"</span>,((foot+inch/<span class="number">12</span>)*<span class="number">0.3048</span>));</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>运行结果:</p><p><img src="https://img.imql.life/illustrations/6fc2821cffaa3589822b22ba6122fc09.gif" alt="长度换算.gif"></p><p>英尺似乎没发挥作用?这是怎么回事?原来,是由于 C 语言中相同数据类型的变量的计算结果仍然是该类型,inch 是 int 类型,12 是整形常量,默认是 int 类型,那么对于这个值永远都是在 0 到 11 范 围的 inch 来说,其与 12 的除法运算永远都是 int 类型,永远都会直接舍弃掉小数点后面的数据,永远都为 0,所以才会有以上的运行结果。</p><p>那么,以上程序该如何改进呢?这里,又紧接着引入一个知识点:在 C 语言中不同数据类型的变量的运算,是先将所有变量统一转化为一种表示范围最大的数据类型。</p><p>范例:长度换算(改)(修改 length_conversion.c)</p><figure class="highlight c"><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></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><stdio.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span>{</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"请分别输入身高的英尺和英寸,如5,7表示5英尺7英寸:"</span>);</span><br><span class="line"> <span class="type">int</span> foot; <span class="comment">//英尺</span></span><br><span class="line"> <span class="type">int</span> inch; <span class="comment">//英寸</span></span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d,%d"</span>,&foot,&inch);</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"身高是%f米\n"</span>,((foot+inch/<span class="number">12.0</span>)*<span class="number">0.3048</span>)); <span class="comment">//12是整形常量,默认是int类型,12.0是浮点型常量,默认是double类型</span></span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>运行结果:</p><p><img src="https://img.imql.life/illustrations/c867af565be3d4214d738d8dfa03da2e.gif" alt="长度换算(改).gif"></p><h2 id="表达式">表达式<a class="headerlink" href="#表达式"></a></h2><p>一个表达式是一系列运算符和算子的组合,用来计算出一个值。运算符(operator)是指进行运算的动作,比如加法运算符”+“,减法运算符”-“,算子(operand)是指参与运算的值,这个值可能是常数、变量和方法返回值等。</p><h2 id="参考视频">参考视频<a class="headerlink" href="#参考视频"></a></h2><p><a href="https://www.bilibili.com/video/BV19W411B7w1">翁凯 C 语言(bilibili)</a></p><p><a href="https://www.bilibili.com/video/BV17s411N78s">【C 语言】《带你学 C 带你飞》(bilibili)</a></p>]]></content>
<categories>
<category> C 从入门到精通 </category>
</categories>
<tags>
<tag> Ubuntu </tag>
<tag> VMware Workstation </tag>
</tags>
</entry>
<entry>
<title>Python 从入门到实践(二)</title>
<link href="/2020/02/10/Python-Learning(2)/"/>
<url>/2020/02/10/Python-Learning(2)/</url>
<content type="html"><![CDATA[<p>《Python 从入门到实践(一)》是 Python 初级部分的学习笔记,主要是一些基础方面的内容,本篇就为 Python 高级部分的学习笔记,主要是一些面向对象方面的内容。</p><span id="more"></span><h2 id="搭建实践环境">搭建实践环境<a class="headerlink" href="#搭建实践环境"></a></h2><p><a href="https://www.jetbrains.com/pycharm/download/">下载最流行的最新版的 Python 开发软件 PyCharm</a>,建议下载专业版,但是是收费的,如果你和我一样是用来学习的,可以在网上寻找方法免费使用。</p><ol><li>下载好后安装:Next;</li></ol><p><img src="https://img.imql.life/illustrations/62db5344c058783632633e9d494b4e25.png" alt="双击运行程序.png"></p><ol start="2"><li>设置安装路径:将 C 改为 D,Next;</li></ol><p><img src="https://img.imql.life/illustrations/b64333b56551961f21a382fb4d0128c9.png" alt="设置安装路径.png"></p><ol start="3"><li>勾选如图这两个选项,Next;</li></ol><p><img src="https://img.imql.life/illustrations/2eaee5ebde78890ef5d749f18ea37319.png" alt="勾选.png"></p><ol start="4"><li>Install;</li></ol><p><img src="https://img.imql.life/illustrations/a4c96f723b5a14fc689ead1beafc6702.png" alt="Install.png"></p><ol start="5"><li>勾选,Finish;</li></ol><p><img src="https://img.imql.life/illustrations/8e1a7020ff7a1129564ae2274fcf1017.png" alt="Finish.png"></p><ol start="6"><li>不导入设定,直接点 OK;</li></ol><p><img src="https://img.imql.life/illustrations/a6cf053e7b4411cec573bd1ef1b743b6.png" alt="OK.png"></p><ol start="7"><li>勾选上,Continue;</li></ol><p><img src="https://img.imql.life/illustrations/7a36478495fb4c067a5f33a7d94762ce.png" alt="同意.png"></p><ol start="8"><li>Don’t sent;</li></ol><p><img src="https://img.imql.life/illustrations/691b6e2b301be15d9684aedbcc8a5b0c.png" alt="否.png"></p><ol start="9"><li>设置 UI 主题;</li></ol><p><img src="https://img.imql.life/illustrations/d1382d50a4a5d7cd6b0f9bcebb5aa0ac.png" alt="Light.png"></p><ol start="10"><li>需要“学习化”,如何“学习化”这里就不多说了;</li></ol><p><img src="https://img.imql.life/illustrations/51210e1c1a70fab91c3f978fdf238b71.png" alt="激活.png"></p><ol start="11"><li>学习化完成后就是创建项目了,点击 Create New Project;</li></ol><p><img src="https://img.imql.life/illustrations/97875f7a970c80a477b80ea553ac6d6f.png" alt="创建.png"></p><ol start="12"><li>点击 Browse,找到自定义的文件夹,确定;</li></ol><p><img src="https://img.imql.life/illustrations/f06be40a8c16df97678420ce83d7264d.png" alt="Create.png"></p><ol start="13"><li>进行一些设置,点击 files,点击 Settings,在搜索框中搜索 font,按自己喜好设置字体和字体属性,我这里就仅仅将字体尺寸设大点吧,设为 20,确定;</li></ol><p><img src="https://img.imql.life/illustrations/2d44173d6265790e09f66e9c2008dc4d.png" alt="font.png"></p>]]></content>
<categories>
<category> Python 从入门到实践 </category>
</categories>
<tags>
<tag> Windows </tag>
<tag> Python </tag>
<tag> Pycharm </tag>
</tags>
</entry>
<entry>
<title>Java 从入门到实践(一)</title>
<link href="/2020/02/06/Java_Learning_1/"/>
<url>/2020/02/06/Java_Learning_1/</url>
<content type="html"><![CDATA[<p>Java——面向对象编程语言的领军者!</p><span id="more"></span><h2 id="搭建_Java_学习环境">搭建 Java 学习环境<a class="headerlink" href="#搭建_Java_学习环境"></a></h2><h3 id="安装_VMware_pro_15">安装 VMware pro 15<a class="headerlink" href="#安装_VMware_pro_15"></a></h3><p>下载<a href="https://www.52pojie.cn/thread-1026907-1-1.html">学习版</a>,安装步骤不多说了,只是有一点建议,也是我装软件的原则:能不装 C 盘就别装 C 盘。</p><h3 id="安装_Windows_10">安装 Windows 10<a class="headerlink" href="#安装_Windows_10"></a></h3><p>我在网上找到一个<a href="https://www.cnblogs.com/gxhunter/p/10290748.html">精简版的 Windows 10 系统</a>,有介绍和下载方式,这回就用这个精简版的镜像。由于是安装 Windows 系统,具体如何安装这里就不再多说了。</p><h3 id="安装_JDK_9_0_4">安装 JDK 9.0.4<a class="headerlink" href="#安装_JDK_9_0_4"></a></h3><p><a href="https://pan.baidu.com/s/1R0Y6nDqlYxKvelV3dAtekQ">下载 JDK 9.0.4</a>,提取码:ua1e,下好后安装,安装路径可以自定义,公共 JRE 可装可不装,如下图,我这次装一装。</p><p><img src="https://img.imql.life/illustrations/19dd03061f4f0d1f19f2726760baea57.png" alt="安装.png"></p><h3 id="配置系统环境变量">配置系统环境变量<a class="headerlink" href="#配置系统环境变量"></a></h3><p>右键此电脑->属性->高级系统设置->高级->环境变量,点击下方的新建,变量名填写 JAVA_HOME,变量值就是安装 JDK 9.0.4 时设置的路径,确定。</p><p>如下图,在系统变量栏中找到 Path 变量,点击编辑,点击新建,键入 %JAVA_HOME%\bin,确定。运行 CMD,键入 java,发现系统识别了 java 命令。</p><p><img src="https://img.imql.life/illustrations/de5c9e100f0c3ef2c44f0c6bf40af2b8.png" alt="Path.png"></p><h2 id="String(字符串)">String(字符串)<a class="headerlink" href="#String(字符串)"></a></h2><h2 id="类集框架">类集框架<a class="headerlink" href="#类集框架"></a></h2><h2 id="参考-2">参考<a class="headerlink" href="#参考-2"></a></h2><ul><li><a href="https://www.bilibili.com/video/BV1Lf4y1U7Cz?p=9">黑马 Java 零基础入门到就业_Java 基础(IDEA 版本)</a></li></ul>]]></content>
<categories>
<category> Java 从入门到实践 </category>
</categories>
<tags>
<tag> VMware Workstation </tag>
<tag> JDK </tag>
<tag> Windows </tag>
</tags>
</entry>
<entry>
<title>Python 从入门到实践(一)</title>
<link href="/2020/01/27/Python-Learning(1)/"/>
<url>/2020/01/27/Python-Learning(1)/</url>
<content type="html"><![CDATA[<p>在当今的环境下 Python 逐渐成为一门热门的语言,作为一门有着 30 年发展历史的编程语言,其在数据分析领域以及人工智能领域发挥着重要作用。Python 是基于 C 语言,一诞生就具备了完善的语法,其给程序员最直观的印象是——它的简洁性。</p><span id="more"></span><h2 id="Python_特点">Python 特点<a class="headerlink" href="#Python_特点"></a></h2><ol><li>语法简单灵活;</li><li>规范化代码;</li><li>Python 是一个开源项目,有着广泛的开发支持;</li><li>Python 是一门面向对象的编程语言;</li><li>Python 具有强大的可移植性;</li><li>Python 属于解释性的编程语言;</li><li>Python 是一个“胶水语言”;</li><li>Python 拥有良好的并发处理支持。</li></ol><h2 id="搭建_Python_学习环境">搭建 Python 学习环境<a class="headerlink" href="#搭建_Python_学习环境"></a></h2><p>前往<a href="https://www.python.org/"> Python 官网</a>下载最新版 Python,需要说明的是,Python2.x 和 Python3.x 之间存在较大差异,在开发中一般都使用 Python3.x,本次使用的版本为 3.8.1。</p><p><img src="https://img.imql.life/illustrations/a34cc43c7b29863f520a1d58bd084945.png" alt="最新版Python下载.png"></p><p>下载完成后运行安装程序,勾选 Add Python 3.8 to PATH,点击 Customize installation,点击 Next,点击 Install,等待安装完成。按下 Windows+R 组合键,输入 CMD 进入命令行窗口,输入 python,发现可进入 Python 交互式环境,如下图。</p><p><img src="https://img.imql.life/illustrations/a895778fe13964f9b250423aef160803.png" alt="Python交互式环境.png"></p><p>文本编辑器到底哪家强?我推荐 Visual Studio Code。<a href="https://code.visualstudio.com/">前往官网</a>,点击 Download for Windows,下载完成后运行安装程序,下一步即可,建议到下图这一步时勾选上这三个选项,等待安装完成。</p><p><img src="https://img.imql.life/illustrations/80cf3e513e05f4c37d2eba5d9c65c3f8.png" alt="勾选.png"></p><p>安装完成后进入 Visual Studio Code,进入扩展市场(左侧第五个图标),搜索 chinese,如下图,点击 Install 安装简体中文包,安装完成后点击 Restart Now,。</p><p><img src="https://img.imql.life/illustrations/323541e6bb2a759580e833fb8fc5de00.png" alt="安装简体中文包.png"></p><p>仍然点击左侧第五个图标,搜索 python,第一个就是微软官方的,如下图,安装。</p><p><img src="https://img.imql.life/illustrations/906d518282e07620fa1ed47cbffa5f79.png" alt="Python.png"></p><h2 id="Python_学习起步">Python 学习起步<a class="headerlink" href="#Python_学习起步"></a></h2><p>虽然 Python 拥有交互式环境,但是无论如何,程序是需要定义在源文件之中的,Python 源文件的后缀为 py。新建一个文件夹,名字自定义,例如 Python Learning,VS Code 中打开该文件夹,如下图(也可以直接右键点击 Python Learning,选择通过 Code 打开),VS Code 中新建文件,命名为 hello_world.py,文件中输入以下一行代码,Ctrl+S 保存。</p><figure class="highlight python"><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">print</span>(<span class="string">"Hello,world!"</span>)</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/0eada0e201cbcdffafc6d67850a6c527.png" alt="打开文件夹.png"></p><p>点击右上角运行图标,可看到学习任何一门编程语言时第一个编写的程序的运行结果,如下图。</p><p><img src="https://img.imql.life/illustrations/5cd833a7342e631ca4cdfbbd95e4d298.png" alt="第一个程序.png"></p><h2 id="注释-2">注释<a class="headerlink" href="#注释-2"></a></h2><ul><li>单行注释:<code># [注释内容]</code></li><li>多行注释:<code>'''[多行注释内容]'''</code>或<code>"""[多行注释内容]"""</code></li></ul><h2 id="变量(对象)">变量(对象)<a class="headerlink" href="#变量(对象)"></a></h2><p>Python 中的变量不需要声明,每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建。</p><p>范例:使用变量(修改文件 hello_world.py)</p><figure class="highlight python"><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">message = <span class="string">"Hello,world!"</span></span><br><span class="line"><span class="built_in">print</span>(message)</span><br><span class="line">message = <span class="string">"Hello,ql!"</span></span><br><span class="line"><span class="built_in">print</span>(message)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">Hello,world!</span><br><span class="line">Hello,ql!</span><br></pre></td></tr></table></figure><p>可以同时为多个变量赋值。</p><p>范例:为多个变量赋值(修改文件 hello_world.py)</p><figure class="highlight python"><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">message1, message2 = <span class="string">"Hello,world!"</span>, <span class="string">"Hello,ql!"</span></span><br><span class="line"><span class="built_in">print</span>(message1)</span><br><span class="line"><span class="built_in">print</span>(message2)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">Hello,world!</span><br><span class="line">Hello,ql!</span><br></pre></td></tr></table></figure><p>值得说明的是,如果我们比较熟悉面向对象的编程的话,Python 语言里面所有的变量严格意义上来讲应该被称为“对象”;</p><p>范例:定义变量但是不设置内容(新建文件 <a href="http://None.py">None.py</a>)</p><figure class="highlight python"><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">message = <span class="literal">None</span> <span class="comment"># 空引用</span></span><br><span class="line"><span class="built_in">print</span>(message)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">None</span><br></pre></td></tr></table></figure><p>很多编程语言都会使用<code>;</code>作为每行程序的完结符,然而<code>;</code>在 Python 中被设计为可选符号,如果希望在一行定义多个变量,可用<code>;</code>。</p><p>范例:使用<code>;</code>对一行中的多个变量进行区分(新建文件 hello_ql.py)</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">message = <span class="string">"Hello,world"</span> ;<span class="built_in">print</span>(message) ;message = <span class="string">"Hello,ql!"</span> ;<span class="built_in">print</span>(message)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">Hello,world!</span><br><span class="line">Hello,ql!</span><br></pre></td></tr></table></figure><p>和其他语言一样,Python 中,我们在命名变量时也需要遵守一些规则和指南,违反规则将导致错误,遵守指南让你编写的代码更容易阅读和理解:</p><ul><li>变量名只能包含字母、数字和下划线。变量名可以以字母或下划线开头但不能以数字开头;</li><li>变量名不能包含空格,但可用下划线代替;</li><li>不要将 Python 关键字用做变量名,注意将 Python 内置函数用做变量名时,虽然不会导致错误但将覆盖这些函数;</li><li>变量名应即简短又具有描述性。例如:name 比 n 好,student_name 比 s_n 好,name_length 比 length_of_persons_name;</li><li>慎用小写字母 i 和大写字母 O,因为它们可能被人错看成数字 1 和 0。</li></ul><h2 id="常用数据类型">常用数据类型<a class="headerlink" href="#常用数据类型"></a></h2><p>在 Python 之中常用的数据类型包括:整数、浮点数、复数、布尔、字符串、列表、元组、字典和日期。</p><p>范例:通过 type() 函数查看数据类型(新建文件 <a href="http://type.py">type.py</a>)</p><figure class="highlight python"><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">message = <span class="string">"Hello,world!"</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(message))</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><class 'str'></span><br></pre></td></tr></table></figure><p>"<class ‘str’>"表示 message 变量为字符串类型。</p><h3 id="整数和浮点数">整数和浮点数<a class="headerlink" href="#整数和浮点数"></a></h3><p>范例:两个整数相除(新建文件 <a href="http://num.py">num.py</a>)</p><figure class="highlight python"><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">num_a = <span class="number">10</span></span><br><span class="line">num_b = <span class="number">4</span></span><br><span class="line"><span class="built_in">print</span>(num_a/num_b)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">2.5</span></span><br></pre></td></tr></table></figure><p>范例:获取数据类型(修改文件 <a href="http://num.py">num.py</a>)</p><figure class="highlight python"><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">num_a = <span class="number">10</span></span><br><span class="line">num_b = <span class="number">4</span></span><br><span class="line"><span class="built_in">print</span>(num_a/num_b)</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(num_a))</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(num_b))</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(num_a/num_b))</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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"><class 'int'></span><br><span class="line"><class 'int'></span><br><span class="line"><class 'float'></span><br></pre></td></tr></table></figure><h3 id="复数">复数<a class="headerlink" href="#复数"></a></h3><p>复数数据类型不能直接使用,需要通过 complex() 函数。</p><p>范例:使用复数(一)(新建文件 <a href="http://complex.py">complex.py</a>)</p><figure class="highlight python"><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">num = <span class="built_in">complex</span>(<span class="number">10</span>,<span class="number">2</span>) <span class="comment"># 实部为10,虚部为2</span></span><br><span class="line"><span class="built_in">print</span>(num)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">(10+2j)</span><br></pre></td></tr></table></figure><p>范例:使用复数(二)(修改文件 <a href="http://complex.py">complex.py</a>)</p><figure class="highlight python"><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">num = <span class="built_in">complex</span>(<span class="number">10</span>,<span class="number">2</span>) <span class="comment"># 实部为10,虚部为2</span></span><br><span class="line"><span class="built_in">print</span>(num)</span><br><span class="line"><span class="built_in">print</span>(num.real) <span class="comment"># 获取实部</span></span><br><span class="line"><span class="built_in">print</span>(num.imag) <span class="comment"># 获取虚部</span></span><br><span class="line"><span class="built_in">print</span>(num.conjugate()) <span class="comment"># 获取共轭复数</span></span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">(10+2j)</span><br><span class="line">10.0</span><br><span class="line">2.0</span><br><span class="line">(10-2j)</span><br></pre></td></tr></table></figure><h3 id="布尔">布尔<a class="headerlink" href="#布尔"></a></h3><p>“布尔”是 19 世纪一位英国数学家的名字,Python 中布尔的取值:<code>True</code>和<code>False</code>。</p><p>范例:使用布尔(一)(新建文件 <a href="http://boolean.py">boolean.py</a>)</p><figure class="highlight python"><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">flag = <span class="literal">True</span> <span class="comment"># Python中的True是首字母大写的</span></span><br><span class="line"><span class="keyword">if</span> flag: <span class="comment"># 分支语句</span></span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"Hello,world!"</span>)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Hello,world!</span><br></pre></td></tr></table></figure><p>Python 是通过 C 语言开发的,Python 继承了布尔型值为 0 表示假,为非 0 表示真的特性。</p><p>范例:使用布尔(二)(修改文件 <a href="http://boolean.py">boolean.py</a>)</p><figure class="highlight python"><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">flag = <span class="number">1</span> <span class="comment"># 非0</span></span><br><span class="line"><span class="keyword">if</span> flag: <span class="comment"># 分支语句</span></span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"Hello,world!"</span>)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Hello,world!</span><br></pre></td></tr></table></figure><h3 id="字符串">字符串<a class="headerlink" href="#字符串"></a></h3><p>字符串是一个开发中最为重要的的概念,Python 中直接使用单引号<code>''</code>或双引号<code>""</code>进行字符串的定义,使用哪一种引号定义字符串都是一样的,但需统一,不同的引号可以嵌套。</p><p>范例:引号嵌套(新建文件 quotation_mark.py)</p><figure class="highlight python"><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">message = <span class="string">'"Hello,world!"'</span> <span class="comment"># 使用单引号定义字符串</span></span><br><span class="line"><span class="built_in">print</span>(message)</span><br><span class="line">message = <span class="string">"'Hello,ql!'"</span> <span class="comment"># 使用双引号定义字符串</span></span><br><span class="line"><span class="built_in">print</span>(message)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">"Hello,world!"</span><br><span class="line">'Hello,ql!'</span><br></pre></td></tr></table></figure><p>可使用<code>+</code>进行字符串的拼接操作。</p><p>范例:字符串的拼接(新建文件 <a href="http://string.py">string.py</a>)</p><figure class="highlight python"><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">message = <span class="string">"Hello,world!,"</span>+<span class="string">"Hello,ql!"</span></span><br><span class="line"><span class="built_in">print</span>(message)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Hello,world!,Hello,ql!</span><br></pre></td></tr></table></figure><h4 id="常用转义字符串">常用转义字符串<a class="headerlink" href="#常用转义字符串"></a></h4><table><thead><tr><th>符号</th><th>描述</th><th>符号</th><th>描述</th></tr></thead><tbody><tr><td>\</td><td>续航符,实现字符串多行定义</td><td>\n</td><td>换行</td></tr><tr><td>\\</td><td>等价于“\”</td><td>\v</td><td>纵向制表符</td></tr><tr><td>\’</td><td>等价于单引号</td><td>\t</td><td>横向制表符</td></tr><tr><td>\"</td><td>等价于双引号</td><td>\r</td><td>回车</td></tr><tr><td>\000</td><td>空字符串</td><td>\f</td><td>换页</td></tr><tr><td>\b</td><td>退格</td><td>\oyy</td><td>八进制字符,如“\o12:”为换行</td></tr><tr><td>\e</td><td>转义</td><td>\xyy</td><td>十进制字符,如“\x0a”为换行</td></tr></tbody></table><p>范例:使用转义字符串(新建文件 <a href="http://escape.py">escape.py</a>)</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">message = <span class="string">"Python:\"Hello,world!\"\n\tPython:\"Hello,ql!\""</span></span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">Python:"Hello,world!"</span><br><span class="line"> Python:"Hello,ql!"</span><br></pre></td></tr></table></figure><h3 id="函数_input">函数 input()<a class="headerlink" href="#函数_input"></a></h3><p>利用函数 input(),Python 可以接受通过键盘输入的字符串类型的数据</p><p>范例:通过键盘输入数据(新建文件 <a href="http://input.py">input.py</a>)</p><figure class="highlight python"><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">input_data = <span class="built_in">input</span>(<span class="string">"你的名字:"</span>) <span class="comment"># 给出提示字符串</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">"Python:Hello,"</span>+input_data+<span class="string">"!"</span>)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">你的名字:ql</span><br></pre></td></tr></table></figure><figure class="highlight plaintext"><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">你的名字:ql</span><br><span class="line">Python:Hello,ql!</span><br></pre></td></tr></table></figure><p>范例:获取输入类型(修改文件 <a href="http://input.py">input.py</a>)</p><figure class="highlight python"><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">input_data = <span class="built_in">input</span>(<span class="string">"你的名字:"</span>) <span class="comment"># 给出提示字符串</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">"Python:Hello,"</span>+input_data+<span class="string">"!"</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(input_data))</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">你的名字:ql</span><br></pre></td></tr></table></figure><figure class="highlight plaintext"><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">你的名字:ql</span><br><span class="line">Python:Hello,ql!</span><br><span class="line"><class 'str'></span><br></pre></td></tr></table></figure><h3 id="数据类型转换函数">数据类型转换函数<a class="headerlink" href="#数据类型转换函数"></a></h3><table><thead><tr><th>函数</th><th>描述</th></tr></thead><tbody><tr><td>int(数据)</td><td>将指定数据转为整形数据</td></tr><tr><td>float(数据)</td><td>将指定数据转为浮点型数据</td></tr><tr><td>bool(数据)</td><td>将指定数据转为布尔型数据</td></tr><tr><td>str(数据)</td><td>将指定数据转为字符串型数据</td></tr></tbody></table><p>范例:int() 函数(一)(新建文件 <a href="http://int.py">int.py</a>)</p><figure class="highlight python"><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"><span class="built_in">str</span> = <span class="string">"155"</span></span><br><span class="line">temp = <span class="built_in">int</span>(<span class="built_in">str</span>)</span><br><span class="line"><span class="built_in">print</span>(temp)</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(temp))</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">155</span><br><span class="line"><class 'int'></span><br></pre></td></tr></table></figure><p>如果字符串不是由规定字符组成,<a href="http://int.py">int.py</a> 就会产生异常。</p><p>范例:字符串不是由规定字符组成(修改文件 <a href="http://int.py">int.py</a>)</p><figure class="highlight python"><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"><span class="built_in">str</span> = <span class="string">"2BC9"</span></span><br><span class="line">temp = <span class="built_in">int</span>(<span class="built_in">str</span>)</span><br><span class="line"><span class="built_in">print</span>(temp)</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(temp))</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">Traceback (most recent call last):</span><br><span class="line"> File "d:/Python Learning/20200205/int.py", line 2, in <module></span><br><span class="line"> temp = int(str)</span><br><span class="line">ValueError: invalid literal for int() with base 10: '2BC9'</span><br></pre></td></tr></table></figure><p>范例:int() 函数(二)(修改文件 <a href="http://int.py">int.py</a>)</p><figure class="highlight python"><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"><span class="built_in">str</span> = <span class="string">"199"</span></span><br><span class="line">num_f = <span class="string">"199.6"</span></span><br><span class="line">num_bol = <span class="literal">True</span> <span class="comment"># True转为整形数据1</span></span><br><span class="line">result = <span class="built_in">int</span>(<span class="built_in">str</span>) + <span class="built_in">int</span>(num_f) + <span class="built_in">int</span>(num_bol)</span><br><span class="line"><span class="built_in">print</span>(result)</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(result))</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">399</span><br><span class="line"><class 'int'></span><br></pre></td></tr></table></figure><p>范例:int() 函数(三)(修改文件 <a href="http://int.py">int.py</a>)</p><figure class="highlight python"><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">num_a = <span class="built_in">int</span>(<span class="built_in">input</span>(<span class="string">"请输入第一个整数:"</span>))</span><br><span class="line">num_b = <span class="built_in">int</span>(<span class="built_in">input</span>(<span class="string">"请输入第二个整数:"</span>))</span><br><span class="line">result = num_a + num_b</span><br><span class="line"><span class="built_in">print</span>(num_a+<span class="string">"+"</span>+num_b+<span class="string">"="</span>+result)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">请输入第一个整数:12</span><br></pre></td></tr></table></figure><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">请输入第二个整数:13</span><br></pre></td></tr></table></figure><figure class="highlight plaintext"><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">请输入第一个整数:12</span><br><span class="line">请输入第二个整数:13</span><br><span class="line">Traceback (most recent call last):</span><br><span class="line"> File "d:/Python Learning/20200205/int.py", line 4, in <module></span><br><span class="line"> print(num_a+"+"+num_b+"="+result)</span><br><span class="line">TypeError: unsupported operand type(s) for +: 'int' and 'str'</span><br></pre></td></tr></table></figure><p>使用<code>+</code>拼接任何数据与字符串时都需要先将任何数据转为字符串类型。</p><p>范例:改正以上错误(修改文件 <a href="http://int.py">int.py</a>)</p><figure class="highlight python"><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">num_a = <span class="built_in">int</span>(<span class="built_in">input</span>(<span class="string">"请输入第一个整数:"</span>))</span><br><span class="line">num_b = <span class="built_in">int</span>(<span class="built_in">input</span>(<span class="string">"请输入第二个整数:"</span>))</span><br><span class="line">result = num_a + num_b</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">str</span>(num_a)+<span class="string">"+"</span>+<span class="built_in">str</span>(num_b)+<span class="string">"="</span>+<span class="built_in">str</span>(result))</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">请输入第一个整数:12</span><br></pre></td></tr></table></figure><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">请输入第二个整数:13</span><br></pre></td></tr></table></figure><figure class="highlight plaintext"><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">请输入第一个整数:12</span><br><span class="line">请输入第二个整数:13</span><br><span class="line">12+13=25</span><br></pre></td></tr></table></figure><h3 id="格式化输出">格式化输出<a class="headerlink" href="#格式化输出"></a></h3><p>在使用<code>+</code>拼接字符串时总是得先将所有数据转为字符串实在是太麻烦。Python 沿用了传统的格式化输出标记和格式化输出辅助标记。</p><h4 id="格式化输出标记">格式化输出标记<a class="headerlink" href="#格式化输出标记"></a></h4><table><thead><tr><th>标记</th><th>描述</th><th>标记</th><th>描述</th></tr></thead><tbody><tr><td>%c</td><td>输出单个字符字符串</td><td>%s</td><td>输出字符串</td></tr><tr><td>%d</td><td>输出整形</td><td>%f</td><td>输出浮点型,可设置精度</td></tr><tr><td>%e</td><td>以科学计数法格式输出,使用小写字母 e</td><td>%E</td><td>以科学计数法格式输出,使用大写字母 E</td></tr><tr><td>%g</td><td>%f 和 %e 的简写</td><td>%G</td><td>%f 和 %E 的简写</td></tr><tr><td>%u</td><td>输出无符号整型</td><td>%o</td><td>输出无符号八进制数</td></tr><tr><td>%x</td><td>输出无符号十六进制数</td><td>%X</td><td>输出无符号十六进制数(大写字母)</td></tr></tbody></table><p>范例:格式化输出标记(新建文件 <a href="http://format1.py">format1.py</a>)</p><figure class="highlight python"><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">age = <span class="number">23</span></span><br><span class="line">url = <span class="string">"https://ql-isaac.github,io"</span></span><br><span class="line">qq = <span class="number">834471527</span></span><br><span class="line">message = <span class="string">"ql 今年 %d 岁,我的个人博客地址:%s,我的 qq 号码(十六进制):0X%X。"</span>%(age,url,qq)</span><br><span class="line"><span class="built_in">print</span>(message)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ql 今年 23 岁,我的个人博客地址:https://ql-isaac.github,io,我的 qq 号码(十六进制):0X31BD0667。</span><br></pre></td></tr></table></figure><h4 id="格式化输出辅助标记">格式化输出辅助标记<a class="headerlink" href="#格式化输出辅助标记"></a></h4><table><thead><tr><th>标记</th><th>描述</th><th>标记</th><th>描述</th></tr></thead><tbody><tr><td>*</td><td>定义宽度或小数点精度</td><td>#</td><td>在八进制数前面显示零(0),在十六进制数前面显示“0x”或“0X”</td></tr><tr><td>-</td><td>左对齐</td><td>0</td><td>显示位数不足时填充 0</td></tr><tr><td>+</td><td>在正数前面显示加号</td><td>m.n</td><td>m 设置显示总长度,n 设置小数位数</td></tr><tr><td>空格</td><td>显示位数不足时填充空格</td><td></td><td></td></tr><tr><td>(var)</td><td>映射变量(字典参数)</td><td></td><td></td></tr></tbody></table><p>范例:格式化输出辅助标记(一)(新建文件 <a href="http://format2.py">format2.py</a>)</p><figure class="highlight python"><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">num_a = <span class="number">192.121231311121231</span></span><br><span class="line">num_b = <span class="number">98.23</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">"%f,%f"</span>%(num_a,num_b)) <span class="comment"># %f 默认保留小数点后六位数字</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">"%5.2f,%10.2f"</span>%(num_a,num_b))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">"%5.2f,%010.2f"</span>%(num_a,num_b))</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">192.121231,98.230000</span><br><span class="line">192.12, 98.23</span><br><span class="line">192.12,0000098.23</span><br></pre></td></tr></table></figure><p>范例:格式化输出辅助标记(二)(修改文件 <a href="http://format2.py">format2.py</a>)</p><figure class="highlight python"><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">num_a = <span class="number">192.121231311121231</span></span><br><span class="line">num_b = <span class="number">98.23</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">"%(num_a)f,%(num_b)f"</span>%<span class="built_in">vars</span>()) <span class="comment"># %f 默认保留小数点后六位数字</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">"%(num_a)5.2f,%(num_b)10.2f"</span>%<span class="built_in">vars</span>())</span><br><span class="line"><span class="built_in">print</span>(<span class="string">"%(num_a)5.2f,%(num_b)010.2f"</span>%<span class="built_in">vars</span>())</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">192.121231,98.230000</span><br><span class="line">192.12, 98.23</span><br><span class="line">192.12,0000098.23</span><br></pre></td></tr></table></figure><h3 id="函数_print">函数 print()<a class="headerlink" href="#函数_print"></a></h3><p>默认情况下使用函数 print() 都会进行换行,如果不希望换行,可以使用“end“参数。</p><p>范例:使用“end“参数(新建文件 <a href="http://print.py">print.py</a>)</p><figure class="highlight python"><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="built_in">print</span>(<span class="string">"Python:Hello,world"</span>,end=<span class="string">"!"</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">"Hello,ql!"</span>,end=<span class="string">"\n"</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">"ql:Hello,Python!"</span>)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">Python:Hello,world!Hello,ql!</span><br><span class="line">ql:Hello,Python!</span><br></pre></td></tr></table></figure><h2 id="运算符">运算符<a class="headerlink" href="#运算符"></a></h2><h3 id="数学运算符">数学运算符<a class="headerlink" href="#数学运算符"></a></h3><table><thead><tr><th>运算符</th><th>描述</th><th>范例</th></tr></thead><tbody><tr><td>+</td><td>加法计算</td><td>20 + 15 = 35</td></tr><tr><td>-</td><td>减法计算</td><td>20 - 15 = 5</td></tr><tr><td>*</td><td>乘法计算</td><td>20 * 15 = 300</td></tr><tr><td>/</td><td>除法计算</td><td>20 / 15 =</td></tr><tr><td>%</td><td>取模计算</td><td>10 % 3 = 1</td></tr><tr><td>**</td><td>幂运算</td><td>10 ** 3 = 1000</td></tr><tr><td>//</td><td>整除计算</td><td>10 // 3 = 3</td></tr></tbody></table><p>范例:数学运算符(一)(新建文件 <a href="http://arithmetic.py">arithmetic.py</a>)</p><figure class="highlight python"><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">result = (<span class="number">1</span> + <span class="number">2</span>) * (<span class="number">4</span> / <span class="number">2</span>)</span><br><span class="line"><span class="built_in">print</span>(result)</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(result)) <span class="comment"># 只要进行了除法,返回的数据类型就是浮点型</span></span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">6.0</span><br><span class="line"><class 'float'></span><br></pre></td></tr></table></figure><p>范例:数学运算符(二)(修改文件 <a href="http://arithmetic.py">arithmetic.py</a>)</p><figure class="highlight python"><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">result = (<span class="number">1</span> + <span class="number">2</span>) * (<span class="number">4</span> // <span class="number">2</span>)</span><br><span class="line"><span class="built_in">print</span>(result)</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(result))</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">6</span><br><span class="line"><class 'int'></span><br></pre></td></tr></table></figure><h3 id="简化赋值运算符">简化赋值运算符<a class="headerlink" href="#简化赋值运算符"></a></h3><table><thead><tr><th>运算符</th><th>范例</th><th>形如</th></tr></thead><tbody><tr><td>+=</td><td>a += b</td><td>a = a + b</td></tr><tr><td>-=</td><td>a -= b</td><td>a = a - b</td></tr><tr><td>*=</td><td>a *= b</td><td>a = a * b</td></tr><tr><td>/=</td><td>a /= b</td><td>a = a / b</td></tr><tr><td>%=</td><td>a %= b</td><td>a = a % b</td></tr><tr><td>**=</td><td>a **= b</td><td>a = a ** b</td></tr><tr><td>//=</td><td>a //= b</td><td>a = a // b</td></tr></tbody></table><p>范例:字符串上使用乘法(新建文件 <a href="http://multiplication.py">multiplication.py</a>)</p><figure class="highlight python"><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">message = <span class="string">"Hello,world!"</span></span><br><span class="line">message *= <span class="number">3</span></span><br><span class="line"><span class="built_in">print</span>(message)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Hello,world!Hello,world!Hello,world!</span><br></pre></td></tr></table></figure><p>Python 中没有自增(<code>++</code>)和自减(<code>--</code>)运算符,因为 Python 中所有的变量都为对象,所有的数据类型都为引用数据类型,而自增(<code>++</code>)和自减(<code>--</code>)运算符是只适用于基本数据类型的。</p><h3 id="关系运算符">关系运算符<a class="headerlink" href="#关系运算符"></a></h3><table><thead><tr><th>运算符</th><th>描述</th><th>范例</th></tr></thead><tbody><tr><td>==</td><td>相等比较</td><td>1 == 1(True)</td></tr><tr><td>!=</td><td>不等比较</td><td>1 != 1(False)</td></tr><tr><td>></td><td>大于比较</td><td>10 > 5(True)</td></tr><tr><td><</td><td>小于比较</td><td>10 < 20(True)</td></tr><tr><td>>=</td><td>大于等于比较</td><td>10 >= 10(True)</td></tr><tr><td><=</td><td>小于等于比较</td><td>20 <= 20(True)</td></tr></tbody></table><p>关系运算符除了能针对数值型数据进行比较之外,还能比较字符串,比较字符串实际上就是依次比较字符的编码。</p><p>范例:比较字符串(新建文件 <a href="http://string.py">string.py</a>)</p><figure class="highlight python"><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"><span class="built_in">print</span>(<span class="string">"ql"</span> == <span class="string">"ql"</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">"ql"</span> > <span class="string">"Ql"</span> > <span class="string">"QL"</span>)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">True</span><br><span class="line">True</span><br></pre></td></tr></table></figure><p>如果想知道某单个字符字符串的编码,可使用 ord() 函数。</p><p>范例:查看某单个字符字符串的编码(新建文件 <a href="http://ord.py">ord.py</a>)</p><figure class="highlight python"><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">print</span>(<span class="string">"小写的“l”的编码:%d,大写的“L”的编码:%d"</span>%(<span class="built_in">ord</span>(<span class="string">"l"</span>),<span class="built_in">ord</span>(<span class="string">"L"</span>)))</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">小写的“l”的编码:108,大写的“L”的编码:76</span><br></pre></td></tr></table></figure><p>顺便说明一下数字和大小写字母的编码范围:</p><ul><li>数字:”0“(48) ~ ”9“(57)</li><li>大写字母:”A“(65) ~ ”Z“(90)</li><li>小写字母:”a“(97) ~ “z”(122)</li></ul><h3 id="逻辑运算符">逻辑运算符<a class="headerlink" href="#逻辑运算符"></a></h3><table><thead><tr><th>运算符</th><th>描述</th></tr></thead><tbody><tr><td>and</td><td>逻辑与</td></tr><tr><td>or</td><td>逻辑或</td></tr><tr><td>not</td><td>逻辑非</td></tr></tbody></table><h3 id="位运算符">位运算符<a class="headerlink" href="#位运算符"></a></h3><table><thead><tr><th>运算符</th><th>描述</th></tr></thead><tbody><tr><td>&</td><td>位与</td></tr><tr><td>|</td><td>位或</td></tr><tr><td>^</td><td>位异或</td></tr><tr><td>~</td><td>位非</td></tr><tr><td><<</td><td>左移运算符</td></tr><tr><td>>></td><td>右移运算符</td></tr></tbody></table><h3 id="进制转换函数">进制转换函数<a class="headerlink" href="#进制转换函数"></a></h3><table><thead><tr><th>函数</th><th>描述</th></tr></thead><tbody><tr><td>bin(数据)</td><td>转换为二进制数据</td></tr><tr><td>oct(数据)</td><td>转换为八进制数据</td></tr><tr><td>int(数据)</td><td>转换为十进制数据</td></tr><tr><td>hex(数据)</td><td>转换为十六进制数据</td></tr></tbody></table><h3 id="身份运算符">身份运算符<a class="headerlink" href="#身份运算符"></a></h3><p>Python 中所有的数据类型都为引用数据类型,id() 函数可以获取相应的内存地址。</p><p>范例:id() 函数(新建文件 <a href="http://id.py">id.py</a>)</p><figure class="highlight python"><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">num_a = <span class="number">2</span></span><br><span class="line">num_b = <span class="number">1</span> + <span class="number">1</span></span><br><span class="line">num_c = <span class="number">4</span> - <span class="number">2</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">"num_a 变量的地址:%d"</span>%<span class="built_in">id</span>(num_a))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">"num_b 变量的地址:%d"</span>%<span class="built_in">id</span>(num_b))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">"num_c 变量的地址:%d"</span>%<span class="built_in">id</span>(num_c))</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">num_a 变量的地址:1757145024</span><br><span class="line">num_b 变量的地址:1757145024</span><br><span class="line">num_c 变量的地址:1757145024</span><br></pre></td></tr></table></figure><p>Python 中相等比较运算符<code>==</code>类似于 Java 中的<code>equals()</code>。</p><p>范例:内容相等比较(新建文件 <a href="http://equals.py">equals.py</a>)</p><figure class="highlight python"><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">num_a = <span class="number">2</span> <span class="comment"># 整形</span></span><br><span class="line">num_b =<span class="number">2.0</span> <span class="comment"># 浮点型</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">"整形变量地址:%d,浮点型变量地址:%d,两者内容是否相等:%s"</span>%(<span class="built_in">id</span>(num_a),<span class="built_in">id</span>(num_b),(num_a == num_b)))</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">整形变量地址:1757145024,浮点型变量地址:11878208,两者内容是否相等:True</span><br></pre></td></tr></table></figure><p>那么 Java 中的<code>==</code>在 Python 中用什么运算符替代呢?答案是身份运算符。</p><table><thead><tr><th>运算符</th><th>描述</th></tr></thead><tbody><tr><td>is</td><td>判断是否引用同一内存</td></tr><tr><td>is not</td><td>判断是否引用不同内存</td></tr></tbody></table><p>范例:内存地址相等比较(修改文件 <a href="http://equals.py">equals.py</a>)</p><figure class="highlight python"><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">num_a = <span class="number">2</span> <span class="comment"># 整形</span></span><br><span class="line">num_b = <span class="number">2.0</span> <span class="comment"># 浮点型</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">"整形变量地址:%d,浮点型变量地址:%d,两者地址是否相等:%s"</span>%(<span class="built_in">id</span>(num_a),<span class="built_in">id</span>(num_b),(num_a <span class="keyword">is</span> num_b)))</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">整形变量地址:1757145024,浮点型变量地址:16400192,两者内容是否相等:False</span><br></pre></td></tr></table></figure><h2 id="分支结构">分支结构<a class="headerlink" href="#分支结构"></a></h2><p>针对分支结构的实现,Python 里有三个关键字:<code>if</code>、<code>elif</code>(Python 单独提供了该关键字,同 else if)和<code>else</code>,三种语法:</p><ul><li>if 判断</li></ul><figure class="highlight python"><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"><span class="keyword">if</span> <布尔表达式>:</span><br><span class="line"> <语句块></span><br></pre></td></tr></table></figure><ul><li>if…else 判断</li></ul><figure class="highlight python"><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"><span class="keyword">if</span> <布尔表达式>:</span><br><span class="line"> <语句块></span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> <语句块></span><br></pre></td></tr></table></figure><ul><li>多条件判断</li></ul><figure class="highlight python"><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"><span class="keyword">if</span> <布尔表达式>:</span><br><span class="line"> <语句块></span><br><span class="line"><span class="keyword">elif</span> <布尔表达式>:</span><br><span class="line"> <语句块></span><br><span class="line"><span class="keyword">elif</span> <布尔表达式>:</span><br><span class="line"> <语句块></span><br><span class="line"> <...></span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> <语句块></span><br></pre></td></tr></table></figure><p>不得不说说 Python 中的缩进,Python 根据缩进来判断代码行与前一个代码行的关系,类似于 C 和 Java 语言的大括号,PEP8 建议每级缩进都使用四个空格,这既可提高可读性,又留下了足够多的多级缩进空间。</p><p>范例:判断闰年(新建文件 leap_year.py)</p><figure class="highlight python"><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">year = <span class="built_in">int</span>(<span class="built_in">input</span>(<span class="string">"请输入一个年份:"</span>))</span><br><span class="line"><span class="keyword">if</span> (year % <span class="number">4</span>) == <span class="number">0</span>:</span><br><span class="line"> <span class="keyword">if</span>(year % <span class="number">100</span>) == <span class="number">0</span>:</span><br><span class="line"> <span class="keyword">if</span>(year % <span class="number">400</span>) == <span class="number">0</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"%d 年是闰年"</span>%(year)) <span class="comment"># 整百年里能被400整除的是闰年</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"%d 年不是闰年"</span>%(year))</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"%d 年是闰年"</span>%(year)) <span class="comment"># 非整百年里能被4整除的为闰年</span></span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"%d 年不是闰年"</span>%(year))</span><br></pre></td></tr></table></figure><h2 id="循环结构">循环结构<a class="headerlink" href="#循环结构"></a></h2><p>循环结构指的就是某段代码重复地执行,在循环结构之中需要定义一个循环的条件,只有在满足循环条件时代码才执行,Python 中循环结构有两种:while 循环和 for 循环。</p><h3 id="while_循环">while 循环<a class="headerlink" href="#while_循环"></a></h3><figure class="highlight python"><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="keyword">while</span> <循环条件>:</span><br><span class="line"> <循环语句块></span><br><span class="line"> <修改循环条件></span><br></pre></td></tr></table></figure><p>或</p><figure class="highlight python"><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 class="keyword">while</span> <循环条件>:</span><br><span class="line"> <循环语句块></span><br><span class="line"> <修改循环条件></span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> <循环条件不满足时执行的语句块></span><br></pre></td></tr></table></figure><p>范例:进行 1~100 的自然数的累加(新建文件 <a href="http://accumulation.py">accumulation.py</a>)</p><figure class="highlight python"><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"><span class="built_in">sum</span> = <span class="number">0</span></span><br><span class="line">num = <span class="number">1</span></span><br><span class="line"><span class="keyword">while</span> num <= <span class="number">100</span>:</span><br><span class="line"> <span class="built_in">sum</span> = <span class="built_in">sum</span> + num</span><br><span class="line"> num += <span class="number">1</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">sum</span>)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">5050</span><br></pre></td></tr></table></figure><p>范例:打印 1000 以内的斐波那契数列(新建文件 fibonacci_sequence.py)</p><figure class="highlight python"><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">num_a = <span class="number">0</span></span><br><span class="line">num_b = <span class="number">1</span></span><br><span class="line"><span class="keyword">while</span> num_b < <span class="number">1000</span>:</span><br><span class="line"> <span class="built_in">print</span>(num_b,end=<span class="string">"、"</span>)</span><br><span class="line"> temp = num_b;</span><br><span class="line"> num_b = num_a + num_b</span><br><span class="line"> num_a = temp</span><br></pre></td></tr></table></figure><h3 id="for_循环">for 循环<a class="headerlink" href="#for_循环"></a></h3><table><thead><tr><th>for 循环</th><th>for…else 循环</th></tr></thead><tbody><tr><td>for <变量> in <序列></td><td></td></tr></tbody></table><p><循环语句> | for <变量> in <序列></p><p><循环语句></p><p>else:</p><p><循环语句执行完毕后的语句> |</p><h2 id="序列">序列<a class="headerlink" href="#序列"></a></h2><p>Python 在设计的过程中强调的一直是简洁性。在许多的编程语言中,都是首先利用了数组去描述多数据的存储,但是数组有长度固定,插入麻烦等缺点,因而才有了许多数据结构来满足我们的各种需求,Python 则帮我们封装了数组和许多数据结构,相应着重提出了序列这一概念,将能动态修改的内容统一称为序列,在 Python 之中字符串、列表、元组、字典都属于序列。</p><h3 id="列表">列表<a class="headerlink" href="#列表"></a></h3><p>直接使用一对中括号定义列表,可使用索引访问列表元素,从 0 开始。</p><p>范例:定义列表(新建文件 <a href="http://list.py">list.py</a>)</p><figure class="highlight python"><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">infos = [<span class="string">"C/C++"</span>,<span class="string">"Java"</span>,<span class="string">"Python"</span>]</span><br><span class="line"><span class="built_in">print</span>(infos[<span class="number">0</span>],end=<span class="string">"、"</span>)</span><br><span class="line"><span class="built_in">print</span>(infos[<span class="number">1</span>],end=<span class="string">"、"</span>)</span><br><span class="line"><span class="built_in">print</span>(infos[<span class="number">2</span>])</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">C/C++、Java、Python</span><br></pre></td></tr></table></figure><h4 id="特性">特性<a class="headerlink" href="#特性"></a></h4><p>范例:空列表不等同于 None(新建文件 <a href="http://None.py">None.py</a>)</p><figure class="highlight python"><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">list_a = []</span><br><span class="line">list_b = <span class="literal">None</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">"list_a的地址为 %d,类型为 %s"</span>%(<span class="built_in">id</span>(list_a),<span class="built_in">type</span>(list_a))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">"list_b的地址为 %d,类型为 %s"</span>%(<span class="built_in">id</span>(list_b),<span class="built_in">type</span>(list_b))</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">list_a的地址为 13626696,类型为 <class 'list'></span><br><span class="line">list_b的地址为 1453821160,类型为 <class 'NoneType'></span><br></pre></td></tr></table></figure><p>范例:在进行索引访问时不能越界(修改文件 <a href="http://list.py">list.py</a>)</p><figure class="highlight python"><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">infos = [<span class="string">"C/C++"</span>,<span class="string">"Java"</span>,<span class="string">"Python"</span>]</span><br><span class="line"><span class="built_in">print</span>(infos[<span class="number">0</span>],end=<span class="string">"、"</span>)</span><br><span class="line"><span class="built_in">print</span>(infos[<span class="number">1</span>],end=<span class="string">"、"</span>)</span><br><span class="line"><span class="built_in">print</span>(infos[<span class="number">2</span>])</span><br><span class="line"><span class="built_in">print</span>(infos[<span class="number">3</span>])</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">C/C++、Java、Python</span><br><span class="line">Traceback (most recent call last):</span><br><span class="line"> File "d:/Python Learning/(一)/20200226/list.py", line 5, in <module></span><br><span class="line"> print(infos[3])</span><br><span class="line">IndexError: list index out of range</span><br></pre></td></tr></table></figure><p>范例:列表除了可以正向索引访问之外,还可以反向索引访问(修改文件 <a href="http://list.py">list.py</a>)</p><figure class="highlight python"><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">infos = [<span class="string">"C/C++"</span>,<span class="string">"Java"</span>,<span class="string">"Python"</span>]</span><br><span class="line"><span class="built_in">print</span>(infos[-<span class="number">3</span>],end=<span class="string">"、"</span>)</span><br><span class="line"><span class="built_in">print</span>(infos[-<span class="number">2</span>],end=<span class="string">"、"</span>)</span><br><span class="line"><span class="built_in">print</span>(infos[-<span class="number">1</span>])</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">C/C++、Java、Python</span><br></pre></td></tr></table></figure><p>范例:通过列表保存多种数据类型(新建文件 <a href="http://python.py">python.py</a>)</p><figure class="highlight python"><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">infos = [<span class="string">"Python"</span>,<span class="string">"简洁"</span>,[<span class="string">"列表元素 1"</span>,<span class="string">"列表元素 2"</span>,<span class="string">"列表元素 3"</span>]] <span class="comment"># 数据的意义:编程语言(Python),特点(简洁),举例(列表)</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">"编程语言:%s"</span>%infos[<span class="number">0</span>],end=<span class="string">"、"</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">"特点:%s"</span>%infos[<span class="number">1</span>],end=<span class="string">"、"</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">"举例:%s"</span>%infos[<span class="number">2</span>])</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">编程语言:Python、特点:简洁、举例:['列表元素 1', '列表元素 2', '列表元素 3']</span><br></pre></td></tr></table></figure><p>范例:使用 for 循环迭代输出(修改文件 <a href="http://list.py">list.py</a>)</p><figure class="highlight python"><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">infos = [<span class="string">"C/C++"</span>,<span class="string">"Java"</span>,<span class="string">"Python"</span>]</span><br><span class="line"><span class="keyword">for</span> pl <span class="keyword">in</span> infos:</span><br><span class="line"> <span class="built_in">print</span>(pl)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">C/C++</span><br><span class="line">Java</span><br><span class="line">Python</span><br></pre></td></tr></table></figure><p>范例:使用 for 循环索引访问输出(修改文件 <a href="http://list.py">list.py</a>)</p><figure class="highlight python"><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">infos = [<span class="string">"C/C++"</span>,<span class="string">"Java"</span>,<span class="string">"Python"</span>]</span><br><span class="line"><span class="keyword">for</span> index <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(infos)):</span><br><span class="line"> <span class="built_in">print</span>(infos[index])</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><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">C/C++</span><br><span class="line">Java</span><br><span class="line">Python</span><br></pre></td></tr></table></figure><p>范例:根据索引修改数据内容(修改文件 <a href="http://list.py">list.py</a>)</p><figure class="highlight python"><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">infos = [<span class="string">"C/C++"</span>,<span class="string">"Java"</span>,<span class="string">"Python"</span>]</span><br><span class="line">infos[<span class="number">1</span>] = <span class="string">"PHP"</span></span><br><span class="line"><span class="built_in">print</span>(infos[<span class="number">0</span>],end=<span class="string">"、"</span>)</span><br><span class="line"><span class="built_in">print</span>(infos[<span class="number">1</span>],end=<span class="string">"、"</span>)</span><br><span class="line"><span class="built_in">print</span>(infos[<span class="number">2</span>])</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">C/C++、PHP、Python</span><br></pre></td></tr></table></figure><p>范例:使用乘法(新建文件 <a href="http://multiply.py">multiply.py</a>)</p><figure class="highlight python"><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">infos = [<span class="string">"C/C++"</span>,<span class="string">"Java"</span>,<span class="string">"Python"</span>] * <span class="number">3</span></span><br><span class="line"><span class="built_in">print</span>(infos)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">['C/C++', 'Java', 'Python', 'C/C++', 'Java', 'Python', 'C/C++', 'Java', 'Python']</span><br></pre></td></tr></table></figure><p>范例:使用加法(新建文件 <a href="http://add.py">add.py</a>)</p><figure class="highlight python"><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">infos = [<span class="string">"C/C++"</span>,<span class="string">"Java"</span>,<span class="string">"Python"</span>] + [<span class="string">"PHP"</span>]</span><br><span class="line"><span class="built_in">print</span>(infos)</span><br></pre></td></tr></table></figure><p>打印结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">['C/C++', 'Java', 'Python', 'PHP']</span><br></pre></td></tr></table></figure><h4 id="数据分片">数据分片<a class="headerlink" href="#数据分片"></a></h4><p>列表的数据分片,即截取列表的一部分:</p><ul><li>指定截取范围:<code><列表>[<开始索引>:<结束索引>]</code>;</li><li>从指定索引一直截取到结尾:<code><列表>[<开始索引>:]</code>;</li><li>从开头一直截取到指定索引:<code><列表>[:<结束索引>]</code>;</li><li>设置截取步长:<code><列表>[<开始索引>:<结束索引>:<步长>]</code>。</li></ul><h3 id="元组">元组<a class="headerlink" href="#元组"></a></h3><h3 id="序列统计函数">序列统计函数<a class="headerlink" href="#序列统计函数"></a></h3><h2 id="函数">函数<a class="headerlink" href="#函数"></a></h2><h2 id="函数深入">函数深入<a class="headerlink" href="#函数深入"></a></h2><h3 id="lambda_表达式">lambda 表达式<a class="headerlink" href="#lambda_表达式"></a></h3><p>lambda 表达式即 lambda 函数,</p><h3 id="主函数">主函数<a class="headerlink" href="#主函数"></a></h3><h3 id="callable">callable()<a class="headerlink" href="#callable"></a></h3><p>callabl()</p><figure class="highlight plaintext"><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">print("input()是否可以调用:%s" % callable(input))</span><br><span class="line">def get_info</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> Python 从入门到实践 </category>
</categories>
<tags>
<tag> Windows </tag>
<tag> Python </tag>
<tag> Visual Studio Code </tag>
</tags>
</entry>
<entry>
<title>我的博客的诞生(三)</title>
<link href="/2020/01/24/My_HexoBlog_with_NexT_3/"/>
<url>/2020/01/24/My_HexoBlog_with_NexT_3/</url>
<content type="html"><![CDATA[<p>本文记录和讲解我的博客的使用。</p><span id="more"></span><h2 id="Markdown">Markdown<a class="headerlink" href="#Markdown"></a></h2><p>Markdown 是一种轻量级的专为写作而生的标记语言,其语法十分简单,常用的标记符号不超过十个。</p><h2 id="Typora">Typora<a class="headerlink" href="#Typora"></a></h2><p>Typora 是一个 Markdown 文件编辑器,最大的特色是命令式的实时预览,一旦熟悉了 Markdown 语法,写作体验极好。其全平台支持,可到<a href="https://typora.io/">官网</a>下载,但目前这款软件已开始收费。</p><h2 id="MarkText">MarkText<a class="headerlink" href="#MarkText"></a></h2><p>MarkText,绝对是 Typora 的最佳替代品,它开源免费,本人强烈推荐,请前往它的 GitHub 发布页面下载安装使用。</p><h2 id="书写博文">书写博文<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup><a class="headerlink" href="#书写博文"></a></h2><p>通过执行<code>hexo new post <自定义 md 文件名></code>,相应 Markdown 文件将在 _posts 下生成,我们可以使用 MarkText 打开该 Markdown 文件书写博文。</p><div class="note info flat"><p>以下动图为一开始使用 Typora 录制,只是便于对博文书写语法进行讲解,其同样适用于 MarkText。</p></div><h3 id="标题">标题<a class="headerlink" href="#标题"></a></h3><p>使用<code>#</code>可表示 1-6 级标题。一级标题对应一个 #,二级标题对应两个 # ,以此类推,如下图(注意 # 后面有一个空格):</p><p><img src="https://img.imql.life/illustrations/37eb93cc10af3f74217e67b51eafcee1.gif" alt="标题" title="标题"></p><h3 id="脚注">脚注<a class="headerlink" href="#脚注"></a></h3><p>不多说了,看图吧:</p><p><img src="https://img.imql.life/illustrations/a79d5008c2749bdb6d2bcb09f1c62866.gif" alt="脚注" title="脚注"></p><h3 id="有序列表">有序列表<a class="headerlink" href="#有序列表"></a></h3><p>使用<code><序号>.</code>(<code>.</code>后面有一个空格)可表示有序列表,若<code><序号>.</code>之后接了实际内容,则回车自动生成下一项,如没有实际内容,回车回到正文:</p><p><img src="https://img.imql.life/illustrations/64e04735a9e72be9db6f6ce588fc4186.gif" alt="有序列表" title="有序列表"></p><h3 id="无序列表">无序列表<a class="headerlink" href="#无序列表"></a></h3><p>使用<code>-</code>(<code>-</code>后面有空格)可表示无序列表,若<code>-</code>之后接了实际内容,则回车自动生成下一项,如没有实际内容,回车回到正文:</p><p><img src="https://img.imql.life/illustrations/5991da600c0ae90223cbffd4b33fe02c.gif" alt="无序列表" title="无序列表"></p><h3 id="任务列表">任务列表<a class="headerlink" href="#任务列表"></a></h3><p>使用<code>- [ ]</code>(<code>[ ]</code>后面有空格)可表示任务列表,若<code>- [ ]</code>之后接了实际内容,则回车自动生成下一项,如没有实际内容,回车回到正文:</p><p><img src="https://img.imql.life/illustrations/00906c96e536625f4fde1d00fe8aa103.gif" alt="任务列表" title="任务列表"></p><div class="note info flat"><p>以上三种列表之间可以相互嵌套,只需在敲子列表前敲四个空格即可。</p></div><h3 id="代码段">代码段<a class="headerlink" href="#代码段"></a></h3><p>用一对单个反引号把代码包起来即可:</p><p><img src="https://img.imql.life/illustrations/8ea44d3ecf13adf6c7eada7d07fcdc22.gif" alt="代码段" title="代码段"></p><h3 id="代码块">代码块<a class="headerlink" href="#代码块"></a></h3><p>先敲三个反引号再回车,就能生成一个空代码块,粘贴进代码就可以了,右下方可以指定语言,会有相应的高亮显示:</p><p><img src="https://img.imql.life/illustrations/2d196e2b65f28df4eec433fbd6a76350.gif" alt="代码块" title="代码块"></p><div class="note info flat"><p>其实以上表示代码块的语法是 Typora 对 Markdown 语法的简化,可使用<code>Ctrl</code>+<code>/</code>切换到源代码模式,可看到是一对三个反引号包起来即表示代码块。</p></div><h3 id="链接">链接<a class="headerlink" href="#链接"></a></h3><p>先用一对中括号包裹链接文本,再用一对小括号包裹地址:</p><p><img src="https://img.imql.life/illustrations/78b2548c699ffae5eecab28caf62b250.gif" alt="链接" title="链接"></p><h3 id="插入图片">插入图片<a class="headerlink" href="#插入图片"></a></h3><p>先敲一个<code>!</code>,再用一对中括号包裹图片描述,最后敲一对小括号就可以选择图片插入:</p><p><img src="https://img.imql.life/illustrations/b82d697b763ed58708b2e3eebf821663.gif" alt="插入图表" title="插入图表"></p><h2 id="博客构建仓库">博客构建仓库<a class="headerlink" href="#博客构建仓库"></a></h2><p>现在,虽然博文没写几篇,我已经遇到了这样两个问题:换了一台电脑怎么办?博客构建目录怎么备份?</p><p>直接使用 U 盘显然是非常原始愚蠢的办法,这时,我想到了最流行的分布式版本控制系统 Git 和全球最大的代码托管平台 GitHub。</p><h3 id="使用_Git_管理博客构建目录并托管到_GitHub">使用 Git 管理博客构建目录并托管到 GitHub<a class="headerlink" href="#使用_Git_管理博客构建目录并托管到_GitHub"></a></h3><p>进入 <a href="http://github.com/">Github 首页</a>,右上角的加号处创建仓库,仓库名自定义,如 blog。</p><p>进入<博客构建目录>,初始化一个 Git 项目:</p><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">git init</span><br></pre></td></tr></table></figure><p>将全部文件添加进暂存区:</p><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">git add .</span><br></pre></td></tr></table></figure><p>提交到本地版本库(第一次):</p><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">git commit -m <span class="string">":tada:"</span></span><br></pre></td></tr></table></figure><p>添加远程版本库(仓库)地址:</p><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">git remote add origin [email protected]:<自己的GitHub用户名>/blog.git</span><br></pre></td></tr></table></figure><p>推送到远程版本库(仓库):</p><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">git branch -M main</span><br><span class="line">git push -u origin main</span><br></pre></td></tr></table></figure><p>这时你可以看到 GitHub 上刚建的仓库中出现了博客构建目录下的一些文件,你仔细和本地比对后可能会有以下问题。</p><div class="note info flat"><p>少了一些文件夹,比如 node_modules、public 和 .deploy_git,这是怎么回事?</p></div><div class="note success flat"><p>其实这是正常的,这些文件在 .gitignore 中被指定,被 Git 忽略了,因为这些文件都是衍生文件,根本不重要,比如 node_modules 文件夹可以通过 npm install 生成。</p></div><div class="note info flat"><p>少了主题文件夹!难道这个也被 Git 忽略了?.gitignore 没指定啊。</p></div><div class="note success flat"><p>是的,主题文件夹也被忽略了,但是是由于我们当初是通过<code>git clone</code>下载的主题,其本身也是一个 Git 项目,拥有自己的仓库,这种情况推荐的做法是将该 Git 项目添加为子项目。</p></div><h3 id="将主题添加为子项目">将主题添加为子项目<a class="headerlink" href="#将主题添加为子项目"></a></h3><p>访问<a href="https://github.com/next-theme/hexo-theme-next/">主题仓库</a>,点击右上方的 Fork,创建一个自己的分支。</p><p>删除主题文件夹,执行以下命令将主题设置为子项目。</p><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">git submodule add -b master [email protected]:next-theme/hexo-theme-next.git themes/next</span><br></pre></td></tr></table></figure><p>提交到本地版本库:</p><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">git add .</span><br><span class="line">git commit -m <span class="string">"将主题添加为子项目"</span></span><br></pre></td></tr></table></figure><p>推送到远程版本库(仓库):</p><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">git push</span><br></pre></td></tr></table></figure><p>这时你可以看到 GitHub 上的仓库中主题文件夹出来了,点开后跳到自己的分支。</p><p>以上不仅实现了博客构建目录的备份,更将博客构建目录变成了一个 Git 项目。那么如何多端书写博文呢?</p><h3 id="多端书写">多端书写<a class="headerlink" href="#多端书写"></a></h3><p>我们换了一台新电脑后,需要五步进行多端书写:</p><ol><li>安装 Node.js,安装 hexo-cli;</li><li>安装和配置 Git,执行以下命令克隆博客构建仓库;</li></ol><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">git <span class="built_in">clone</span> --recursive [email protected]:<自己的GitHub用户名>/blog.git</span><br></pre></td></tr></table></figure><ol start="3"><li>安装依赖:</li></ol><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">npm install</span><br></pre></td></tr></table></figure><div class="note success flat"><p>这时进行本地预览(hexo s),你会发现你的博客原封不动的回来了。</p></div><ol start="4"><li>书写完博文后更新博客构建仓库:</li></ol><figure class="highlight diff"><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">git add .</span><br><span class="line">git commit -m ":memo:"</span><br><span class="line">git push</span><br></pre></td></tr></table></figure><ol start="5"><li>更新博客:<code>hexo g -d</code>。</li></ol><div class="note primary flat"><p>更新博客后,所有文章的更新时间都变成了最近的时间如果我们不自己在每篇文章的 front-matter(即文章的 MD 文件开头那部分)中设定 updated 的值,如果我们不能接受这一情况,则需要自己设定一下 updated 的值,格式同<code>"2023-08-12 11:15:15"</code>。</p></div><div class="note primary flat"><p>hexo-cli,只是 hexo 的命令行接口,它的作用是方便我们执行 hexo 的相关命令,我们只是在第一次初始化一个 hexo 博客时需要真正使用到它(<code>hexo init</code>),我们常用的<code>hexo clean</code>、<code>hexo g -d</code>其实都是来自于 hexo 这个 npm 包,而其是作为我们构建博客的一个依赖被安装的,所以,在一台新电脑上,我们完全不必再次安装 hexo-cli,而是直接在博客构建目录下调用 hexo,观察到 package.json 中定义了以下几个 NPM 命令,其实 hexo 官方已经给我们设定好了,即<code>npm run build</code>就是调用<code>hexo generate</code>,<code>npm run deploy</code>就是调用<code>hexo deploy</code>,其他同理,那么,在以上多端书写五个步骤中,就可以省略掉安装 hexo-cli 并将最后一步命令替换为<code>npm run build && npm run deploy</code>。</p><figure class="highlight json"><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><br><span class="line"><span class="attr">"scripts"</span><span class="punctuation">:</span> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"build"</span><span class="punctuation">:</span> <span class="string">"hexo generate"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"clean"</span><span class="punctuation">:</span> <span class="string">"hexo clean"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"deploy"</span><span class="punctuation">:</span> <span class="string">"hexo deploy"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"server"</span><span class="punctuation">:</span> <span class="string">"hexo server"</span></span><br><span class="line"> <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure></div><h2 id="持续集成">持续集成<a class="headerlink" href="#持续集成"></a></h2><p>虽然实现了多端书写,但是操作起来也挺麻烦的。换电脑要重新配置环境,书写完博文除了要部署博客,还要更新博客构建仓库,这时, GitHub Actions 就派上用场了。</p><div class="note info flat"><p>GitHub Actions 可以简单理解为可以让你在云端对自己的仓库进行一系列的命令,对于免费用户,每月有 2000 分钟的使用时间。</p></div><p>前往博客构建仓库,创建一个工作流文件(一个 yml 文件):</p><p><img src="https://img.imql.life/illustrations/ccefe1737c9aec06e15c0ca3bd6c8e9e.png" alt="image.png"></p><p>重命名此 yml 文件为 hexo-build.yml,复制粘贴以下内容:</p><div class="tabs" id="hexo-build"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#hexo-build-1">注释版</button></li><li class="tab"><button type="button" data-href="#hexo-build-2">清洁版</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="hexo-build-1"><figure class="highlight yaml"><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><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">name:</span> <span class="string">hexo-build</span></span><br><span class="line"><span class="comment"># 仓库main分支有推送时执行jobs下定义的任务</span></span><br><span class="line"><span class="attr">on:</span></span><br><span class="line"> <span class="attr">push:</span></span><br><span class="line"> <span class="attr">branches:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">main</span></span><br><span class="line"><span class="comment"># 设置时区为上海</span></span><br><span class="line"><span class="attr">env:</span></span><br><span class="line"> <span class="attr">TZ:</span> <span class="string">Asia/Shanghai</span></span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line"> <span class="comment"># 定义名为blog-build的任务</span></span><br><span class="line"> <span class="attr">blog-build:</span></span><br><span class="line"> <span class="comment"># 定义运行的操作系统</span></span><br><span class="line"> <span class="attr">runs-on:</span> <span class="string">ubuntu-latest</span></span><br><span class="line"> <span class="comment"># 定义步骤</span></span><br><span class="line"> <span class="attr">steps:</span></span><br><span class="line"> <span class="comment"># 签出仓库的默认分支,此处即为main,同时迁出子项目,此处即为主题仓库</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Checkout</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/checkout@v3</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">submodules:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># 安装v12.14.0的Node.js,同时进行全局缓存</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Install</span> <span class="string">Node.js</span> <span class="string">v12.14.0</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/setup-node@v3</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">node-version:</span> <span class="string">"12.14.0"</span></span><br><span class="line"> <span class="attr">cache:</span> <span class="string">"npm"</span></span><br><span class="line"> <span class="comment"># 缓存文件夹node_modules并生成唯一码</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Cache</span> <span class="string">dependencies</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/cache@v3</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">cache-dependencies</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">path:</span> <span class="string">node_modules</span></span><br><span class="line"> <span class="attr">key:</span> <span class="string">${{runner.OS}}-${{hashFiles('**/package-lock.json')}}</span></span><br><span class="line"> <span class="comment"># 如果唯一码比对不成功,重新安装依赖,成功则沿用缓存</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Install</span> <span class="string">dependencies</span></span><br><span class="line"> <span class="attr">if:</span> <span class="string">steps.cache-dependencies.outputs.cache-hit</span> <span class="type">!=</span> <span class="string">'true'</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">npm</span> <span class="string">ci</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Setup</span> <span class="string">private</span> <span class="string">rsa</span> <span class="string">key</span></span><br><span class="line"> <span class="attr">env:</span></span><br><span class="line"> <span class="attr">DEPLOY_KEY:</span> <span class="string">${{secrets.DEPLOY_KEY}}</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> mkdir -p ~/.ssh/</span></span><br><span class="line"><span class="string"> echo "$DEPLOY_KEY" > ~/.ssh/id_rsa </span></span><br><span class="line"><span class="string"> chmod 600 ~/.ssh/id_rsa</span></span><br><span class="line"><span class="string"> ssh-keyscan github.com >> ~/.ssh/known_hosts</span></span><br><span class="line"><span class="string"> ssh-keyscan gitee.com >> ~/.ssh/known_hosts</span></span><br><span class="line"><span class="string"></span> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Deploy</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> git config --global user.name "${{secrets.GIT_NAME}}"</span></span><br><span class="line"><span class="string"> git config --global user.email "${{secrets.GIT_EMAIL}}"</span></span><br><span class="line"><span class="string"> npm run build && npm run deploy</span></span><br></pre></td></tr></table></figure><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="hexo-build-2"><figure class="highlight yaml"><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></pre></td><td class="code"><pre><span class="line"><span class="attr">name:</span> <span class="string">hexo-build</span></span><br><span class="line"><span class="attr">on:</span></span><br><span class="line"> <span class="attr">push:</span></span><br><span class="line"> <span class="attr">branches:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">main</span></span><br><span class="line"><span class="attr">env:</span></span><br><span class="line"> <span class="attr">TZ:</span> <span class="string">Asia/Shanghai</span></span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line"> <span class="attr">blog-build:</span></span><br><span class="line"> <span class="attr">runs-on:</span> <span class="string">ubuntu-latest</span></span><br><span class="line"> <span class="attr">steps:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Checkout</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/checkout@v3</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">submodules:</span> <span class="literal">true</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Install</span> <span class="string">Node.js</span> <span class="string">v12.14.0</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/setup-node@v3</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">node-version:</span> <span class="string">"12.14.0"</span></span><br><span class="line"> <span class="attr">cache:</span> <span class="string">"npm"</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Cache</span> <span class="string">dependencies</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/cache@v3</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">cache-dependencies</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">path:</span> <span class="string">node_modules</span></span><br><span class="line"> <span class="attr">key:</span> <span class="string">${{runner.OS}}-${{hashFiles('**/package-lock.json')}}</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Install</span> <span class="string">dependencies</span></span><br><span class="line"> <span class="attr">if:</span> <span class="string">steps.cache-dependencies.outputs.cache-hit</span> <span class="type">!=</span> <span class="string">'true'</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">npm</span> <span class="string">ci</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Setup</span> <span class="string">private</span> <span class="string">rsa</span> <span class="string">key</span></span><br><span class="line"> <span class="attr">env:</span></span><br><span class="line"> <span class="attr">DEPLOY_KEY:</span> <span class="string">${{secrets.DEPLOY_KEY}}</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> mkdir -p ~/.ssh/</span></span><br><span class="line"><span class="string"> echo "$DEPLOY_KEY" > ~/.ssh/id_rsa </span></span><br><span class="line"><span class="string"> chmod 600 ~/.ssh/id_rsa</span></span><br><span class="line"><span class="string"> ssh-keyscan github.com >> ~/.ssh/known_hosts</span></span><br><span class="line"><span class="string"> ssh-keyscan gitee.com >> ~/.ssh/known_hosts</span></span><br><span class="line"><span class="string"></span> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Deploy</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> git config --global user.name "${{secrets.GIT_NAME}}"</span></span><br><span class="line"><span class="string"> git config --global user.email "${{secrets.GIT_EMAIL}}"</span></span><br><span class="line"><span class="string"> npm run build && npm run deploy</span></span><br></pre></td></tr></table></figure><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><p>先别着急提交以上内容,在这个工作流文件中,存在 <code>${{}}</code> 这种格式的东西,这是我们工作流需要使用到的变量,需要提前指定一下。</p><p>前往博客构建仓库(再开一个浏览器标签页),添加变量(会被加密):</p><p><img src="https://img.imql.life/illustrations/a719b00caa586a017f102c13f01b19ea.png" alt="image.png"></p><ul><li>指定 DEPLOY_KEY 的值,此值为我们电脑用户文件夹下 .ssh 下 id_rsa 的内容,即私钥,该私钥在<a href="https://www.imql.life/2020/01/24/What_is_Git/#%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE_Git">安装和配置 Git</a> 时生成。</li><li>指定 GIT_NAME 的值,即自己的 GitHub 用户名。</li><li>指定 GIT_EMAIL 的值,即自己的 GitHub 邮箱。</li></ul><p>指定好后就可以提交 hexo-build.yml,之后会看到工作流进行中,最终完成。</p><p>这样以后对于任何一台新电脑,只需要三步即可多端书写:</p><ol><li>安装和配置 Git,执行以下命令克隆博客构建仓库;</li></ol><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">git <span class="built_in">clone</span> --recursive [email protected]:<自己的GitHub用户名>/blog.git</span><br></pre></td></tr></table></figure><ol start="2"><li>安装依赖:</li></ol><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">npm install</span><br></pre></td></tr></table></figure><ol start="3"><li>书写完博文后更新博客构建仓库:</li></ol><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">git add .</span><br><span class="line">git commit -m <span class="string">":memo:"</span></span><br><span class="line">git push</span><br></pre></td></tr></table></figure><h3 id="【优化】增量生成">【优化】增量生成<a class="headerlink" href="#【优化】增量生成"></a></h3><p>观察 GitHub Actions 工作流日志,每次执行<code>npm run build</code>都是生成全量的博客源文件,这看起来也没什么问题,但是要是以后文章数量多起来,这个执行起来可老花时间了。</p><p>对于<code>npm run build</code>这个命令,也就是实际执行的<code>hexo generate</code>,其默认就是会增量生成博客源文件,前提是当前目录下存在目录 public(也就是旧版的全量的博客源文件)和缓存文件 db.json。于是,优化工作流文件 hexo-build.yml 如下,旧版的全量的博客源文件从博客源文件版本库下载即可,缓存文件 db.json 第一次生成之后上传为构件以供下一次工作流下载。</p><div class="tabs" id="hexo-build"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#hexo-build-1">注释版</button></li><li class="tab"><button type="button" data-href="#hexo-build-2">清洁版</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="hexo-build-1"><figure class="highlight diff"><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><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br></pre></td><td class="code"><pre><span class="line">name: hexo-build</span><br><span class="line"># 仓库main分支有推送时执行jobs下定义的任务</span><br><span class="line">on:</span><br><span class="line"> push:</span><br><span class="line"> branches:</span><br><span class="line"> - main</span><br><span class="line"># 设置时区为上海</span><br><span class="line">env:</span><br><span class="line"> TZ: Asia/Shanghai</span><br><span class="line">jobs:</span><br><span class="line"> # 定义名为blog-build的任务</span><br><span class="line"> blog-build:</span><br><span class="line"> # 定义运行的操作系统</span><br><span class="line"> runs-on: ubuntu-latest</span><br><span class="line"> # 定义步骤</span><br><span class="line"> steps:</span><br><span class="line"> # 签出仓库的默认分支,此处即为main,同时迁出子项目,此处即为主题仓库</span><br><span class="line"> - name: Checkout</span><br><span class="line"> uses: actions/checkout@v3</span><br><span class="line"> with:</span><br><span class="line"> submodules: true</span><br><span class="line"> # 安装v12.14.0的Node.js,同时进行全局缓存</span><br><span class="line"> - name: Install Node.js v12.14.0</span><br><span class="line"> uses: actions/setup-node@v3</span><br><span class="line"> with:</span><br><span class="line"> node-version: "12.14.0"</span><br><span class="line"> cache: "npm"</span><br><span class="line"> # 缓存文件夹node_modules并生成唯一码</span><br><span class="line"> - name: Cache dependencies</span><br><span class="line"> uses: actions/cache@v3</span><br><span class="line"> id: cache-dependencies</span><br><span class="line"> with:</span><br><span class="line"> path: node_modules</span><br><span class="line"> key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}</span><br><span class="line"> # 如果唯一码比对不成功,重新安装依赖,成功则沿用缓存</span><br><span class="line"> - name: Install dependencies</span><br><span class="line"> if: steps.cache-dependencies.outputs.cache-hit != 'true'</span><br><span class="line"> run: npm ci</span><br><span class="line"> - name: Setup private rsa key</span><br><span class="line"> env:</span><br><span class="line"> DEPLOY_KEY: ${{secrets.DEPLOY_KEY}}</span><br><span class="line"> run: |</span><br><span class="line"> mkdir -p ~/.ssh/</span><br><span class="line"> echo "$DEPLOY_KEY" > ~/.ssh/id_rsa</span><br><span class="line"> chmod 600 ~/.ssh/id_rsa</span><br><span class="line"> ssh-keyscan github.com >> ~/.ssh/known_hosts</span><br><span class="line"> ssh-keyscan gitee.com >> ~/.ssh/known_hosts</span><br><span class="line"><span class="addition">+ - name: Download PUBLIC</span></span><br><span class="line"><span class="addition">+ run: |</span></span><br><span class="line"><span class="addition">+ # 下载自己的GitHub用户仓库,下载的文件为master.zip</span></span><br><span class="line"><span class="addition">+ curl -LsO https://github.com/ql-isaac/<自己的Github用户名>.github.io/archive/refs/heads/master.zip</span></span><br><span class="line"><span class="addition">+ # 解压</span></span><br><span class="line"><span class="addition">+ unzip master.zip -d .</span></span><br><span class="line"><span class="addition">+ # 重命名为public</span></span><br><span class="line"><span class="addition">+ mv <自己的Github用户名>.github.io-master/ public</span></span><br><span class="line"><span class="addition">+ - name: Download DB</span></span><br><span class="line"><span class="addition">+ uses: dawidd6/action-download-artifact@v2</span></span><br><span class="line"><span class="addition">+ continue-on-error: true # 构件最多只能保存90天,90天过后这一步会报错,设置成报错继续执行</span></span><br><span class="line"><span class="addition">+ with:</span></span><br><span class="line"><span class="addition">+ github_token: ${{secrets.GITHUB_TOKEN}}</span></span><br><span class="line"><span class="addition">+ name: "DB"</span></span><br><span class="line"> - name: Generate and deploy</span><br><span class="line"> run: |</span><br><span class="line"> git config --global user.name "${{secrets.GIT_NAME}}"</span><br><span class="line"> git config --global user.email "${{secrets.GIT_EMAIL}}"</span><br><span class="line"> npm run build && npm run deploy</span><br><span class="line"><span class="addition">+ - name: Upload DB for next workflow to download</span></span><br><span class="line"><span class="addition">+ uses: actions/upload-artifact@v3</span></span><br><span class="line"><span class="addition">+ with:</span></span><br><span class="line"><span class="addition">+ name: "DB"</span></span><br><span class="line"><span class="addition">+ path: db.json</span></span><br><span class="line"><span class="addition">+ retention-days: 90</span></span><br></pre></td></tr></table></figure><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="hexo-build-2"><figure class="highlight diff"><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><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line">name: hexo-build</span><br><span class="line">on:</span><br><span class="line"> push:</span><br><span class="line"> branches:</span><br><span class="line"> - main</span><br><span class="line">env:</span><br><span class="line"> TZ: Asia/Shanghai</span><br><span class="line">jobs:</span><br><span class="line"> blog-build:</span><br><span class="line"> runs-on: ubuntu-latest</span><br><span class="line"> steps:</span><br><span class="line"> - name: Checkout</span><br><span class="line"> uses: actions/checkout@v3</span><br><span class="line"> with:</span><br><span class="line"> submodules: true</span><br><span class="line"> - name: Install Node.js v12.14.0</span><br><span class="line"> uses: actions/setup-node@v3</span><br><span class="line"> with:</span><br><span class="line"> node-version: "12.14.0"</span><br><span class="line"> cache: "npm"</span><br><span class="line"> - name: Cache dependencies</span><br><span class="line"> uses: actions/cache@v3</span><br><span class="line"> id: cache-dependencies</span><br><span class="line"> with:</span><br><span class="line"> path: node_modules</span><br><span class="line"> key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}</span><br><span class="line"> - name: Install dependencies</span><br><span class="line"> if: steps.cache-dependencies.outputs.cache-hit != 'true'</span><br><span class="line"> run: npm ci</span><br><span class="line"> - name: Setup private rsa key</span><br><span class="line"> env:</span><br><span class="line"> DEPLOY_KEY: ${{secrets.DEPLOY_KEY}}</span><br><span class="line"> run: |</span><br><span class="line"> mkdir -p ~/.ssh/</span><br><span class="line"> echo "$DEPLOY_KEY" > ~/.ssh/id_rsa</span><br><span class="line"> chmod 600 ~/.ssh/id_rsa</span><br><span class="line"> ssh-keyscan github.com >> ~/.ssh/known_hosts</span><br><span class="line"> ssh-keyscan gitee.com >> ~/.ssh/known_hosts</span><br><span class="line"><span class="addition">+ - name: Download PUBLIC</span></span><br><span class="line"><span class="addition">+ run: |</span></span><br><span class="line"><span class="addition">+ curl -LsO https://github.com/ql-isaac/<自己的Github用户名>.github.io/archive/refs/heads/master.zip</span></span><br><span class="line"><span class="addition">+ unzip master.zip -d .</span></span><br><span class="line"><span class="addition">+ mv <自己的Github用户名>.github.io-master/ public</span></span><br><span class="line"><span class="addition">+ - name: Download DB</span></span><br><span class="line"><span class="addition">+ uses: dawidd6/action-download-artifact@v2</span></span><br><span class="line"><span class="addition">+ continue-on-error: true</span></span><br><span class="line"><span class="addition">+ with:</span></span><br><span class="line"><span class="addition">+ github_token: ${{secrets.GITHUB_TOKEN}}</span></span><br><span class="line"><span class="addition">+ name: "DB"</span></span><br><span class="line"> - name: Generate and deploy</span><br><span class="line"> run: |</span><br><span class="line"> git config --global user.name "${{secrets.GIT_NAME}}"</span><br><span class="line"> git config --global user.email "${{secrets.GIT_EMAIL}}"</span><br><span class="line"> npm run build && npm run deploy</span><br><span class="line"><span class="addition">+ - name: Upload DB for next workflow to download</span></span><br><span class="line"><span class="addition">+ uses: actions/upload-artifact@v3</span></span><br><span class="line"><span class="addition">+ with:</span></span><br><span class="line"><span class="addition">+ name: "DB"</span></span><br><span class="line"><span class="addition">+ path: db.json</span></span><br><span class="line"><span class="addition">+ retention-days: 90</span></span><br></pre></td></tr></table></figure><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h3 id="【优化】增量部署">【优化】增量部署<a class="headerlink" href="#【优化】增量部署"></a></h3><p>观察我们的 GitHub 用户仓库,也就是我们的博客源文件版本库,无论我们更新多少次博客,提交历史总是两条,这个是由于使用的<code>npm run deploy</code>,也就是实际执行的<code>hexo deploy</code>,其会在当前目录下寻找目录.deploy_git,如果没有就自己创建一个,将其初始化为一个版本库并将目录 public 里的文件复制进去进行提交。</p><p>如果当前目录有.deploy_git,也就是有旧版的博客源文件版本库,<code>hexo deploy</code>同样会将目录 public 里的文件复制进.deploy_git 中,这时博客源文件会发生合并,Git 会发现哪些文件发生了变化且只会对这些文件进行提交。于是优化工作流文件 hexo-build.yml 如下。</p><div class="tabs" id="hexo-build"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#hexo-build-1">注释版</button></li><li class="tab"><button type="button" data-href="#hexo-build-2">清洁版</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="hexo-build-1"><figure class="highlight diff"><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><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br></pre></td><td class="code"><pre><span class="line">name: hexo-build</span><br><span class="line"># 仓库main分支有推送时执行jobs下定义的任务</span><br><span class="line">on:</span><br><span class="line"> push:</span><br><span class="line"> branches:</span><br><span class="line"> - main</span><br><span class="line"># 设置时区为上海</span><br><span class="line">env:</span><br><span class="line"> TZ: Asia/Shanghai</span><br><span class="line">jobs:</span><br><span class="line"> # 定义名为blog-build的任务</span><br><span class="line"> blog-build:</span><br><span class="line"> # 定义运行的操作系统</span><br><span class="line"> runs-on: ubuntu-latest</span><br><span class="line"> # 定义步骤</span><br><span class="line"> steps:</span><br><span class="line"> # 签出仓库的默认分支,此处即为main,同时迁出子项目,此处即为主题仓库</span><br><span class="line"> - name: Checkout</span><br><span class="line"> uses: actions/checkout@v3</span><br><span class="line"> with:</span><br><span class="line"> submodules: true</span><br><span class="line"> # 安装v12.14.0的Node.js,同时进行全局缓存</span><br><span class="line"> - name: Install Node.js v12.14.0</span><br><span class="line"> uses: actions/setup-node@v3</span><br><span class="line"> with:</span><br><span class="line"> node-version: "12.14.0"</span><br><span class="line"> cache: "npm"</span><br><span class="line"> # 缓存文件夹node_modules并生成唯一码</span><br><span class="line"> - name: Cache dependencies</span><br><span class="line"> uses: actions/cache@v3</span><br><span class="line"> id: cache-dependencies</span><br><span class="line"> with:</span><br><span class="line"> path: node_modules</span><br><span class="line"> key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}</span><br><span class="line"> # 如果唯一码比对不成功,重新安装依赖,成功则沿用缓存</span><br><span class="line"> - name: Install dependencies</span><br><span class="line"> if: steps.cache-dependencies.outputs.cache-hit != 'true'</span><br><span class="line"> run: npm ci</span><br><span class="line"> - name: Setup private rsa key</span><br><span class="line"> env:</span><br><span class="line"> DEPLOY_KEY: ${{secrets.DEPLOY_KEY}}</span><br><span class="line"> run: |</span><br><span class="line"> mkdir -p ~/.ssh/</span><br><span class="line"> echo "$DEPLOY_KEY" > ~/.ssh/id_rsa</span><br><span class="line"> chmod 600 ~/.ssh/id_rsa</span><br><span class="line"> ssh-keyscan github.com >> ~/.ssh/known_hosts</span><br><span class="line"> ssh-keyscan gitee.com >> ~/.ssh/known_hosts</span><br><span class="line"><span class="deletion">- - name: Download PUBLIC</span></span><br><span class="line"><span class="addition">+ - name: Download and clone PUBLIC</span></span><br><span class="line"> run: |</span><br><span class="line"> # 下载自己的GitHub用户仓库,下载的文件为master.zip</span><br><span class="line"> curl -LsO https://github.com/ql-isaac/<自己的Github用户名>.github.io/archive/refs/heads/master.zip</span><br><span class="line"> # 解压</span><br><span class="line"> unzip master.zip -d .</span><br><span class="line"> # 重命名为public</span><br><span class="line"> mv <自己的Github用户名>.github.io-master/ public</span><br><span class="line"><span class="addition">+ # 克隆自己的GitHub用户仓库,重命令为.deploy_git</span></span><br><span class="line"><span class="addition">+ git clone [email protected]:ql-isaac/<自己的Github用户名>.github.io.git .deploy_git</span></span><br><span class="line"> - name: Download DB</span><br><span class="line"> uses: dawidd6/action-download-artifact@v2</span><br><span class="line"> continue-on-error: true # 构件最多只能保存90天,90天过后这一步会报错,设置成报错继续执行</span><br><span class="line"> with:</span><br><span class="line"> github_token: ${{secrets.GITHUB_TOKEN}}</span><br><span class="line"> name: "DB"</span><br><span class="line"> - name: Generate and deploy</span><br><span class="line"> run: |</span><br><span class="line"> git config --global user.name "${{secrets.GIT_NAME}}"</span><br><span class="line"> git config --global user.email "${{secrets.GIT_EMAIL}}"</span><br><span class="line"> npm run build && npm run deploy</span><br><span class="line"> - name: Upload DB for next workflow to download</span><br><span class="line"> uses: actions/upload-artifact@v3</span><br><span class="line"> with:</span><br><span class="line"> name: "DB"</span><br><span class="line"> path: db.json</span><br><span class="line"> retention-days: 90</span><br></pre></td></tr></table></figure><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="hexo-build-2"><figure class="highlight diff"><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><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line">name: hexo-build</span><br><span class="line">on:</span><br><span class="line"> push:</span><br><span class="line"> branches:</span><br><span class="line"> - main</span><br><span class="line">env:</span><br><span class="line"> TZ: Asia/Shanghai</span><br><span class="line">jobs:</span><br><span class="line"> blog-build:</span><br><span class="line"> runs-on: ubuntu-latest</span><br><span class="line"> steps:</span><br><span class="line"> - name: Checkout</span><br><span class="line"> uses: actions/checkout@v3</span><br><span class="line"> with:</span><br><span class="line"> submodules: true</span><br><span class="line"> - name: Install Node.js v12.14.0</span><br><span class="line"> uses: actions/setup-node@v3</span><br><span class="line"> with:</span><br><span class="line"> node-version: "12.14.0"</span><br><span class="line"> cache: "npm"</span><br><span class="line"> - name: Cache dependencies</span><br><span class="line"> uses: actions/cache@v3</span><br><span class="line"> id: cache-dependencies</span><br><span class="line"> with:</span><br><span class="line"> path: node_modules</span><br><span class="line"> key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}</span><br><span class="line"> - name: Install dependencies</span><br><span class="line"> if: steps.cache-dependencies.outputs.cache-hit != 'true'</span><br><span class="line"> run: npm ci</span><br><span class="line"> - name: Setup private rsa key</span><br><span class="line"> env:</span><br><span class="line"> DEPLOY_KEY: ${{secrets.DEPLOY_KEY}}</span><br><span class="line"> run: |</span><br><span class="line"> mkdir -p ~/.ssh/</span><br><span class="line"> echo "$DEPLOY_KEY" > ~/.ssh/id_rsa</span><br><span class="line"> chmod 600 ~/.ssh/id_rsa</span><br><span class="line"> ssh-keyscan github.com >> ~/.ssh/known_hosts</span><br><span class="line"> ssh-keyscan gitee.com >> ~/.ssh/known_hosts</span><br><span class="line"><span class="deletion">- - name: Download PUBLIC</span></span><br><span class="line"><span class="addition">+ - name: Download and clone PUBLIC</span></span><br><span class="line"> run: |</span><br><span class="line"> curl -LsO https://github.com/ql-isaac/<自己的Github用户名>.github.io/archive/refs/heads/master.zip</span><br><span class="line"> unzip master.zip -d .</span><br><span class="line"> mv <自己的Github用户名>.github.io-master/ public</span><br><span class="line"><span class="addition">+ git clone [email protected]:ql-isaac/<自己的Github用户名>.github.io.git .deploy_git</span></span><br><span class="line"> - name: Download DB</span><br><span class="line"> uses: dawidd6/action-download-artifact@v2</span><br><span class="line"> continue-on-error: true</span><br><span class="line"> with:</span><br><span class="line"> github_token: ${{secrets.GITHUB_TOKEN}}</span><br><span class="line"> name: "DB"</span><br><span class="line"> - name: Generate and deploy</span><br><span class="line"> run: |</span><br><span class="line"> git config --global user.name "${{secrets.GIT_NAME}}"</span><br><span class="line"> git config --global user.email "${{secrets.GIT_EMAIL}}"</span><br><span class="line"> npm run build && npm run deploy</span><br><span class="line"> - name: Upload DB for next workflow to download</span><br><span class="line"> uses: actions/upload-artifact@v3</span><br><span class="line"> with:</span><br><span class="line"> name: "DB"</span><br><span class="line"> path: db.json</span><br><span class="line"> retention-days: 90</span><br></pre></td></tr></table></figure><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h2 id="云端开发">云端开发<a class="headerlink" href="#云端开发"></a></h2><p>现在,终于不用担心换电脑的问题了,终于可以好好写博文了,但是现实情况是博文还是没写几篇,反而深陷各种主题尝试、调试和魔改无法自拔,往往是这里还想改一下,但是没电脑在身边,只有平板或者手机。GitHub 真是懂我们的心思,它带着 Codespaces 来了。</p><p>在博客构建仓库创建一个 Codespace:</p><p><img src="https://img.imql.life/illustrations/0103766d08ff60fa0515816fc27575a9.png" alt="创建一个 Codespace" title="创建一个 Codespace"></p><p>默认使用的是一个多用镜像,拥有 Python、Node.js、Docker 等多个开发环境,我们可以自定义一个开发环境:</p><ol><li>访问 Visual Studio Code 命令面板(Shift+Command+P / Ctrl+Shift+P),输入“add dev”。单击“Codespaces: Add Dev Container Configuration Files…”;</li><li>单击“Create a new configuration…”;</li><li>单击“Show All Definitions…”;</li><li>输入“node”,单击“Basic Node.js”;</li></ol><p><img src="https://img.imql.life/illustrations/dfd0be81974b5a5c57653b9ba3abb595.png" alt="image.png"></p><ol start="5"><li>单击“18-bullseye”;</li><li>确定。</li></ol><p>修改生成的 Dockerfile,设定时区、安装 Vim:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">FROM library/node:18-bullseye</span><br><span class="line"><span class="addition">+</span></span><br><span class="line"><span class="addition">+ENV TZ="Asia/Shanghai"</span></span><br><span class="line"><span class="addition">+</span></span><br><span class="line">ARG DEBIAN_FRONTEND=noninteractive</span><br><span class="line">RUN apt update \</span><br><span class="line"><span class="deletion">- && apt install -y --no-install-recommends sudo \</span></span><br><span class="line"><span class="addition">+ && apt install -y --no-install-recommends sudo vim \</span></span><br><span class="line"> && apt autoremove -y \</span><br><span class="line"> && rm -rf /var/lib/apt/lists/* \</span><br><span class="line"> && echo "node ALL=(ALL) NOPASSWD: ALL" >/etc/sudoers.d/node \</span><br><span class="line"> && chmod 0440 /etc/sudoers.d/node</span><br></pre></td></tr></table></figure><p>修改生成的 devcontainer.json,更改开发环境的 name 为 Hexo,定义生命周期脚本<sup class="footnote-ref"><a href="#fn2" id="fnref2">[2]</a></sup>:</p><figure class="highlight diff"><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">{</span><br><span class="line"><span class="deletion">- "name": "Basic Node.js",</span></span><br><span class="line"><span class="addition">+ "name": "Hexo",</span></span><br><span class="line"> "build": { "dockerfile": "Dockerfile" },</span><br><span class="line"><span class="deletion">- "remoteUser": "node"</span></span><br><span class="line"><span class="addition">+ "remoteUser": "node",</span></span><br><span class="line"><span class="addition">+ "postCreateCommand": "mkdir -p ~/.ssh/ && echo \"$DEPLOY_KEY\" > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa && ssh-keyscan github.com >> ~/.ssh/known_hosts && sudo npm install -g hexo-cli && cd ${containerWorkspaceFolder} && rm -rf node_modules && npm ci",</span></span><br><span class="line"><span class="addition">+ "postStartCommand": "hexo clean && hexo generate"</span></span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>访问 Visual Studio Code 命令面板(Shift+Command+P / Ctrl+Shift+P),输入“rebuild”。单击“Codespaces: Rebuild Container”,rebuild。</p><p>这样,一个适合 Hexo 的开发环境就配置好了,可自行阅读<a href="https://docs.github.com/en/codespaces">官方文档</a>进行自定义。</p><p>最后将更改提交并推送:</p><figure class="highlight diff"><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">git add .</span><br><span class="line">git commit -m ":construction_worker: 使用Codespaces"</span><br><span class="line">git push</span><br></pre></td></tr></table></figure><hr class="footnotes-sep"><section class="footnotes"><ol class="footnotes-list"><li id="fn1" class="footnote-item"><p><a href="https://www.runoob.com/markdown/md-tutorial.html">菜鸟教程</a> <a href="#fnref1" class="footnote-backref">↩︎</a></p></li><li id="fn2" class="footnote-item"><p><a href="https://containers.dev/implementors/json_reference/#lifecycle-scripts">生命周期脚本</a> <a href="#fnref2" class="footnote-backref">↩︎</a></p></li></ol></section>]]></content>
<categories>
<category> 我的博客 </category>
</categories>
<tags>
<tag> Git </tag>
<tag> MarkText </tag>
</tags>
</entry>
<entry>
<title>我的博客的诞生(二)</title>
<link href="/2020/01/24/My_HexoBlog_with_NexT_2/"/>
<url>/2020/01/24/My_HexoBlog_with_NexT_2/</url>
<content type="html"><![CDATA[<p>本文记录和讲解一下<a href="https://blog.imql.life">我的博客</a>是如何进行个性化设置和配置的,可供参考。</p><span id="more"></span><div class="note primary flat"><p>本文对于文件(代码)变动的描述方式为 <code>-</code> 指删掉该行,<code>+</code> 指增加改行(如果你是直接复制此行,请注意删掉 <code>+</code> 和上下文对齐),<code>...</code> 表示省略上下文。另外,本文对于文件(代码)变动的描述只针对当时的文件(代码)版本,请根据实际情况决定对自己的相应文件(代码)进行变动。</p></div><h2 id="个性化设置和配置前的提示">个性化设置和配置前的提示<a class="headerlink" href="#个性化设置和配置前的提示"></a></h2><p>个性化设置和配置了一处自己的博客,可以通过本地部署的方式(<code>hexo s</code>)查看相应效果,甚至可以直接修改一处,刷新一下查看效果,等都设置和配置完毕了再部署到 Github Pages 等平台(<code>hexo g -d</code>)。</p><h2 id="Hexo_的个性化设置和配置-2">Hexo 的个性化设置和配置<a class="headerlink" href="#Hexo_的个性化设置和配置-2"></a></h2><h3 id="NexT_主题的下载和设置">NexT 主题的下载和设置<a class="headerlink" href="#NexT_主题的下载和设置"></a></h3><p>默认的 landscape 主题并不好看,在网上搜索了一下,发现 NexT 主题是最受欢迎的。</p><p>在<博客构建目录>下进入终端,输入如下命令,等待 NexT 下载到当前文件夹下 themes 下 next 下。</p><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">git <span class="built_in">clone</span> https://github.com/next-theme/hexo-theme-next themes/next</span><br></pre></td></tr></table></figure><p>下载完成后,编辑 Hexo 的配置文件(_config.yml):</p><figure class="highlight diff"><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><br><span class="line"># Extensions</span><br><span class="line">## Plugins: https://hexo.io/plugins/</span><br><span class="line">## Themes: https://hexo.io/themes/</span><br><span class="line"><span class="deletion">-theme: landscape</span></span><br><span class="line"><span class="addition">+theme: next</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><div class="note info flat"><p>原来文件夹 themes 下的 landscape 就可以删掉了,如果它还在的话。如果你是 2020 年 12 月 11 日之后开启个人博客之旅的话,默认的 landscape 主题是通过 npm 安装的,请行以下命令卸载掉它并手动删除其配置文件 _config.landscape.yml ,当然你想保留也行,毕竟美化的尽头是默认(bushi)。</p><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">npm uninstall hexo-theme-landscape</span><br></pre></td></tr></table></figure></div><h3 id="配置博客基本信息-2">配置博客基本信息<a class="headerlink" href="#配置博客基本信息-2"></a></h3><p>编辑 Hexo 的配置文件,个性化配置自己的站点信息:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line"># Site</span><br><span class="line"><span class="deletion">-title: Hexo</span></span><br><span class="line"><span class="deletion">-subtitle: ''</span></span><br><span class="line"><span class="deletion">-description: ''</span></span><br><span class="line"><span class="deletion">-keywords:</span></span><br><span class="line"><span class="deletion">-author: John Doe</span></span><br><span class="line"><span class="deletion">-language: en</span></span><br><span class="line">timezone:</span><br><span class="line">...</span><br></pre></td></tr></table></figure><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line"># Site</span><br><span class="line"><span class="addition">+title: ql's blog</span></span><br><span class="line"><span class="addition">+subtitle: It's a beautiful day!</span></span><br><span class="line"><span class="addition">+description: 一尘不染不是不再有尘埃,而是尘埃让它飞扬,我自做我的阳光。</span></span><br><span class="line"><span class="addition">+keywords: 学习与生活</span></span><br><span class="line"><span class="addition">+author: ql</span></span><br><span class="line"><span class="addition">+language: zh-CN</span></span><br><span class="line">timezone:</span><br><span class="line">...</span><br></pre></td></tr></table></figure><p>效果图:</p><p><img src="https://img.imql.life/illustrations/bf6017a5f60fe0b2939098d6b874de8d.png" alt="配置博客站点基本信息.png"></p><h3 id="配置永久链接-2">配置永久链接<a class="headerlink" href="#配置永久链接-2"></a></h3><p>默认的永久链接是年月日加文章标题,而我们文章的标题一般都是中文的,但是永久链接中的标题并不是中文的,而是转码过的,这样非常不利于链接的分享。</p><p>我的解决办法是配置永久链接为年月日加文章标题的英文翻译,编辑 Hexo 的配置文件:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line"># URL</span><br><span class="line">## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'</span><br><span class="line"><span class="deletion">-url: http://yoursite.com</span></span><br><span class="line"><span class="addition">+url: https://blog.xxx.xx</span></span><br><span class="line">root: /</span><br><span class="line"><span class="deletion">-permalink: :year/:month/:day/:title/</span></span><br><span class="line"><span class="addition">+permalink: :year/:month/:day/:trans/</span></span><br><span class="line">permalink_defaults:</span><br><span class="line">pretty_urls:</span><br><span class="line"> trailing_index: true # Set to false to remove trailing 'index.html' from permalinks</span><br><span class="line"> trailing_html: true # Set to false to remove trailing '.html' from permalinks</span><br><span class="line">...</span><br></pre></td></tr></table></figure><p>之后记得在每篇博文的开头部分加上 trans 和文章标题的英文翻译:</p><p><img src="https://img.imql.life/illustrations/e8fb3714d2efa5e4cd18e54ae35e5caa.png" alt="trans.png"></p><h3 id="更换默认的_Markdown_渲染器-2">更换默认的 Markdown 渲染器<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup><a class="headerlink" href="#更换默认的_Markdown_渲染器-2"></a></h3><p>默认的 Markdown 渲染器不支持脚注,于是我们执行以下命令换一个渲染器。</p><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">npm uninstall --save hexo-renderer-marked</span><br><span class="line">npm install --save hexo-renderer-markdown-it</span><br></pre></td></tr></table></figure><p>编辑 Hexo 的配置文件,追加以下内容。</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line"><span class="addition">+# Markdown-it config</span></span><br><span class="line"><span class="addition">+## Docs: https://github.com/celsomiranda/hexo-renderer-markdown-it/wiki</span></span><br><span class="line"><span class="addition">+markdown:</span></span><br><span class="line"><span class="addition">+ # 渲染设置</span></span><br><span class="line"><span class="addition">+ render:</span></span><br><span class="line"><span class="addition">+ # 置为true时,html内容保持不变;置为false时,html内容将被转义成普通字符串</span></span><br><span class="line"><span class="addition">+ html: true</span></span><br><span class="line"><span class="addition">+ # 是否生成与XHTML完全兼容的标签(不懂是什么意思)</span></span><br><span class="line"><span class="addition">+ xhtmlOut: false</span></span><br><span class="line"><span class="addition">+ # # 置为true时,每个换行符都被渲染成一个<br>(即Hexo的默认表现);置为false时,每个换行符都被忽略,但两个换行符即空行可正常创建段落(GFM的默认表现)</span></span><br><span class="line"><span class="addition">+ breaks: false</span></span><br><span class="line"><span class="addition">+ # 是否自动识别链接并把它渲染成链接</span></span><br><span class="line"><span class="addition">+ linkify: true</span></span><br><span class="line"><span class="addition">+ # 是否自动识别印刷格式(例如(c)渲染为©)</span></span><br><span class="line"><span class="addition">+ typographer: true</span></span><br><span class="line"><span class="addition">+ quotes: '“”‘’'</span></span><br><span class="line"><span class="addition">+ # 设置所需插件</span></span><br><span class="line"><span class="addition">+ plugins:</span></span><br><span class="line"><span class="addition">+ - markdown-it-footnote</span></span><br></pre></td></tr></table></figure><h2 id="NexT_的个性化设置与配置">NexT 的个性化设置与配置<a class="headerlink" href="#NexT_的个性化设置与配置"></a></h2><p>创建 NexT 的配置文件:</p><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">cp</span> themes/next/_config.yml _config.next.yml</span><br></pre></td></tr></table></figure><div class="note info flat"><p>自 Hexo v5 开始,可以将主题的配置文件复制到博客构建目录下并重命名为 _config.<主题名字>.yml,创建一个新的配置文件,这样以后通过<code>git pull</code>更新主题时就不会发生冲突。</p></div><h3 id="配置站点图标-2">配置站点图标<a class="headerlink" href="#配置站点图标-2"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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><br><span class="line">favicon:</span><br><span class="line"><span class="deletion">- small: /images/favicon-16x16-next.png</span></span><br><span class="line"><span class="deletion">- medium: /images/favicon-32x32-next.png</span></span><br><span class="line"><span class="deletion">- apple_touch_icon: /images/apple-touch-icon-next.png</span></span><br><span class="line"><span class="deletion">- safari_pinned_tab: /images/logo.svg</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><figure class="highlight diff"><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><br><span class="line">favicon:</span><br><span class="line"><span class="addition">+ small: <自己图床的地址或者本地地址></span></span><br><span class="line"><span class="addition">+ medium: <自己图床的地址或者本地地址></span></span><br><span class="line"><span class="addition">+ apple_touch_icon: <自己图床的地址或者本地地址></span></span><br><span class="line"><span class="addition">+ safari_pinned_tab: <自己图床的地址或者本地地址></span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><p>效果图:</p><p><img src="https://img.imql.life/illustrations/bff791d8f3b87e358f2d2c0183e5e290.png" alt="配置站点图标.png"></p><h3 id="在页脚设定建站年份">在页脚设定建站年份<a class="headerlink" href="#在页脚设定建站年份"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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">...</span><br><span class="line">footer:</span><br><span class="line"> # Specify the date when the site was setup. If not defined, current year will be used.</span><br><span class="line"><span class="deletion">- #since: 2015</span></span><br><span class="line"><span class="addition">+ since: 2020</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><p>效果展示(从设定的起始年份到当前年份):</p><p><img src="https://img.imql.life/illustrations/a6c2d6225dd7ecc1ca7b91d4ff1e3d1b.png" alt="建站年份" title="建站年份"></p><h3 id="在页脚添加备案信息">在页脚添加备案信息<a class="headerlink" href="#在页脚添加备案信息"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line"> # Beian ICP and gongan information for Chinese users. See: http://www.beian.miit.gov.cn, http://www.beian.gov.cn</span><br><span class="line"> beian:</span><br><span class="line"><span class="deletion">- enable: false</span></span><br><span class="line"><span class="addition">+ enable: true</span></span><br><span class="line"><span class="deletion">- icp:</span></span><br><span class="line"><span class="addition">+ icp: 京ICP备20031573号-2</span></span><br><span class="line"> # The digit in the num of gongan beian.</span><br><span class="line"> gongan_id:</span><br><span class="line"> # The full num of gongan beian.</span><br><span class="line"> gongan_num:</span><br><span class="line"> # The icon for gongan beian. See: http://www.beian.gov.cn/portal/download</span><br><span class="line"> gongan_icon_url:</span><br><span class="line">...</span><br></pre></td></tr></table></figure><p>效果展示:</p><p><img src="https://img.imql.life/illustrations/fb9805c241a1cdb3079a02f5e5084a71.png" alt="备案信息" title="备案信息"></p><h3 id="选择主题风格">选择主题风格<a class="headerlink" href="#选择主题风格"></a></h3><p>编辑 NexT 的配置文件(喜欢什么风格的话把前面的 # 去掉即可,注意只能启用一种风格):</p><figure class="highlight diff"><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><br><span class="line"># Schemes</span><br><span class="line">scheme: Muse</span><br><span class="line">#scheme: Mist</span><br><span class="line">#scheme: Pisces</span><br><span class="line">#scheme: Gemini</span><br><span class="line">...</span><br></pre></td></tr></table></figure><p>各种主题风格展示:</p><p><img src="https://img.imql.life/illustrations/6b38f760b400db65b2278b623a119f5c.png" alt="Muse" title="Muse"><img src="https://img.imql.life/illustrations/089b4342552ec9ed70710ce86a38a51f.png" alt="Mist" title="Mist"></p><p><img src="https://img.imql.life/illustrations/7570155dfc974acc6e45ee80e293c992.png" alt="Pisces" title="Pisces"></p><p><img src="https://img.imql.life/illustrations/c4575460770b2ab6e79018a4a6f4b377.png" alt="Gemini" title="Gemini"></p><h3 id="添加标签和分类页面-2">添加标签和分类页面<a class="headerlink" href="#添加标签和分类页面-2"></a></h3><p>编辑 NexT 的配置文件,添加标签和分类菜单项:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line"># Usage: `Key: /link/ || icon`</span><br><span class="line"># Key is the name of menu item. If the translation for this item is available, the translated text will be loaded, otherwise the Key name will be used. Key is case-senstive.</span><br><span class="line"># Value before `||` delimiter is the target link, value after `||` delimiter is the name of Font Awesome icon.</span><br><span class="line"># When running the site in a subdirectory (e.g. yoursite.com/blog), remove the leading slash from link value (/archives -> archives).</span><br><span class="line"># External url should start with http:// or https://</span><br><span class="line">menu:</span><br><span class="line"> home: / || fa fa-home</span><br><span class="line"> #about: /about/ || fa fa-user</span><br><span class="line"><span class="deletion">- #tags: /tags/ || fa fa-tags</span></span><br><span class="line"><span class="addition">+ tags: /tags/ || fa fa-tags</span></span><br><span class="line"><span class="deletion">- #categories: /categories/ || fa fa-th</span></span><br><span class="line"><span class="addition">+ categories: /categories/ || fa fa-th</span></span><br><span class="line"> archives: /archives/ || fa fa-archive</span><br><span class="line"> #schedule: /schedule/ || fa fa-calendar</span><br><span class="line"> #sitemap: /sitemap.xml || fa fa-sitemap</span><br><span class="line"> #commonweal: /404/ || fa fa-heartbeat</span><br><span class="line">...</span><br></pre></td></tr></table></figure><p>在<博客构建目录>下进入终端,执行如下命令。</p><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 new page tags</span><br></pre></td></tr></table></figure><p>编辑生成的 <a href="http://index.md">index.md</a>:</p><figure class="highlight diff"><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"><span class="comment">---</span></span><br><span class="line"><span class="deletion">-title: tags</span></span><br><span class="line">date: 2020-01-24 22:20:25</span><br><span class="line"><span class="comment">---</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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 class="comment">---</span></span><br><span class="line"><span class="addition">+title: 标签</span></span><br><span class="line">date: 2020-01-24 22:20:25</span><br><span class="line"><span class="addition">+type: tags</span></span><br><span class="line"><span class="comment">---</span></span><br></pre></td></tr></table></figure><p>在<博客构建目录>下进入终端,执行如下命令。</p><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 new page categories</span><br></pre></td></tr></table></figure><p>编辑生成的 <a href="http://index.md">index.md</a>:</p><figure class="highlight diff"><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"><span class="comment">---</span></span><br><span class="line"><span class="deletion">-title: categories</span></span><br><span class="line">date: 2020-01-24 22:21:09</span><br><span class="line"><span class="comment">---</span></span><br></pre></td></tr></table></figure><figure class="highlight diff"><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 class="comment">---</span></span><br><span class="line"><span class="addition">+title: 分类</span></span><br><span class="line">date: 2020-01-24 22:21:09</span><br><span class="line"><span class="addition">+type: categories</span></span><br><span class="line"><span class="comment">---</span></span><br></pre></td></tr></table></figure><p>编辑文章模板文件(为<博客构建目录>下 scaffolds 下 <a href="http://post.md">post.md</a>):</p><figure class="highlight diff"><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"><span class="comment">---</span></span><br><span class="line">title: {{ title }}</span><br><span class="line">date: {{ date }}</span><br><span class="line">tags:</span><br><span class="line"><span class="addition">+categories:</span></span><br><span class="line"><span class="comment">---</span></span><br></pre></td></tr></table></figure><p>以后想写文章(执行<code>hexo new post <自定义名></code>,编辑相应生成的<自定义名>.md)时,只需自定义 tags 和 categories 的值(注意键值之间有空格),该文章就会在标签页面和分类页面被标记和分类起来。</p><h3 id="设置侧边栏总是显示(只适合风格_Muse_或_Mist)">设置侧边栏总是显示(只适合风格 Muse 或 Mist)<a class="headerlink" href="#设置侧边栏总是显示(只适合风格_Muse_或_Mist)"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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">...</span><br><span class="line"> # Sidebar Display (only for Muse | Mist), available values:</span><br><span class="line"> # - post expand on posts automatically. Default.</span><br><span class="line"> # - always expand for all pages automatically.</span><br><span class="line"> # - hide expand only when click on the sidebar toggle icon.</span><br><span class="line"> # - remove totally remove sidebar including sidebar toggle.</span><br><span class="line"><span class="deletion">- display: post</span></span><br><span class="line"><span class="addition">+ display: always</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><h3 id="头像-2">头像<a class="headerlink" href="#头像-2"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line"># Sidebar Avatar</span><br><span class="line">avatar:</span><br><span class="line"> # Replace the default image and set the url here.</span><br><span class="line"><span class="deletion">- url: #/images/avatar.gif</span></span><br><span class="line"><span class="addition">+ url: <自己图床的地址或者本地地址></span></span><br><span class="line"> # If true, the avatar will be dispalyed in circle.</span><br><span class="line"><span class="deletion">- rounded: false</span></span><br><span class="line"><span class="addition">+ rounded: true</span></span><br><span class="line"> # If true, the avatar will be rotated with the cursor.</span><br><span class="line"><span class="deletion">- rotated: false</span></span><br><span class="line"><span class="addition">+ rotated: true</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><h3 id="添加社交链接-2">添加社交链接<a class="headerlink" href="#添加社交链接-2"></a></h3><p>编辑 NexT 的配置文件,个性化添加自己的社交链接:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line"># Usage: `Key: permalink || icon`</span><br><span class="line"># Key is the link label showing to end users.</span><br><span class="line"># Value before `||` delimiter is the target permalink, value after `||` delimiter is the name of Font Awesome icon.</span><br><span class="line">social:</span><br><span class="line"><span class="addition">+ blog: https://blog.imql.life/ || fas fa-blog</span></span><br><span class="line"><span class="addition">+ www: https://www.imql.life/ || fas fa-house-user</span></span><br><span class="line"><span class="addition">+ nav: https://nav.imql.life/ || fas fa-location-arrow</span></span><br><span class="line"><span class="addition">+ space: https://space.imql.life/ || fas fa-cube</span></span><br><span class="line"><span class="deletion">- #GitHub: https://github.com/yourname || fab fa-github</span></span><br><span class="line"><span class="addition">+ Github: https://github.com/ql-isaac || fab fa-github</span></span><br><span class="line"><span class="deletion">- #E-Mail: mailto:[email protected] || fa fa-envelope</span></span><br><span class="line"><span class="addition">+ E-Mail: mailto:[email protected] || fa fa-envelope</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><h3 id="添加友情链接">添加友情链接<a class="headerlink" href="#添加友情链接"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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><br><span class="line">links:</span><br><span class="line"><span class="deletion">- #Title: http://yoursite.com</span></span><br><span class="line"><span class="addition">+ <标题1>: <地址1></span></span><br><span class="line"><span class="addition">+ <标题2>: <地址2></span></span><br><span class="line"><span class="addition">+ <标题3>: <地址3></span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><h3 id="启用文章底部标签图标">启用文章底部标签图标<a class="headerlink" href="#启用文章底部标签图标"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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"># Use icon instead of the symbol # to indicate the tag at the bottom of the post</span><br><span class="line"><span class="deletion">-tag_icon: false</span></span><br><span class="line"><span class="addition">+tag_icon: true</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><p>效果展示:</p><p><img src="https://img.imql.life/illustrations/d6c1bddda492c9bf405da36039e3024f.png" alt="tag" title="tag"></p><h3 id="集成在线编辑-2">集成在线编辑<a class="headerlink" href="#集成在线编辑-2"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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><br><span class="line"># Post edit</span><br><span class="line"># Easily browse and edit blog source code online.</span><br><span class="line">post_edit:</span><br><span class="line"><span class="deletion">- enable: false</span></span><br><span class="line"><span class="deletion">- url: https://github.com/user-name/repo-name/tree/branch-name/subdirectory-name # Link for view source</span></span><br><span class="line"><span class="deletion">- #url: https://github.com/user-name/repo-name/edit/branch-name/subdirectory-name # Link for fork & edit</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><figure class="highlight diff"><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><br><span class="line"># Post edit</span><br><span class="line"># Easily browse and edit blog source code online.</span><br><span class="line">post_edit:</span><br><span class="line"><span class="addition">+ enable: true</span></span><br><span class="line"><span class="addition">+ url: https://github.dev/<自己的GitHub用戶名>/# # Link for view & edit</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><h3 id="设置文本对齐方式为左对齐">设置文本对齐方式为左对齐<a class="headerlink" href="#设置文本对齐方式为左对齐"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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">...</span><br><span class="line"># Set the text alignment in posts / pages.</span><br><span class="line">text_align:</span><br><span class="line"> # Available values: start | end | left | right | center | justify | justify-all | match-parent</span><br><span class="line"><span class="deletion">- desktop: justify</span></span><br><span class="line"><span class="addition">+ desktop: left</span></span><br><span class="line"><span class="deletion">- mobile: justify</span></span><br><span class="line"><span class="addition">+ mobile: left</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><h3 id="代码块设置-2">代码块设置<a class="headerlink" href="#代码块设置-2"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">codeblock:</span><br><span class="line"> # Code Highlight theme</span><br><span class="line"> # All available themes: https://theme-next.js.org/highlight/</span><br><span class="line"> theme:</span><br><span class="line"> light: default</span><br><span class="line"> dark: stackoverflow-dark</span><br><span class="line"> prism:</span><br><span class="line"> light: prism</span><br><span class="line"> dark: prism-dark</span><br><span class="line"> # Add copy button on codeblock</span><br><span class="line"> copy_button:</span><br><span class="line"><span class="deletion">- enable: false</span></span><br><span class="line"><span class="addition">+ enable: true</span></span><br><span class="line"> # Available values: default | flat | mac</span><br><span class="line"> style:</span><br><span class="line">...</span><br></pre></td></tr></table></figure><div class="note info flat"><p>以上设置为个人偏好,请查看注释,通过本地部署的方式查看确定自己的偏好。</p></div><h3 id="回到顶部按钮设置">回到顶部按钮设置<a class="headerlink" href="#回到顶部按钮设置"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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">...</span><br><span class="line">back2top:</span><br><span class="line"> enable: true</span><br><span class="line"> # Back to top in sidebar.</span><br><span class="line"> sidebar: false</span><br><span class="line"> # Scroll percent label in b2t button.</span><br><span class="line"><span class="deletion">- scrollpercent: false</span></span><br><span class="line"><span class="addition">+ scrollpercent: true</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><h3 id="在页面顶部显示浏览进度">在页面顶部显示浏览进度<a class="headerlink" href="#在页面顶部显示浏览进度"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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">...</span><br><span class="line"># Reading progress bar</span><br><span class="line">reading_progress:</span><br><span class="line"><span class="deletion">- enable: false</span></span><br><span class="line"><span class="addition">+ enable: true</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><h3 id="在右上角添加渲染本站的源码仓库传送门">在右上角添加渲染本站的源码仓库传送门<a class="headerlink" href="#在右上角添加渲染本站的源码仓库传送门"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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">...</span><br><span class="line"># `Follow me on GitHub` banner in the top-right corner.</span><br><span class="line">github_banner:</span><br><span class="line"><span class="deletion">- enable: false</span></span><br><span class="line"><span class="addition">+ enable: true</span></span><br><span class="line"><span class="deletion">- permalink: https://github.com/yourname</span></span><br><span class="line"><span class="addition">+ permalink: https://github.com/<自己的GitHub用戶名></span></span><br><span class="line"> title: Follow me on GitHub</span><br><span class="line">...</span><br></pre></td></tr></table></figure><h3 id="字体">字体<a class="headerlink" href="#字体"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">font:</span><br><span class="line"><span class="deletion">- enable: false</span></span><br><span class="line"><span class="addition">+ enable: true</span></span><br><span class="line">...</span><br><span class="line"> # Global font settings used for all elements inside <body>.</span><br><span class="line"> global:</span><br><span class="line"> external: true</span><br><span class="line"><span class="deletion">- family: Lato</span></span><br><span class="line"><span class="addition">+ family:</span></span><br><span class="line"> size:</span><br><span class="line">...</span><br><span class="line"> # Font settings for posts (.post-body).</span><br><span class="line"> posts:</span><br><span class="line"> external: true</span><br><span class="line"><span class="deletion">- family:</span></span><br><span class="line"><span class="addition">+ family: Noto Serif SC</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><h3 id="优雅地查看图片">优雅地查看图片<a class="headerlink" href="#优雅地查看图片"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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">...</span><br><span class="line"># FancyBox is a tool that offers a nice and elegant way to add zooming functionality for images.</span><br><span class="line"># For more information: https://fancyapps.com/fancybox</span><br><span class="line"><span class="deletion">-fancybox: false</span></span><br><span class="line"><span class="addition">+fancybox: true</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><h3 id="开启图片懒加载">开启图片懒加载<a class="headerlink" href="#开启图片懒加载"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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">...</span><br><span class="line"># Vanilla JavaScript plugin for lazyloading images.</span><br><span class="line"># For more information: https://github.com/ApoorvSaxena/lozad.js</span><br><span class="line"><span class="deletion">-lazyload: false</span></span><br><span class="line"><span class="addition">+lazyload: true</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><h3 id="开启_busuanzi_统计">开启 busuanzi 统计<a class="headerlink" href="#开启_busuanzi_统计"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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><br><span class="line"># Show Views / Visitors of the website / page with busuanzi.</span><br><span class="line"># Get more information on http://ibruce.info/2015/04/04/busuanzi</span><br><span class="line">busuanzi_count:</span><br><span class="line"><span class="deletion">- enable: false</span></span><br><span class="line"><span class="addition">+ enable: true</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><h3 id="添加搜索功能-2">添加搜索功能<a class="headerlink" href="#添加搜索功能-2"></a></h3><p>在<博客构建目录>下进入终端,输入如下命令安装 hexo-generator-searchdb。</p><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">npm install --save hexo-generator-searchdb</span><br></pre></td></tr></table></figure><p>开启搜索功能:</p><figure class="highlight diff"><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><br><span class="line"># Local Search</span><br><span class="line"># Dependencies: https://github.com/theme-next/hexo-generator-searchdb</span><br><span class="line">local_search:</span><br><span class="line"><span class="deletion">- enable: false</span></span><br><span class="line"><span class="addition">+ enable: true</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><h3 id="设置_Note_tag">设置 Note tag<a class="headerlink" href="#设置_Note_tag"></a></h3><p>编辑 NexT 的配置文件:</p><figure class="highlight diff"><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></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line"># Note tag (bootstrap callout)</span><br><span class="line">note:</span><br><span class="line"> # Note tag style values:</span><br><span class="line"> # - simple bs-callout old alert style. Default.</span><br><span class="line"> # - modern bs-callout new (v2-v3) alert style.</span><br><span class="line"> # - flat flat callout style with background, like on Mozilla or StackOverflow.</span><br><span class="line"> # - disabled disable all CSS styles import of note tag.</span><br><span class="line"><span class="deletion">- style: simple</span></span><br><span class="line"><span class="addition">+ style: flat</span></span><br><span class="line"><span class="deletion">- icons: false</span></span><br><span class="line"><span class="addition">+ icons: true</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure><h2 id="参考-6">参考<a class="headerlink" href="#参考-6"></a></h2><ul><li><a href="https://theme-next.js.org/">NexT 主题文档</a></li><li><a href="https://lixint.github.io/">lixint</a></li><li><a href="http://www.dragonbaby308.com/">dragonbaby308</a></li></ul><hr class="footnotes-sep"><section class="footnotes"><ol class="footnotes-list"><li id="fn1" class="footnote-item"><p><a href="https://zhanghuimeng.github.io/post/add-footnote-plugin-for-hexo-blog/">为 Hexo 博客添加脚注插件</a> <a href="#fnref1" class="footnote-backref">↩︎</a></p></li></ol></section>]]></content>
<categories>
<category> 我的博客 </category>
</categories>
<tags>
<tag> Hexo </tag>
<tag> NexT </tag>
</tags>
</entry>
<entry>
<title>我的博客的诞生(一)</title>
<link href="/2020/01/24/My_HexoBlog_with_NexT_1/"/>
<url>/2020/01/24/My_HexoBlog_with_NexT_1/</url>
<content type="html"><![CDATA[<p><a href="https://hexo.io/zh-cn/">Hexo</a>,一个静态博客框架,这意味着最低成本的部署,使用它的人也最多,插件和主题也最丰富。本文来记录和讲解一下我认为的搭建个人博客最佳实践,可供大家参考。</p><span id="more"></span><div class="note primary flat"><p>本文对于文件(代码)变动的描述方式为 <code>-</code> 指删掉该行,<code>+</code> 指增加改行(如果你是直接复制此行,请注意删掉 <code>+</code> 和上下文对齐),<code>...</code> 表示省略上下文。另外,本文对于文件(代码)变动的描述只针对当时的文件(代码)版本,请根据实际情况决定对自己的相应文件(代码)进行变动。</p></div><h2 id="安装_Node_js">安装 Node.js<a class="headerlink" href="#安装_Node_js"></a></h2><p>进入<a href="https://nodejs.org/zh-cn/"> Node.js 官方网站</a>,点击下载 LTX(Long Term Support)版,安装步骤非常简单,一直 next;</p><h2 id="安装和配置_Git-2">安装和配置 Git<a class="headerlink" href="#安装和配置_Git-2"></a></h2><p>进入<a href="https://git-scm.com/downloads"> Git 官方网站下载页面</a>,选择 Windows 版本的 Git 下载,<a href="https://www.imql.life/2020/01/24/What_is_Git/#Windows-10-%E4%B8%8A%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE-Git">安装和配置步骤</a>我记录在上一篇文章中,请参考进行;</p><h2 id="安装_hexo_cli">安装 hexo-cli<a class="headerlink" href="#安装_hexo_cli"></a></h2><ol><li>在合适的路径下新建一个文件夹,文件夹名自定义,例如 blog,作为<博客构建目录>;</li><li>进入<博客构建目录>,在空白处点鼠标的右键,选择 Git Bash Here 进入终端;</li><li>更换 <a href="https://nodejs.org/en/knowledge/getting-started/npm/what-is-npm/">npm</a> 的源地址以提高包下载速度:</li></ol><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">npm config <span class="built_in">set</span> registry https://registry.npmmirror.com</span><br></pre></td></tr></table></figure><ol start="4"><li>在终端输入如下命令,回车,等待 hexo-cli 安装完成,完成后,可输入<code>hexo -v</code>查看相关版本信息;</li></ol><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">npm install -g hexo-cli</span><br></pre></td></tr></table></figure><h2 id="初始化一个_Hexo_项目">初始化一个 Hexo 项目<a class="headerlink" href="#初始化一个_Hexo_项目"></a></h2><ol start="5"><li>在终端输入<code>hexo init</code>,等待,可在<博客构建目录>中看到生成了如下图所示的文件;</li></ol><p><img src="https://img.imql.life/illustrations/0431ca765bdb7f7de1020a927982e674.png" alt="初始文件" title="初始文件"></p><h2 id="本地部署自己的博客">本地部署自己的博客<a class="headerlink" href="#本地部署自己的博客"></a></h2><p>在终端输入 <code>hexo s</code>,<a href="http://localhost:4000">查看本地部署自己的博客是否成功</a>;</p><h2 id="创建_GitHub_用户仓库">创建 GitHub 用户仓库<a class="headerlink" href="#创建_GitHub_用户仓库"></a></h2><p>点击右上角的加号,点击 New repository,填写 Repository name,这里的仓库名要按照”<自己的 Github 用户名>.github.io“的格式来填,填写 Description,点击 Creat repository,创建仓库成功;</p><h2 id="部署至_Github_Pages">部署至 Github Pages<a class="headerlink" href="#部署至_Github_Pages"></a></h2><ol><li>安装 Hexo 的 Git 插件。终端输入如下命令,回车,等待下载完成;</li></ol><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">npm install --save hexo-deployer-git</span><br></pre></td></tr></table></figure><ol start="2"><li>编辑 Hexo 的配置文件:</li></ol><figure class="highlight diff"><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><br><span class="line"># Deployment</span><br><span class="line">## Docs: https://hexo.io/docs/deployment.html</span><br><span class="line">deploy:</span><br><span class="line"><span class="deletion">- type: ''</span></span><br><span class="line"><span class="addition">+ type: git</span></span><br><span class="line"><span class="addition">+ repo:</span></span><br><span class="line"><span class="addition">+ github: [email protected]:<自己的Github用户名>/<自己的Github用户名>.github.io.git,master</span></span><br></pre></td></tr></table></figure><ol start="3"><li>在终端输入 <code>hexo g -d</code>,回车,进行博客的最终操作——生成静态文件后立即部署到 Github Pages 中(可看到上面创建了的仓库会相应生成我们的博客文件);</li><li><a href="https://ql-isaac.github.io">大功告成,散花!(将域名中 ql-isaac 替换成自己的 Github 用户名)</a>;</li></ol><div class="note primary flat"><p>以上步骤完成后,对于初次搭建个人博客的小伙伴来说可不着急进行以下进阶部署方式,推荐阅读<a href="https://blog.imql.life/2020/01/24/My_HexoBlog_with_NexT_3/">本系列第三篇文章</a>开始写几篇笔记、博文吧~</p></div><h2 id="部署至_Vercel">部署至 Vercel<a class="headerlink" href="#部署至_Vercel"></a></h2><ol><li><a href="https://vercel.com/">Vercel</a>,我用过的最好用的网站托管平台,和 GitHub Pages 一样,也是用来托管你的博客的,但是它在国内的网络状况要比 GitHub Pages 好。首先点击登录:</li></ol><p><img src="https://img.imql.life/illustrations/3a8fb05e2477d4c678a4741c3085f07a.png" alt="登录.png"></p><ol start="2"><li>直接使用 GitHub 账号,如下图,之后会弹出一个授权窗口,授权一下;</li></ol><p><img src="https://img.imql.life/illustrations/22f886f14ffdeaf0ca50b6946b4585c0.png" alt="直接使用GitHub账号.png"></p><ol start="3"><li>点击 New Project,选择添加 GitHub 账户,如下图,确认安装 Vercel;</li></ol><p><img src="https://img.imql.life/illustrations/877e9a9b1894291c4bfa0d3100ece65e.png" alt="添加GitHub账户.png"></p><ol start="4"><li>默认是只显示你 GitHub 账户前五个更新了的仓库,如果在这里没找到上面创建了的仓库,可在搜索框内输入上面创建了的仓库的名称,即<自己的 Github 用户名>.github.io,这时就可以导入了,如下图;</li></ol><p><img src="https://img.imql.life/illustrations/7ea2e35791371f86053f14c9c73f1293.png" alt="导入.png"></p><ol start="5"><li>直接点击 deploy(部署):</li></ol><p><img src="https://img.imql.life/illustrations/e2c277e2b6c2a9425f94cba1086c3e39.png" alt="部署.png"></p><ol start="6"><li><a href="https://ql-isaac-github-io.vercel.app/">大功又告成,散花!(将域名中 ql-isaac 替换成自己的 Github 用户名)</a>;</li></ol><h3 id="自定义域名">自定义域名<a class="headerlink" href="#自定义域名"></a></h3><ol start="7"><li>都自建了一个博客,博客域名怎么能不自己定义呢?<a href="https://dnspod.cloud.tencent.com/">前往腾讯云域名注册</a>,搜索一下自己喜欢的名字,实在想不出什么来,可以和我一样用“imxx.xx"的格式(I am xx),我选的域名为 <code>imql.life</code>,也不贵,一年 50 元以内;</li><li>在以上创建的项目设置中,找到 Domains(域名),添加自定义博客域名,一般就是 <code>blog.xxx.xx</code>:</li></ol><p><img src="https://img.imql.life/illustrations/fa8989bee9d2422c28dba1425b4cbb29.png" alt="自定义域名.png"></p><ol start="9"><li>需要添加解析。前往 <a href="https://console.dnspod.cn/dns/list">DNSPOD</a>,点击自己域名,添加解析,如下图;</li></ol><p><img src="https://img.imql.life/illustrations/294b8288de63f07fee67854cbfb7cd6d.png" alt="添加解析.png"></p><div class="note info flat"><p>这里的记录值填写 Vercel 专门给中国提供的一个值 <code>cname-china.vercel-dns.com</code>更好。</p></div><ol start="10"><li>大功又又告成,散花!访问自己定义的博客域名即可;</li></ol><h2 id="部署至_Webify">部署至 Webify<a class="headerlink" href="#部署至_Webify"></a></h2><ol><li>Webify,Web 应用托管,国内版的 Vercel,觉得 Vercel 还是比较慢的话就用这个吧。首先注册一个腾讯云账号,进入控制台,进入 Web 应用托管:</li></ol><p><img src="https://img.imql.life/illustrations/7476f2738d454d52fad88ddaa3620aad.png" alt="Web应用托管.png"></p><ol start="2"><li>新建应用:</li></ol><p><img src="https://img.imql.life/illustrations/56c9451019103a6a1dc66683c504065a.png" alt="新建应用.png"></p><ol start="3"><li>选择 Gitee 平台:</li></ol><p><img src="https://img.imql.life/illustrations/43d468f06c8d2b676d8fab9cf2f4d466.png" alt="Gitee平台.png"></p><div class="note info flat"><p>这里我试过其他三个平台,仓库更新触发部署都是失败的。</p></div><ol start="4"><li>授权:</li></ol><p><img src="https://img.imql.life/illustrations/d6038b6a419b92b8f16699ef6825ed98.png" alt="授权.png"></p><ol start="5"><li>鼠标移动到右上角加号处,选择从 GitHub/GitLab 导入仓库,复制上面创建了的仓库的地址到第一栏,仓库名称填自己的 Gitee 用户名,导入。</li></ol><div class="note info flat"><p>这里导入成功后,在仓库页面上边一栏的右侧服务处可开启 Gitee Pages,由于是国内的服务,访问速度肯定比 GitHub Pages 要快,但是需要实名认证,而且不支持自定义域名,不支持页面自动更新,在此不推荐。</p></div><ol start="6"><li>编辑 Hexo 的配置文件:</li></ol><figure class="highlight diff"><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><br><span class="line"># Deployment</span><br><span class="line">## Docs: https://hexo.io/docs/deployment.html</span><br><span class="line">deploy:</span><br><span class="line"> type: git</span><br><span class="line"> repo:</span><br><span class="line"> github: [email protected]:<自己的Github用户名>/<自己的Github用户名>.github.io.git,master</span><br><span class="line"><span class="addition">+ gitee: [email protected]:<自己的Gitee用户名>/<自己的Gitee用户名>.git,master</span></span><br></pre></td></tr></table></figure><ol start="7"><li>导入以上自己的 Gitee 用户名命名的仓库,框架选择纯静态页面;</li><li>部署,确认;</li><li>等待发布成功,相对来说有点慢;</li><li>等待 CDN 配置;</li><li>大功又又又告成,散花!访问自己的应用域名即可;</li></ol><h3 id="自定义域名(需备案)">自定义域名(需备案)<a class="headerlink" href="#自定义域名(需备案)"></a></h3><ol start="12"><li>在应用详情-应用设置中,点击添加域名,如下图。</li></ol><p><img src="https://img.imql.life/illustrations/8de041bb105a8be9f125f70b454702f0.png" alt="添加域名.png"></p><ol start="13"><li>添加自定义域名(HTTPS 证书没有的话请点击链接申请一个,免费的):</li></ol><p><img src="https://img.imql.life/illustrations/7d38727d19e4639125699c91d94d09bf.png" alt="自定义域名.png"></p><ol start="14"><li>等待变更(有点慢);</li><li>添加解析。前往 <a href="https://console.dnspod.cn/dns/list">DNSPOD</a>,找到自己域名,找到上面添加的解析,修改记录值为 Webify 给的值,如下图;</li></ol><p><img src="https://img.imql.life/illustrations/df1c1f3e89d4180b72b3e5849fd6262c.png" alt="Webify给的值.png"></p><p><img src="https://img.imql.life/illustrations/7962a43d150da8eeb7bc6b440a743f1e.png" alt="修改解析" title="修改解析"></p><ol start="16"><li>大功又又又又告成,散花!访问自己定义的博客域名即可;</li></ol><h2 id="境内境外双线部署">境内境外双线部署<a class="headerlink" href="#境内境外双线部署"></a></h2><p>最后的最后,你是否追求极致,是否希望最低成本实现全球部署,很简单,再添加一个解析,线路类型为境外,记录值为 <code>cname.vercel-dns.com</code>即可。</p><p><img src="https://img.imql.life/illustrations/7ae8079ba505acb9a4701a3a3c112b9a.png" alt="境外.png"></p><p><img src="https://img.imql.life/illustrations/377f151d6356bc498d480e7a0f9c3c7b.png" alt="国内测速.png"></p><p><img src="https://img.imql.life/illustrations/789222c74ea97b63cc5e516598366b7e.png" alt="国际测速.png"></p>]]></content>
<categories>
<category> 我的博客 </category>
</categories>
<tags>
<tag> Windows </tag>
<tag> Git </tag>
<tag> Hexo </tag>
<tag> Node.js </tag>
</tags>
</entry>
<entry>
<title>什么是 Git?</title>
<link href="/2020/01/24/What_is_Git/"/>
<url>/2020/01/24/What_is_Git/</url>
<content type="html"><![CDATA[<p>Git 是一个目前世界上最流行的开源分布式版本控制系统。</p><span id="more"></span><h2 id="Git_的诞生">Git 的诞生<a class="headerlink" href="#Git_的诞生"></a></h2><p>Git 是<a href="https://www.baidu.com/s?wd=%E6%9E%97%E7%BA%B3%E6%96%AF%C2%B7%E6%89%98%E7%93%A6%E5%85%B9&tn=SE_PcZhidaonwhc_ngpagmjz&rsv_dl=gh_pc_zhidao">林纳斯·托瓦兹</a>为了帮助管理 <a href="https://baike.baidu.com/item/Linux/27050">Linux</a> 内核开发而开发的。在 2002 年以前,世界各地的志愿者还是以一种传统的方式将源代码文件发给林纳斯·托瓦兹,然后由他本人通过手工方式合并代码。当时虽然有 CSV、SVN 这些免费的版本控制系统,但是速度慢、需要联网,也有一些商用的版本控制系统,虽然比 CSV、SVN 好用,但是不开源,和 Linux 的开源精神不符。2002 年,Linux 系统已经发展了十年,代码库之大让林纳斯·托瓦兹很难继续通过手工方式管理,最终林纳斯·托瓦兹选择了一个商业的版本控制系统 BitKeeper,BitKeeper 的东家 BitMover 公司出于人道主义精神,授权 Linux 社区免费使用这个版本控制系统,这看起来是一个很好的局面。Linux 社区牛人聚集,2005 年,开发 Samba 的 Andrew 试图破解 BitKeeper 的协议的行为被 BitMover 公司发现,Linux 社区的 BitKeeper 免费使用权被收回,于是,<a href="https://www.baidu.com/s?wd=%E6%9E%97%E7%BA%B3%E6%96%AF%C2%B7%E6%89%98%E7%93%A6%E5%85%B9&tn=SE_PcZhidaonwhc_ngpagmjz&rsv_dl=gh_pc_zhidao">林纳斯·托瓦兹</a>花了两周时间自己用 C 写了一个分布式版本控制系统,Git 诞生!之后,Git 迅速成为最流行的分布式版本控制系统,随即,2008 年,GitHub 网站上线,它为开源项目免费提供 Git 存储,无数开源项目开始迁移至 GitHub,包括 jQuery、PHP、Ruby 等等。</p><h2 id="安装和配置_Git">安装和配置 Git<a class="headerlink" href="#安装和配置_Git"></a></h2><p>我在《我的 HexoBlog 的诞生(一)》中已经完成了 Git 的安装和配置,不过那只是在 Windows 上,而且也没详细讲,这里就详细讲解一下如何在 Windows 和 Linux 上安装和配置 Git 吧。</p><h3 id="Windows_10_上安装和配置_Git">Windows 10 上安装和配置 Git<a class="headerlink" href="#Windows_10_上安装和配置_Git"></a></h3><ol><li>双击安装程序;</li></ol><p><img src="https://img.imql.life/illustrations/4db3988e88014c9cf2015a260baad44b.png" alt="安装程序" title="安装程序"></p><ol start="2"><li>GNU 许可证。不看,Next;</li></ol><p><img src="https://img.imql.life/illustrations/f4c2a18504d9beb697dfca2fb2baf830.png" alt="许可协议" title="许可协议"></p><ol start="3"><li>设置安装路径。可以将 C 改为 D,安装在 D 盘,这里就不改了,Next;</li></ol><p><img src="https://img.imql.life/illustrations/d5c58bfb9594c5c598ca0ce0e25d2c8e.png" alt="设置安装路径" title="设置安装路径"></p><ol start="4"><li>安装组件。第一个选项是说是否创建桌面快捷方式,可以不勾选,下面六个都勾选了,为默认,不更改,倒数第一个是说是否检查更新,可以不勾选,倒数第二个是说是否在所有控制台窗口中使用 TrueType 字体,勾选,Next;</li></ol><p><img src="https://img.imql.life/illustrations/e5a74fac34d173b630a80ffd4567fe73.png" alt="安装组件" title="安装组件"></p><ol start="5"><li>开始菜单设置。直接 Next;</li></ol><p><img src="https://img.imql.life/illustrations/d87bbcff09da70aa766bcc6baef10d24.png" alt="开始菜单设置" title="开始菜单设置"></p><ol start="6"><li>设置 Git 的默认文本编辑器:就选择 Vim,Next;</li></ol><p><img src="https://img.imql.life/illustrations/840d5ccbd64c47229662736c83aaeb4b.png" alt="设置Git的默认文本编辑器" title="设置Git的默认文本编辑器"></p><ol start="7"><li>调整 PATH 环境。就选择默认推荐的,Next,该推荐项是说仅向 PATH 添加一些最小的 Git 包装器,以避免使用可选的 Unix 工具造成环境混乱,能够通过 Git Bash、命令提示符、Windows PowerShell 以及在 PATH 中寻找 Git 的任何第三方软件使用 Git;</li></ol><p><img src="https://img.imql.life/illustrations/8e91c4cd317846766a76e392fb880086.png" alt="调整Path环境" title="调整Path环境"></p><ol start="8"><li>选择 HTTPS 后端传输。第一个选项是说使用 OpenSSL 库,服务器证书将使用 ca-bundle.crt 文件进行验证,这是我们常用的选项,第二个选项是说使用本地 Windows 安全通道库,服务器证书将使用 Windows 证书存储验证,此选项还允许使用公司的内部根 CA 证书,例如通过 Active Directory Domain Services,这里,就默认第一个选项,Next;</li></ol><p><img src="https://img.imql.life/illustrations/b38a3e85a5b39464986e08395ee46035.png" alt="选择HTTPS后端传输" title="选择HTTPS后端传输"></p><ol start="9"><li>配置行尾符号转换:第一个选项是说签出 Windows 风格,提交 Unix 风格的行尾,即签出文本文件时,Git 会将 LF 转换为 CRLF,提交文本文件时,CRLF 将转换为 LF,对于跨平台项目,这是 Windows 上的推荐设置(“core.autocrlf”设置为“true”)。第二个选项是说按原样签出,提交 Unix 样式的行尾,签出文本文件时,Git 不会执行任何转换,提交文本文件时,CRLF 将转换为 LF,对于跨平台项目,这是 Unix 上的建议设置(“core.autocrlf”设置为“input”)。第三个选项是说按原样签出,按原样提交,当签出或提交文本文件时,Git 不会执行任何转换,不建议跨平台项目选择此选项(“core.autocrlf”设置为“false”),这里,就默认第一个选项,Next;</li></ol><p><img src="https://img.imql.life/illustrations/ec51b1b4fc5e38131c17e99d67d82f58.png" alt="配置行尾符号转换" title="配置行尾符号转换"></p><ol start="10"><li>配置终端模拟器以与 Git Bash 一起使用。第一个选项是说使用 MinTTY(MSYS2 的默认终端),Git Bash 将使用 MinTTY 作为终端模拟器,该模拟器具有可调整大小的窗口,非矩形选择和 Unicode 字体,Windows 控制台程序(例如交互式 Python)必须通过“ winpty”启动才能在 MinTTY 中运行,第二个选项是说使用 Windows 的默认控制台窗口,Git 将使用 Windows 的默认控制台窗口(“cmd.exe”),该窗口可以与 Win32 控制台程序(如交互式 Python 或 node.js)一起使用,但默认的回滚非常有限,需要配置为使用 unicode 字体以正确显示非 ASCII 字符,并且在 Windows 10 之前,其窗口不能自由调整大小,并且只允许矩形文本选择,这里,就默认第一个选项,Next;</li></ol><p><img src="https://img.imql.life/illustrations/a6de4c8a6358563c695ad73ccf6189da.png" alt="配置终端模拟器以与Git_Bash一起使用" title="配置终端模拟器以与Git_Bash一起使用"></p><ol start="11"><li>配置额外的选项。第一个选项是说启用文件系统缓存,文件系统数据将被批量读取并缓存在内存中用于某些操作(“core.fscache”设置为“true”), 这可以显着地提升性能,第二个选项是说启用 Git 凭证管理器,Windows 的 Git 凭证管理器为 Windows 提供安全的 Git 凭证存储,最显著的是对 Visual Studio Team Services 和 GitHub 的多因素身份验证支持(需要 .NET Framework v4.5.1 或更高版本),第三个选项是说启用符号链接,启用符号链接需要 SeCreateSymbolicLink 权限,现有存储库不受此设置的影响,这里,就默认第一个和第二个选项,Install;</li></ol><p><img src="https://img.imql.life/illustrations/36ae0d9592dcb8d0ef8c96a751dac76e.png" alt="配置额外的选项" title="配置额外的选项"></p><ol start="12"><li>安装完成;</li></ol><p><img src="https://img.imql.life/illustrations/12eea40c83659b80648d5280bf4e062f.png" alt="安装完成" title="安装完成"></p><ol start="13"><li>Release Notes;</li></ol><p><img src="https://img.imql.life/illustrations/a4f7e5a1271b6214c159244674e4a071.png" alt="Release Notes" title="Release Notes"></p><ol start="14"><li>至此 Git 就算安装完毕了,之后需要去 <a href="https://github.com/">Github</a> 和 <a href="https://gitee.com/">Gitee</a> 注册一个自己的账号,需要绑定自己的邮箱,Github 的话强烈建议绑定谷歌邮箱;</li></ol><p><img src="https://img.imql.life/illustrations/c76465756143a7aef2f04769676efac8.png" alt="注册" title="注册"></p><ol start="15"><li>在桌面右键,点击 Git Bash Here;</li></ol><p><img src="https://img.imql.life/illustrations/69113b03ada6655d5eff921bde59b908.png" alt="桌面右键" title="桌面右键"></p><ol start="16"><li>全局用户信息配置。分别输入以下两个命令回车执行,无提示表示命令执行成功,可以用<code>git config --list</code>来查看配置好的信息;</li></ol><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">git config --global user.name <span class="string">"<自己的GitHub用户名>"</span></span><br></pre></td></tr></table></figure><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">git config --global user.email <span class="string">"<自己的GitHub邮箱>"</span></span><br></pre></td></tr></table></figure><ol start="17"><li>生成 SSH 秘钥并复制公钥。输入以下命令回车执行,然后连敲三次回车键,此时打开 .ssh 文件夹,其位于自己的 Windows 用户文件夹下,如下图,用文本编辑器打开 id_rsa.pub,Ctrl+A,复制里面全部的内容;</li></ol><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">ssh-keygen -t rsa</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/0c0fbfcb69253c795b74528a8d9a77ba.png" alt="SSH" title="SSH"></p><ol start="18"><li>Github 和 Gitee 的 SSH 公钥配置。登录自己的 Github 账号,点击右上角的头像,点击 Setting,点击左侧的 SSH and GPG keys,点击右侧的 New SSH key,填写 Tile(自定义),粘贴刚复制的内容为 Key,最后点击 Add SSH key,Gitee 的方式大同小异;</li><li>测试一下。执行<code>ssh -T [email protected]</code>或<code>ssh -T [email protected]</code>,输入 yes 回车,出现以下提示,表示本机和自己的 GitHub/Gitee 账号绑定成功。</li></ol><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Hi <自己的Github/Gitee用户名>! You've successfully authenticated, but <GitHub/Gitee> does not provide shell access.</span><br></pre></td></tr></table></figure><h3 id="Ubuntu_18_04_LTS_上安装和配置_Git">Ubuntu 18.04 LTS 上安装和配置 Git<a class="headerlink" href="#Ubuntu_18_04_LTS_上安装和配置_Git"></a></h3><ol><li>相比在 Windows 上,在 Linux 上安装和配置 Git 的步骤就比较少了。在终端输入以下命令回车执行,确保系统和 apt 包列表完全更新;</li></ol><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">sudo apt-get update -y</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/e1901e3091e404d47dd2161b052232eb.png" alt="更新" title="更新"></p><ol start="2"><li>在终端输入以下命令回车,安装 Git,可再输入下一个命令查看 Git 版本;</li></ol><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">sudo apt install git</span><br></pre></td></tr></table></figure><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">git --version</span><br></pre></td></tr></table></figure><p><img src="https://img.imql.life/illustrations/5430c7a786669076b1504fb9752e577f.gif" alt="安装Git" title="安装Git"></p><ol start="3"><li>全局用户信息配置。分别输入以下两个命令回车执行,无提示表示命令执行成功,可以用<code>git config --list</code>来查看配置好的信息;</li></ol><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">git config --global user.name <span class="string">"<自己的GitHub用户名>"</span></span><br></pre></td></tr></table></figure><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">git config --global user.email <span class="string">"<自己的GitHub邮箱>"</span></span><br></pre></td></tr></table></figure><ol start="4"><li>生成 SSH 秘钥。输入以下命令回车执行,然后连敲三次回车键;</li></ol><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">ssh-keygen -t rsa</span><br></pre></td></tr></table></figure><ol start="5"><li>输入以下命令回车,输入用户密码安装 Vim 文本编辑器;</li></ol><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">sudo apt-get install vim</span><br></pre></td></tr></table></figure><ol start="6"><li>执行以下命令,用 Vim 打开公钥文件,复制其中的内容(不要复制多了,也不要复制少了);</li></ol><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">vim /home/<自己的用户名>/.ssh/id_rsa.pub</span><br></pre></td></tr></table></figure><ol start="7"><li>Github 和 Gitee 的 SSH 公钥配置。登录自己的 Github 账号,点击右上角的头像,点击 Setting,点击左侧的 SSH and GPG keys,点击右侧的 New SSH key,填写 Tile(自定义),粘贴刚复制的内容为 Key,最后点击 Add SSH key,关于 Gitee 的方式大同小异;</li><li>测试一下。执行<code>ssh -T [email protected]</code>或<code>ssh -T [email protected]</code>,输入 yes 回车,出现以下提示,表示本机和自己的 GitHub/Gitee 账号绑定成功。</li></ol><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Hi <自己的Github/Gitee用户名>! You've successfully authenticated, but <GitHub/Gitee> does not provide shell access.</span><br></pre></td></tr></table></figure><h2 id="Git_的工作流程">Git 的工作流程<a class="headerlink" href="#Git_的工作流程"></a></h2><ol><li>克隆 Git 资源作为工作副本;</li><li>在工作副本中编辑、添加或修改文件;</li><li>如果其他人提交了修改,你可以选择更新工作副本;</li><li>在提交前查看修改;</li><li>提交修改;</li><li>在修改完成后,如果发现错误,可以撤回提交并再次修改并提交。</li></ol><p><img src="https://img.imql.life/illustrations/daff5aafb356a6b32fb7207e74d3c90e.jpeg" alt="Git的工作流程" title="Git的工作流程"></p><h2 id="Git_工作区、暂存区和版本库">Git 工作区、暂存区和版本库<a class="headerlink" href="#Git_工作区、暂存区和版本库"></a></h2><ul><li>工作区:工作目录的实际情况。</li><li>暂存区:即工作副本(修改)。</li><li>版本库:即历史提交。</li></ul><p>下面这个图展示了工作区、版本库中的暂存区和版本库之间的关系:</p><p><img src="https://img.imql.life/illustrations/1216606f036c3ca07efc9d6f60879d47.jpeg" alt="Git 工作区、暂存区和版本库.jpg"></p><ol><li>当对当前工作区编辑(M)、添加(A)或删除(D)的文件执行 git add 命令时,暂存区的目录树被更新;</li><li>当执行提交操作(git commit)时,暂存区转化为版本库的下一次提交;</li><li>当执行<code>git reset</code>命令时,暂存区被还原为版本库最新版本(HEAD),工作区不受影响;</li><li>当执行<code>git checkout .</code>或者<code>git checkout -- <file></code>命令时,会用暂存区全部或指定的文件替换工作区的文件。这个操作很危险,会清除工作区中未添加到暂存区的改动;</li><li>当执行<code>git rm --cached <file></code>命令时,会直接从暂存区删除文件,工作区则不做出改变;</li><li>当执行<code>git checkout HEAD</code>或者<code>git checkout HEAD <file></code>命令时,会用版本库最新版本(HEAD)全部或指定的文件替换暂存区以及工作区中的文件。这个命令也是极具危险性的,因为不但会清除工作区中未添加到暂存区的改动,也会清除暂存区中未提交的改动。</li></ol>]]></content>
<categories>
<category> Git 和 GitHub 从入门到实践 </category>
</categories>
<tags>
<tag> Ubuntu </tag>
<tag> Windows </tag>
<tag> Git </tag>
</tags>
</entry>
<entry>
<title>你好,世界!</title>
<link href="/2020/01/24/Hello_World/"/>
<url>/2020/01/24/Hello_World/</url>
<content type="html"><![CDATA[<p>Welcome to <a href="https://hexo.io/">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues">GitHub</a>.</p><span id="more"></span><h2 id="Quick_Start">Quick Start<a class="headerlink" href="#Quick_Start"></a></h2><h3 id="Create_a_new_post">Create a new post<a class="headerlink" href="#Create_a_new_post"></a></h3><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 new <span class="string">"My New Post"</span></span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/writing.html">Writing</a></p><h3 id="Run_server">Run server<a class="headerlink" href="#Run_server"></a></h3><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 server</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/server.html">Server</a></p><h3 id="Generate_static_files">Generate static files<a class="headerlink" href="#Generate_static_files"></a></h3><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 generate</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/generating.html">Generating</a></p><h3 id="Deploy_to_remote_sites">Deploy to remote sites<a class="headerlink" href="#Deploy_to_remote_sites"></a></h3><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 deploy</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/one-command-deployment.html">Deployment</a></p>]]></content>
</entry>
</search>