-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
475 lines (438 loc) · 35.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="format-detection" content="telephone=no"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><link rel="icon" href="/images/icons/favicon-16x16.png?v=2.3.0" type="image/png" sizes="16x16"><link rel="icon" href="/images/icons/favicon-32x32.png?v=2.3.0" type="image/png" sizes="32x32"><meta property="og:type" content="website">
<meta property="og:title" content="Mutong Notes">
<meta property="og:url" content="https://qponahuijiuy.github.io/index.html">
<meta property="og:site_name" content="Mutong Notes">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="Mutong">
<meta property="article:tag" content="Java,Go,Mac,Linux,生活,life">
<meta name="twitter:card" content="summary"><title>Mutong Notes</title><link ref="canonical" href="https://qponahuijiuy.github.io/index.html"><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css" type="text/css"><link rel="stylesheet" href="/css/index.css?v=2.3.0"><script>var Stun = window.Stun || {};
var CONFIG = {
root: '/',
algolia: undefined,
assistSearch: ["google","bing","baidu"],
fontIcon: {"prompt":{"success":"fas fa-check-circle","info":"fas fa-arrow-circle-right","warning":"fas fa-exclamation-circle","error":"fas fa-times-circle"},"copyBtn":"fas fa-copy"},
sidebar: {"offsetTop":"20px","tocMaxDepth":6},
header: {"enable":true,"showOnPost":true,"scrollDownIcon":false},
postWidget: {"endText":true},
nightMode: {"enable":true},
back2top: {"enable":true},
codeblock: {"style":"carbon","highlight":"light","wordWrap":false},
reward: false,
fancybox: false,
zoomImage: {"gapAside":"20px"},
galleryWaterfall: undefined,
lazyload: false,
pjax: {"avoidBanner":false},
externalLink: {"icon":{"enable":true,"name":"fas fa-external-link-alt"}},
shortcuts: undefined,
prompt: {"copyButton":"复制","copySuccess":"复制成功","copyError":"复制失败"},
sourcePath: {"js":"js","css":"css","images":"images"},
};
window.CONFIG = CONFIG;</script><meta name="generator" content="Hexo 5.2.0"></head><body><div class="container" id="container"><header class="header" id="header"><div class="header-inner"><nav class="header-nav header-nav--fixed"><div class="header-nav-inner"><div class="header-nav-menubtn"><i class="fas fa-bars"></i></div><div class="header-nav-menu"><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/"><span class="header-nav-menu-item__icon"><i class="fas fa-home"></i></span><span class="header-nav-menu-item__text">首页</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/archives/"><span class="header-nav-menu-item__icon"><i class="fas fa-folder-open"></i></span><span class="header-nav-menu-item__text">归档</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/categories/"><span class="header-nav-menu-item__icon"><i class="fas fa-layer-group"></i></span><span class="header-nav-menu-item__text">分类</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/tags/"><span class="header-nav-menu-item__icon"><i class="fas fa-tags"></i></span><span class="header-nav-menu-item__text">标签</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/reading/"><span class="header-nav-menu-item__icon"><i class="fas fa-book"></i></span><span class="header-nav-menu-item__text">阅读</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/about/"><span class="header-nav-menu-item__icon"><i class="fas fa-user"></i></span><span class="header-nav-menu-item__text">关于我</span></a></div></div><div class="header-nav-search"><span class="header-nav-search__icon"><i class="fas fa-search"></i></span><span class="header-nav-search__text">搜索</span></div><div class="header-nav-mode"><div class="mode"><div class="mode-track"><span class="mode-track-moon"></span><span class="mode-track-sun"></span></div><div class="mode-thumb"></div></div></div></div></nav><div class="header-banner"><div class="header-banner-info"><div class="header-banner-info__title">Mutong Notes</div><div class="header-banner-info__subtitle">愿一直遇到有趣的人和事</div></div></div></div></header><main class="main" id="main"><div class="main-inner"><div class="content-wrap" id="content-wrap"><div class="content content-home" id="content"><section class="postlist"><article class="postlist-item post"><header class="post-header"><h1 class="post-title"><a class="post-title__link" href="/posts/d48533bf/">【Java】线程池实现原理以及实践场景</a></h1><div class="post-meta"><span class="post-meta-item post-meta-item--createtime"><span class="post-meta-item__icon"><i class="far fa-calendar-plus"></i></span><span class="post-meta-item__info">发表于</span><span class="post-meta-item__value">2021-02-07</span></span><span class="post-meta-item post-meta-item--updatetime"><span class="post-meta-item__icon"><i class="far fa-calendar-check"></i></span><span class="post-meta-item__info">更新于</span><span class="post-meta-item__value">2021-02-07</span></span></div></header><div class="post-body"><div class="post-excerpt"><h2 id="核心设计与实现" >
<a href="#核心设计与实现" class="heading-link"><i class="fas fa-link"></i></a>核心设计与实现</h2>
<h3 id="UML图" >
<a href="#UML图" class="heading-link"><i class="fas fa-link"></i></a>UML图</h3>
<p>我们首先来看一下 ThreadPoolExecutor 的<br>UML 类图,了解下 ThreadPoolExecutor 的继承关系。<br><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20171124%2F06cef2639f294072820abef52e75a1c7.png&refer=http%3A%2F%2F5b0988e595225.cdn.sohucs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1615099773&t=ad17577c9117ed62adb92ffb8d27e9f2" style="" ><br>·<br>最底层的接口是Executor,它只是提供了一种思想,将任务提交和任务的执行解耦,用户无需关注如何创建线程,如何调度线程来执行任务,用户只需提供 Runnable 对象,将任务的运行逻辑提交到执行器 (Executor) 里面。由 Executor 框架完成线程的调配和任务的执行部分。</p></div><div class="post-readmore"><a class="post-readmore__link" href="/posts/d48533bf/"><span class="post-readmore__text">阅读全文</span><span class="post-readmore__icon"><i class="fas fa-long-arrow-alt-right"></i></span></a></div></div></article><article class="postlist-item post"><header class="post-header"><h1 class="post-title"><a class="post-title__link" href="/posts/94563abb/">【Mysql】索引类型优化策略</a></h1><div class="post-meta"><span class="post-meta-item post-meta-item--createtime"><span class="post-meta-item__icon"><i class="far fa-calendar-plus"></i></span><span class="post-meta-item__info">发表于</span><span class="post-meta-item__value">2021-01-31</span></span><span class="post-meta-item post-meta-item--updatetime"><span class="post-meta-item__icon"><i class="far fa-calendar-check"></i></span><span class="post-meta-item__info">更新于</span><span class="post-meta-item__value">2021-01-31</span></span></div></header><div class="post-body"><div class="post-excerpt"><h2 id="1-索引类型" >
<a href="#1-索引类型" class="heading-link"><i class="fas fa-link"></i></a>1. 索引类型</h2>
<h4 id="1-1-普通索引" >
<a href="#1-1-普通索引" class="heading-link"><i class="fas fa-link"></i></a>1.1 普通索引</h4>
<ul>
<li><p>这是一个最基本的索引类型,基于普通字段建立索引,没有任何限制。</p>
<h4 id="1-2-唯一索引" >
<a href="#1-2-唯一索引" class="heading-link"><i class="fas fa-link"></i></a>1.2 唯一索引</h4>
</li>
<li><p>普通索引允许被索引的数据列包含重复的值</p>
</li>
<li><p>唯一索引就是刚好相反,不允许索引的数据列里面有重复的值。比如说身份证号,那么一定是一个唯一索引。因为不可能有两个人的身份证号一模一样。</p>
<h4 id="1-3-主键索引" >
<a href="#1-3-主键索引" class="heading-link"><i class="fas fa-link"></i></a>1.3 主键索引</h4>
</li>
<li><p>主键索引,只要声明一个主键,系统会为主键自动建立索引</p></div><div class="post-readmore"><a class="post-readmore__link" href="/posts/94563abb/"><span class="post-readmore__text">阅读全文</span><span class="post-readmore__icon"><i class="fas fa-long-arrow-alt-right"></i></span></a></div></div></article><article class="postlist-item post"><header class="post-header"><h1 class="post-title"><a class="post-title__link" href="/posts/268bbe0f/">【Mysql】数据类型范式相关</a></h1><div class="post-meta"><span class="post-meta-item post-meta-item--createtime"><span class="post-meta-item__icon"><i class="far fa-calendar-plus"></i></span><span class="post-meta-item__info">发表于</span><span class="post-meta-item__value">2021-01-31</span></span><span class="post-meta-item post-meta-item--updatetime"><span class="post-meta-item__icon"><i class="far fa-calendar-check"></i></span><span class="post-meta-item__info">更新于</span><span class="post-meta-item__value">2021-01-31</span></span></div></header><div class="post-body"><div class="post-excerpt"><h2 id="1-Mysql范式与反范式" >
<a href="#1-Mysql范式与反范式" class="heading-link"><i class="fas fa-link"></i></a>1.Mysql范式与反范式</h2>
<ul>
<li>我们所了解的,我们在设计数据库的时候会遵循数据库的三大范式,但是,有些时候反范式可以增加某些类型的查询,但同时可能是另外一个类型的查询变慢。比如添加技术表和汇总表是一种很好的优化查询的方式,但是这些表维护起来成本也很高。</li>
<li>范式的优点:<ul>
<li>适用于写操作比较多的场景</li>
<li>范式会使数据库很少或者没有重复数据</li>
</ul>
</li>
<li>范式的缺点:<ul>
<li>通常需要关联查询,而关联查询在某些场景下会使我们的索引失效。</li>
</ul>
</li>
<li>反范式的优点:<ul>
<li>反范式化的schema因为所有数据都在一张表中, 可以很好地避免关联。而我们知道关联表的查询效率是比较差的</li>
<li>反范式的表能够更有效的使用索引策略,</li>
</ul>
</li>
<li>但是在真实的环境中,很少会极端的使用范式或者反范式,一般都是部分是遵循范式,部分是反范式的。</div><div class="post-readmore"><a class="post-readmore__link" href="/posts/268bbe0f/"><span class="post-readmore__text">阅读全文</span><span class="post-readmore__icon"><i class="fas fa-long-arrow-alt-right"></i></span></a></div></div></article><article class="postlist-item post"><header class="post-header"><h1 class="post-title"><a class="post-title__link" href="/posts/65e6743d/">【Go】数组,切片,映射</a></h1><div class="post-meta"><span class="post-meta-item post-meta-item--createtime"><span class="post-meta-item__icon"><i class="far fa-calendar-plus"></i></span><span class="post-meta-item__info">发表于</span><span class="post-meta-item__value">2020-11-29</span></span><span class="post-meta-item post-meta-item--updatetime"><span class="post-meta-item__icon"><i class="far fa-calendar-check"></i></span><span class="post-meta-item__info">更新于</span><span class="post-meta-item__value">2020-11-29</span></span></div></header><div class="post-body"><div class="post-excerpt"><h3 id="1-Array-数组" >
<a href="#1-Array-数组" class="heading-link"><i class="fas fa-link"></i></a>1. Array(数组)</h3>
<h4 id="数组定义" >
<a href="#数组定义" class="heading-link"><i class="fas fa-link"></i></a>数组定义</h4>
<figure class="highlight go"><div class="table-container"><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">//定义一个长度为3,元素类型为int的数组a</span></span><br><span class="line"><span class="keyword">var</span> a [<span class="number">3</span>]<span class="keyword">int</span></span><br><span class="line"><span class="keyword">var</span> b [<span class="number">4</span>]<span class="keyword">string</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//数组可以通过下标进行访问,下标从0开始,最后一个元素的下标为 len-1</span></span><br><span class="line">v := a[<span class="built_in">len</span> - <span class="number">1</span>]</span><br></pre></td></tr></table></div></figure></div><div class="post-readmore"><a class="post-readmore__link" href="/posts/65e6743d/"><span class="post-readmore__text">阅读全文</span><span class="post-readmore__icon"><i class="fas fa-long-arrow-alt-right"></i></span></a></div></div></article><article class="postlist-item post"><header class="post-header"><h1 class="post-title"><a class="post-title__link" href="/posts/6d1fa312/">【Go】结构体,方法,接口</a></h1><div class="post-meta"><span class="post-meta-item post-meta-item--createtime"><span class="post-meta-item__icon"><i class="far fa-calendar-plus"></i></span><span class="post-meta-item__info">发表于</span><span class="post-meta-item__value">2020-11-29</span></span><span class="post-meta-item post-meta-item--updatetime"><span class="post-meta-item__icon"><i class="far fa-calendar-check"></i></span><span class="post-meta-item__info">更新于</span><span class="post-meta-item__value">2020-11-29</span></span></div></header><div class="post-body"><div class="post-excerpt"><h3 id="结构体" >
<a href="#结构体" class="heading-link"><i class="fas fa-link"></i></a>结构体</h3>
<ul>
<li>Go语言是静态类型的语言,编译器需要在编译的时候知道每一个值的类型</li>
<li>提前知道值的类型,可以合理的保存。有助于减少内存异常和Bug。</li>
<li>一般需要知道:分配多少内存给这个值,这段内存表示什么。</li>
</ul></div><div class="post-readmore"><a class="post-readmore__link" href="/posts/6d1fa312/"><span class="post-readmore__text">阅读全文</span><span class="post-readmore__icon"><i class="fas fa-long-arrow-alt-right"></i></span></a></div></div></article><article class="postlist-item post"><header class="post-header"><h1 class="post-title"><a class="post-title__link" href="/posts/2ef729d1/">【Go】变量,常量,基本数据类型</a></h1><div class="post-meta"><span class="post-meta-item post-meta-item--createtime"><span class="post-meta-item__icon"><i class="far fa-calendar-plus"></i></span><span class="post-meta-item__info">发表于</span><span class="post-meta-item__value">2020-11-28</span></span><span class="post-meta-item post-meta-item--updatetime"><span class="post-meta-item__icon"><i class="far fa-calendar-check"></i></span><span class="post-meta-item__info">更新于</span><span class="post-meta-item__value">2020-11-28</span></span></div></header><div class="post-body"><div class="post-excerpt"><h3 id="1-标识符和关键字" >
<a href="#1-标识符和关键字" class="heading-link"><i class="fas fa-link"></i></a>1. 标识符和关键字</h3>
<p>Go语言中的标识符由<strong>字母,数字,下划线_</strong> 组成。但是不能以数字开头</p></div><div class="post-readmore"><a class="post-readmore__link" href="/posts/2ef729d1/"><span class="post-readmore__text">阅读全文</span><span class="post-readmore__icon"><i class="fas fa-long-arrow-alt-right"></i></span></a></div></div></article><article class="postlist-item post"><header class="post-header"><h1 class="post-title"><a class="post-title__link" href="/posts/1d9fbb6a/">Docker基础</a></h1><div class="post-meta"><span class="post-meta-item post-meta-item--createtime"><span class="post-meta-item__icon"><i class="far fa-calendar-plus"></i></span><span class="post-meta-item__info">发表于</span><span class="post-meta-item__value">2020-11-28</span></span><span class="post-meta-item post-meta-item--updatetime"><span class="post-meta-item__icon"><i class="far fa-calendar-check"></i></span><span class="post-meta-item__info">更新于</span><span class="post-meta-item__value">2020-11-28</span></span></div></header><div class="post-body"><div class="post-excerpt"><h3 id="一,Docker概述" >
<a href="#一,Docker概述" class="heading-link"><i class="fas fa-link"></i></a>一,Docker概述</h3>
<p>一款产品,肯定有两种环境,一个开发环境,一个上线环境。开发 ,运维。<br>境配置是十分麻烦的,每一个机器都要去部署环境。费事费力。<br>传统:开发jar,运维来做<br>现在:开发打包部署上线,一套流程做完。打包项目带上环境。</p></div><div class="post-readmore"><a class="post-readmore__link" href="/posts/1d9fbb6a/"><span class="post-readmore__text">阅读全文</span><span class="post-readmore__icon"><i class="fas fa-long-arrow-alt-right"></i></span></a></div></div></article></section><nav class="paginator"><div class="paginator-inner"><span class="page-number current">1</span></div></nav></div></div><div class="sidebar-wrap" id="sidebar-wrap"><aside class="sidebar" id="sidebar"><section class="sidebar-toc hide"></section><!-- ov = overview--><section class="sidebar-ov"><div class="sidebar-ov-author"><div class="sidebar-ov-author__avatar"><img class="sidebar-ov-author__avatar_img" src="/images/icons/2.jpg" alt="avatar"></div><p class="sidebar-ov-author__text">work life balance</p></div><div class="sidebar-ov-social"><a class="sidebar-ov-social-item" href="https://github.com/qponahuijiuy" target="_blank" rel="noopener" data-popover="Github" data-popover-pos="up"><span class="sidebar-ov-social-item__icon"><i class="fab fa-github"></i></span></a><a class="sidebar-ov-social-item" href="1530201142" target="_blank" rel="noopener" data-popover="QQ" data-popover-pos="up"><span class="sidebar-ov-social-item__icon"><i class="fab fa-qq"></i></span></a></div><div class="sidebar-ov-state"><a class="sidebar-ov-state-item sidebar-ov-state-item--posts" href="/archives/"><div class="sidebar-ov-state-item__count">7</div><div class="sidebar-ov-state-item__name">归档</div></a><a class="sidebar-ov-state-item sidebar-ov-state-item--categories" href="/categories/"><div class="sidebar-ov-state-item__count">3</div><div class="sidebar-ov-state-item__name">分类</div></a><a class="sidebar-ov-state-item sidebar-ov-state-item--tags" href="/tags/"><div class="sidebar-ov-state-item__count">4</div><div class="sidebar-ov-state-item__name">标签</div></a></div><div class="sidebar-ov-cc"><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en" target="_blank" rel="noopener" data-popover="知识共享许可协议" data-popover-pos="up"><img src="/images/cc-by-nc-sa.svg"></a></div></section></aside></div><div class="clearfix"></div></div></main><footer class="footer" id="footer"><div class="footer-inner"><div><span>Copyright © 2021</span><span class="footer__icon"><i class="fas fa-heart"></i></span><span>Mutong All Rights Reserved</span></div><div><span>由 <a href="http://hexo.io/" title="Hexo" target="_blank" rel="noopener">Hexo</a> 强力驱动</span><span> v5.2.0</span><span class="footer__devider">|</span><span>主题 - <a href="https://github.com/liuyib/hexo-theme-stun/" title="Stun" target="_blank" rel="noopener">Stun</a></span><span> v2.3.0</span></div><div class="busuanzi"><span class="busuanzi-siteuv"><span class="busuanzi-siteuv__icon"><i class="fas fa-user"></i></span><span class="busuanzi-siteuv__info">访问人数</span><span class="busuanzi-siteuv__value" id="busuanzi_value_site_uv"></span></span><span class="busuanzi-sitepv"><span class="busuanzi-siteuv__icon"><i class="fas fa-eye"></i></span><span class="busuanzi-siteuv__info">浏览总量</span><span class="busuanzi-siteuv__value" id="busuanzi_value_site_pv"></span></span></div></div></footer><div class="loading-bar" id="loading-bar"><div class="loading-bar__progress"></div></div><div class="back2top" id="back2top"><span class="back2top__icon"><i class="fas fa-rocket"></i></span></div></div><div class="search-mask"></div><div class="search-popup"><span class="search-close"></span><div class="search-input"><input placeholder="搜索文章(支持多关键词,请用空格分隔)"><div class="search-btns">使用搜索:<span class="search-btns-item search-btns-item--google"><i class="fab fa-google"></i>谷歌</span><span class="search-btns-item search-btns-item--bing"><i></i>必应</span><span class="search-btns-item search-btns-item--baidu"><i></i>百度</span></div></div><div class="search-results"></div></div><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/[email protected]/velocity.min.js"></script><script src="https://cdn.jsdelivr.net/npm/[email protected]/velocity.ui.min.js"></script><script src="https://cdn.jsdelivr.net/npm/ribbon.js@latest/dist/ribbon.min.js" size="120" alpha="0.6" zIndex="-1"></script><script>function initSearch() {
var isXML = true;
var search_path = 'search.xml';
if (!search_path) {
search_path = 'search.xml';
} else if (/json$/i.test(search_path)) {
isXML = false;
}
var path = '/' + search_path;
$.ajax({
url: path,
dataType: isXML ? 'xml' : 'json',
async: true,
success: function (res) {
var datas = isXML ? $('entry', res).map(function () {
// 将 XML 转为 JSON
return {
title: $('title', this).text(),
content: $('content', this).text(),
url: $('url', this).text()
};
}).get() : res;
var $input = $('.search-input input');
var $result = $('.search-results');
// 搜索对象(标题、内容)的权重,影响显示顺序
var WEIGHT = { title: 100, content: 1 };
var searchPost = function () {
var searchText = $input.val().toLowerCase().trim();
// 根据空白字符分隔关键字
var keywords = searchText.split(/[\s]+/);
// 搜索结果
var matchPosts = [];
// 有多个关键字时,将原文字整个保存下来
if (keywords.length > 1) {
keywords.push(searchText);
}
// 防止未输入字符时搜索
if (searchText.length > 0) {
datas.forEach(function (data) {
var isMatch = false;
// 没有标题的文章使用预设的 i18n 变量代替
var title = (data.title && data.title.trim()) || '[ 文章无标题 ]';
var titleLower = title && title.toLowerCase();
// 删除 HTML 标签 和 所有空白字符
var content = data.content && data.content.replace(/<[^>]+>/g, '');
var contentLower = content && content.toLowerCase();
// 删除重复的 /
var postURL = data.url && decodeURI(data.url).replace(/\/{2,}/g, '/');
// 标题中匹配到的关键词
var titleHitSlice = [];
// 内容中匹配到的关键词
var contentHitSlice = [];
keywords.forEach(function (keyword) {
/**
* 获取匹配的关键词的索引
* @param {String} keyword 要匹配的关键字
* @param {String} text 原文字
* @param {Boolean} caseSensitive 是否区分大小写
* @param {Number} weight 匹配对象的权重。权重大的优先显示
* @return {Array}
*/
function getIndexByword (word, text, caseSensitive, weight) {
if (!word || !text) {
return [];
};
var startIndex = 0; // 每次匹配的开始索引
var index = -1; // 匹配到的索引值
var result = []; // 匹配结果
if (!caseSensitive) {
word = word.toLowerCase();
text = text.toLowerCase();
}
while((index = text.indexOf(word, startIndex)) !== -1) {
var hasMatch = false;
// 索引位置相同的关键词,保留长度较长的
titleHitSlice.forEach(function (hit) {
if (hit.index === index && hit.word.length < word.length) {
hit.word = word;
hasMatch = true;
}
});
startIndex = index + word.length;
!hasMatch && result.push({ index: index, word: word, weight: weight });
}
return result;
}
titleHitSlice = titleHitSlice.concat(getIndexByword(keyword, titleLower, false, WEIGHT.title));
contentHitSlice = contentHitSlice.concat(getIndexByword(keyword, contentLower, false, WEIGHT.content));
});
var hitTitle = titleHitSlice.length;
var hitContent = contentHitSlice.length;
if (hitTitle > 0 || hitContent > 0) {
isMatch = true;
}
if (isMatch) {
;[titleHitSlice, contentHitSlice].forEach(function (hit) {
// 按照匹配文字的索引的递增顺序排序
hit.sort(function (left, right) {
return left.index - right.index;
});
});
/**
* 给文本中匹配到的关键词添加标记,从而进行高亮显示
* @param {String} text 原文本
* @param {Array} hitSlice 匹配项的索引信息
* @param {Number} start 开始索引
* @param {Number} end 结束索引
* @return {String}
*/
function highlightKeyword (text, hitSlice, start, end) {
if (!text || !hitSlice || !hitSlice.length) {
return;
}
var result = '';
var startIndex = start;
var endIndex = end;
hitSlice.forEach(function (hit) {
if (hit.index < startIndex) {
return;
}
var hitWordEnd = hit.index + hit.word.length;
result += text.slice(startIndex, hit.index);
result += '<b>' + text.slice(hit.index, hitWordEnd) + '</b>';
startIndex = hitWordEnd;
});
result += text.slice(startIndex, endIndex);
return result;
}
var postData = {};
// 文章总的搜索权重
var postWeight = titleHitSlice.length * WEIGHT.title + contentHitSlice.length * WEIGHT.content;
// 标记匹配关键词后的标题
var postTitle = highlightKeyword(title, titleHitSlice, 0, title.length) || title;
// 标记匹配关键词后的内容
var postContent;
// 显示内容的长度
var SHOW_WORD_LENGTH = 200;
// 命中关键词前的字符显示长度
var SHOW_WORD_FRONT_LENGTH = 20;
var SHOW_WORD_END_LENGTH = SHOW_WORD_LENGTH - SHOW_WORD_FRONT_LENGTH;
// 截取匹配的第一个字符,前后共 200 个字符来显示
if (contentHitSlice.length > 0) {
var firstIndex = contentHitSlice[0].index;
var start = firstIndex > SHOW_WORD_FRONT_LENGTH ? firstIndex - SHOW_WORD_FRONT_LENGTH : 0;
var end = firstIndex + SHOW_WORD_END_LENGTH;
postContent = highlightKeyword(content, contentHitSlice, start, end);
} else { // 未匹配到内容,直接截取前 200 个字符来显示
postContent = content.slice(0, SHOW_WORD_LENGTH);
}
postData.title = postTitle;
postData.content = postContent;
postData.url = postURL;
postData.weight = postWeight;
matchPosts.push(postData);
}
});
}
var resultInnerHtml = '';
if (matchPosts.length) {
// 按权重递增的顺序排序,使权重大的优先显示
matchPosts.sort(function (left, right) {
return right.weight - left.weight;
});
resultInnerHtml += '<ul>';
matchPosts.forEach(function (post) {
resultInnerHtml += '<li><a class="search-results-title" href="' + post.url + '">';
resultInnerHtml += post.title;
resultInnerHtml += '</a><div class="search-results-content">';
resultInnerHtml += post.content;
resultInnerHtml += '</div></li>';
});
resultInnerHtml += '</ul>';
} else {
resultInnerHtml += '<div class="search-results-none"><i class="far fa-meh"></i></div>';
}
$result.html(resultInnerHtml);
};
$input.on('input', searchPost);
$input.on('keyup', function (e) {
if (e.keyCode === Stun.utils.codeToKeyCode('Enter')) {
searchPost();
}
});
}
});
}
function closeSearch () {
$('body').css({ overflow: 'auto' });
$('.search-popup').css({ display: 'none' });
$('.search-mask').css({ display: 'none' });
}
window.addEventListener('DOMContentLoaded', function () {
Stun.utils.pjaxReloadLocalSearch = function () {
$('.header-nav-search').on('click', function (e) {
e.stopPropagation();
$('body').css('overflow', 'hidden');
$('.search-popup')
.velocity('stop')
.velocity('transition.expandIn', {
duration: 300,
complete: function () {
$('.search-popup input').focus();
}
});
$('.search-mask')
.velocity('stop')
.velocity('transition.fadeIn', {
duration: 300
});
initSearch();
});
$('.search-mask, .search-close').on('click', function () {
closeSearch();
});
$(document).on('keydown', function (e) {
// Escape <=> 27
if (e.keyCode === Stun.utils.codeToKeyCode('Escape')) {
closeSearch();
}
});
};
Stun.utils.pjaxReloadLocalSearch();
}, false);
function safeOpenUrl(url) {
var newTab = window.open();
newTab.opener = null;
newTab.location = url;
}
function extSearch(engine) {
var engines = {
google: 'https://www.google.com/search?q=',
bing: 'https://cn.bing.com/search?q=',
baidu: 'https://www.baidu.com/s?ie=UTF-8&wd=',
};
var host = window.location.host;
var query = $('.search-input input').val().toLowerCase().trim();
var uri = engines[engine] + query + ' site:' + host;
if (query) {
safeOpenUrl(uri);
} else {
Stun.utils.popAlert('warning', '请输入字符');
}
}
var assistSearchList = window.CONFIG.assistSearch;
if (Array.isArray(assistSearchList)) {
assistSearchList.forEach(function (name) {
document.querySelector('.search-btns-item--' + name).addEventListener('click', function () {
extSearch(name);
}, false);
});
}</script><script src="https://cdn.jsdelivr.net/npm/pjax@latest/pjax.min.js"></script><script>window.addEventListener('DOMContentLoaded', function () {
var pjax = new Pjax({"selectors":["head title","#main",".pjax-reload"],"history":true,"scrollTo":false,"scrollRestoration":false,"cacheBust":false,"debug":false,"currentUrlFullReload":false,"timeout":0});
// 加载进度条的计时器
var loadingTimer = null;
// 重置页面 Y 方向上的滚动偏移量
document.addEventListener('pjax:send', function () {
$('.header-nav-menu').removeClass('show');
if (CONFIG.pjax && CONFIG.pjax.avoidBanner) {
$('html').velocity('scroll', {
duration: 500,
offset: $('#header').height(),
easing: 'easeInOutCubic'
});
}
var loadingBarWidth = 20;
var MAX_LOADING_WIDTH = 95;
$('.loading-bar').addClass('loading');
$('.loading-bar__progress').css('width', loadingBarWidth + '%');
clearInterval(loadingTimer);
loadingTimer = setInterval(function () {
loadingBarWidth += 3;
if (loadingBarWidth > MAX_LOADING_WIDTH) {
loadingBarWidth = MAX_LOADING_WIDTH;
}
$('.loading-bar__progress').css('width', loadingBarWidth + '%');
}, 500);
}, false);
window.addEventListener('pjax:complete', function () {
clearInterval(loadingTimer);
$('.loading-bar__progress').css('width', '100%');
$('.loading-bar').removeClass('loading');
setTimeout(function () {
$('.loading-bar__progress').css('width', '0');
}, 400);
$('link[rel=prefetch], script[data-pjax-rm]').each(function () {
$(this).remove();
});
$('script[data-pjax], #pjax-reload script').each(function () {
$(this).parent().append($(this).remove());
});
if (Stun.utils.pjaxReloadBoot) {
Stun.utils.pjaxReloadBoot();
}
if (Stun.utils.pjaxReloadScroll) {
Stun.utils.pjaxReloadScroll();
}
if (Stun.utils.pjaxReloadSidebar) {
Stun.utils.pjaxReloadSidebar();
}
if (false) {
if (Stun.utils.pjaxReloadHeader) {
Stun.utils.pjaxReloadHeader();
}
if (Stun.utils.pjaxReloadScrollIcon) {
Stun.utils.pjaxReloadScrollIcon();
}
if (Stun.utils.pjaxReloadLocalSearch) {
Stun.utils.pjaxReloadLocalSearch();
}
}
}, false);
}, false);</script><div id="pjax-reload"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/quicklink.umd.js"></script><script>function initQuicklink() {
quicklink({
timeout: '10000',
priority: true,
ignores: [uri => uri.includes('#'), uri => uri === 'https://qponahuijiuy.github.io/', /\/api\/?/,uri => uri.includes('.xml'),uri => uri.includes('.zip'),(uri, el) => el.hasAttribute('nofollow'),(uri, el) => el.hasAttribute('noprefetch')]
});
}
if (true || false) {
initQuicklink();
} else {
window.addEventListener('DOMContentLoaded', initQuicklink, false);
}</script><script src="https://cdn.jsdelivr.net/gh/sukkaw/busuanzi@latest/bsz.pure.mini.js" async></script></div><script data-pjax="">function loadDisqus () {
if (!document.getElementById('disqus_thread')) {
return;
}
if (window.DISQUS) {
DISQUS.reset({
reload: true,
config: function () {
this.page.url = '';
this.page.identifier = 'index.html';
this.page.title = '';
}
});
} else {
var d = document;
var sc = d.createElement('script');
var se = d.createElement('script');
if (true) {
sc.src = 'https://.disqus.com/count.js';
sc.id = 'dsq-count-scr';
sc.async = true;
if (true) {
sc.setAttribute('data-pjax', '');
}
(d.head || d.body).appendChild(sc);
}
se.src = 'https://.disqus.com/embed.js';
(d.head || d.body).appendChild(se);
}
}
if (true) {
loadDisqus();
} else {
window.addEventListener('DOMContentLoaded', loadDisqus, false);
}</script><script src="/js/utils.js?v=2.3.0"></script><script src="/js/stun-boot.js?v=2.3.0"></script><script src="/js/scroll.js?v=2.3.0"></script><script src="/js/header.js?v=2.3.0"></script><script src="/js/sidebar.js?v=2.3.0"></script><script type="application/json" src="/search.xml"></script></body></html>