jekyll-theme-materialize 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54a0458ded3f011b8552edad9bf06fb7a3d666f9
4
- data.tar.gz: b51d17e5a06400457c7b8d9fefef3e99265e7761
3
+ metadata.gz: fec8da7817375be0eb1e3e2647e54322bb22b1b7
4
+ data.tar.gz: 4567120597f732ce0b55caf2d23b4723a4e5dec5
5
5
  SHA512:
6
- metadata.gz: 831fc071affc542ec76d298ec616f2221310c60a350a7ab4a7135214f2d5c6f8279ab016a24d7002285dea3ce81e094b8f80ae2655a2fe6c218c00ac6298f1a9
7
- data.tar.gz: 194b40d09e88ef090ed3a3f54c05cfe68d9ab8e8c22527ecdd7bc40d30c0c44264e0d57e8b4ff47b33d29fe5aec3de313b6561e23c8d4052e5367b905ea3e837
6
+ metadata.gz: 241120ef8c78b0ed39e13caaff40f201061add6e2b74ad66a5b825afe8745513782bdee4fec8b0e1de1f54f0afe69f3574c28e47a6b8b8fe0e27f086a17332f5
7
+ data.tar.gz: 2aa4421e686ccb4c869930bdff9a971e53f813ef158d7a5ac46a80063575788e5e108b72244a63f1b1de7a6da42670085fa96cffca8e504749d256c4c34eee74
data/README.md CHANGED
@@ -1,18 +1,26 @@
1
1
  # jekyll-theme-materialize
2
2
 
3
- travis-ci:[![Build Status](https://travis-ci.org/KeJunMao/jekyll-theme-materialize.svg?branch=master)](https://travis-ci.org/KeJunMao/jekyll-theme-materialize)
3
+ [![Build Status](https://travis-ci.org/KeJunMao/jekyll-theme-materialize.svg?branch=master)](https://travis-ci.org/KeJunMao/jekyll-theme-materialize)
4
4
 
5
- jekyll-theme-materialize:[![jekyll-theme-materialize Version](https://badge.fury.io/rb/jekyll-theme-materialize.svg)](https://badge.fury.io/rb/jekyll-theme-materialize)
5
+ [![jekyll-theme-materialize Version](https://badge.fury.io/rb/jekyll-theme-materialize.svg)](https://badge.fury.io/rb/jekyll-theme-materialize)
6
6
 
7
- jekyll-lunr-js-search:[![jekyll-lunr-js-search Version](https://badge.fury.io/rb/jekyll-lunr-js-search.svg)](https://badge.fury.io/rb/jekyll-lunr-js-search)
7
+ [![jekyll-lunr-js-search Version](https://badge.fury.io/rb/jekyll-lunr-js-search.svg)](https://badge.fury.io/rb/jekyll-lunr-js-search)
8
8
 
9
9
  ## 预览
10
10
 
11
11
  [coding page(中国)](http://KeJun.coding.me/jekyll-theme-materialize-site/)
12
- [github page](https://kejunmao.github.io/jekyll-theme-materialize-site/)
12
+ [github page](https://kejunmao.github.io/jekyll-theme-materialize/)
13
13
 
14
14
  ## 安装
15
15
 
16
+ 有两种安装方法,一种是gem安装,另一种是`git clone`。
17
+
18
+ > 建议您使用git clone的方法安装。
19
+
20
+ ### 使用gem
21
+
22
+ 若使用gem,您需要手动新建一些文件,和文件夹,如`links.md`、`_data`等
23
+
16
24
  添加下行到你 Jekyll 的 `Gemfile`文件中:
17
25
 
18
26
  ```ruby
@@ -27,9 +35,6 @@ gem "jekyll-lunr-js-search"
27
35
  ```yaml
28
36
  #启用主题
29
37
  theme: jekyll-theme-materialize
30
- #启用搜索
31
- gems: ['jekyll-lunr-js-search']
32
- ```
33
38
 
34
39
  然后执行:
35
40
 
@@ -39,6 +44,15 @@ gems: ['jekyll-lunr-js-search']
39
44
 
40
45
  $ gem install jekyll-theme-materialize
41
46
 
47
+ ```
48
+
49
+ ### 使用git
50
+
51
+ $ git clone https://github.com/KeJunMao/jekyll-theme-materialize.git
52
+ $ cd jekyll-theme-materialize
53
+ $ bundle install
54
+ $ bundle exec jekyll s -w
55
+
42
56
  ## 用法
43
57
 
44
58
  将如下内容添加到你Jekyll 的`_config.yml`文件中,请注意替换为你自己的信息:
@@ -75,7 +89,7 @@ disqus-shortname: blog-kejun-tk #disqus shortname
75
89
  ```yaml
76
90
  ---
77
91
  layout: post # 指定模板
78
- categories: NoImage # 分类,首页显示,该项经常用于检测是否为post
92
+ categories: NoImage # 分类,首页显示,该项经常用于检测是否为post。请注意,每个文章仅支持一个分类。
79
93
  image: # 图像,用于首页,若留空将以NoImage的形式显示
80
94
  tags: jekyll ubuntu # 标签,用于tags页面,允许多个
81
95
  toc: * # 确定是否显示toc目录,默认为不显示。
@@ -83,6 +97,48 @@ comments: true # 是否显示评论
83
97
  ---
84
98
  ```
85
99
 
100
+ 请注意jekyll根目录下的`.md`文件的`layout`与`_layout`文件下的文件对应.如:
101
+
102
+ * `index.md`
103
+
104
+ ```yaml
105
+ ---
106
+ layout: index
107
+ ---
108
+ ```
109
+
110
+ * `links.md`
111
+
112
+ ```yaml
113
+ ---
114
+ layout: links
115
+ ---
116
+ ```
117
+
118
+ * `tags.md`
119
+
120
+ ```yaml
121
+ ---
122
+ layout: tags
123
+ ---
124
+ ```
125
+
126
+ * `about.md`
127
+
128
+ ```yaml
129
+ ---
130
+ layout: about
131
+ ---
132
+ ```
133
+
134
+ * `archive.md`
135
+
136
+ ```yaml
137
+ ---
138
+ layout: archive
139
+ ---
140
+ ```
141
+
86
142
  如需新增page,建议按:
87
143
 
88
144
  * 根目录新建 `pageName.md`,并在头信息中键入如下:
@@ -91,7 +147,7 @@ comments: true # 是否显示评论
91
147
  ---
92
148
  title: pageName # 标题
93
149
  layout: pageName # 模板,建议为标题或文件名,若以文章形式输出,layout 填写 about 并编辑该.md文件即可,无需下一步 。
94
- describe: pageName page # 描述
150
+ describe: pageName # 描述
95
151
  toc: * # 确定是否显示toc目录。
96
152
  comments: true # 是否显示评论
97
153
  ---
@@ -121,8 +177,39 @@ layout: default
121
177
  footer的各种站点URL,请按如下格式填写至`_data/myherfs.yml`的url即可,!请勿更改name!:
122
178
 
123
179
  ```yaml
180
+ # 请不要填写太多否则会很丑。
181
+ - name: twitter
182
+ url: https://twitter.com/yrmkejun
183
+
184
+ - name: facebook
185
+ url:
186
+
187
+ - name: weibo
188
+ url:
189
+
190
+ - name: instagram
191
+ url:
192
+
193
+ - name: tumblr
194
+ url:
195
+
124
196
  - name: github
125
- url: http://gihub.com
197
+ url: https://github.com/KeJunMao
198
+
199
+ - name: linkedin
200
+ url:
201
+
202
+ - name: zhihu
203
+ url:
204
+
205
+ - name: bilibili
206
+ url:
207
+
208
+ - name: telegram
209
+ url:
210
+
211
+ - name: gplus
212
+ url:
126
213
  ```
127
214
 
128
215
  若想要自定义顺序,你可以调整他们的整体顺序。
@@ -149,8 +236,8 @@ footer的各种站点URL,请按如下格式填写至`_data/myherfs.yml`的url即
149
236
  * disqus # 完成,努力实现home和archive评论
150
237
  * toc # 完成
151
238
  * 图像加载动画 # 完成
239
+ * 搜索 # 完成,支持中文,能对文章标题,日期,标签搜索,不再依赖插件
152
240
  * 二次元化选项 # 二次元最棒惹~
153
- * 搜索 # 完成(仅支持英文),若需自定义,请访问:https://github.com/slashdotdash/jekyll-lunr-js-search
154
241
 
155
242
  ## License
156
243
 
data/_data/links.yml CHANGED
@@ -1,19 +1,19 @@
1
1
  - name: 剑雨、幽魂
2
- image: images/links/jianyuyouhun.jpg
2
+ image: assets/images/links/jianyuyouhun.jpg
3
3
  url: http://jianyuyouhun.com/
4
4
  describe: 前往安卓大神之路
5
5
 
6
6
  - name: Parallel
7
- image: images/links/parallel.jpg
7
+ image: assets/images/links/parallel.jpg
8
8
  url: https://swumao.github.io/
9
9
  describe: 茂同学
10
10
 
11
11
  - name: viosey
12
- image: images/links/viosey.png
12
+ image: assets/images/links/viosey.png
13
13
  url: https://blog.viosey.com/
14
14
  describe: 一生想做自由 Geek
15
15
 
16
16
  - name: Halyul
17
- image: images/links/halyul.png
17
+ image: assets/images/links/halyul.png
18
18
  url: https://halyul.com/
19
19
  describe: Material Design爱好者
@@ -27,9 +27,8 @@
27
27
  {% endif %} {% endif %} {% endfor %}
28
28
  <li class="nav-search">
29
29
  <div class="nav-search-wrapper">
30
- <input id="nav-search"><i class="search material-icons">search</i>
31
- <div id="nav-search-results" class="nav-search-results card">
32
-
30
+ <div>
31
+ <input class="cb-search-content" id="cb-search-content" placeholder="文章标题 日期 标签" ><i class="search material-icons">search</i>
33
32
  </div>
34
33
  </div>
35
34
  </li>
@@ -105,7 +104,7 @@
105
104
  <form action="{{ page.url | replace:'index.html','' | prepend: site.baseurl | prepend: site.url }}" method="get">
106
105
  <div class="input-field">
107
106
  <!--<input type="text" id="search-query" name="q" placeholder="Search" autocomplete="off">-->
108
- <input id="search-query" type="search" required name="q" placeholder="Search" autocomplete="off">
107
+ <input class="cb-search-content" type="search" required name="q" placeholder="Search" autocomplete="off">
109
108
  <label class="label-icon" for="search"><i class="material-icons">search</i></label>
110
109
  <i class="material-icons">close</i>
111
110
  </div>
@@ -1,27 +1,38 @@
1
-
2
1
  <script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
3
- <script type="text/javascript" src="{{ "/js/search.min.js" | prepend: site.baseurl }}" ></script>
4
2
  <script type="text/javascript" src="{{ "/assets/js/materialize.min.js" | prepend: site.baseurl }}"></script>
5
3
  <script type="text/javascript" src="{{ "/assets/js/jquery.scrollToTop.min.js" | prepend: site.baseurl }}"></script>
6
4
  <script type="text/javascript" src="{{ "/assets/js/gallery.min.opt.js" | prepend: site.baseurl }}"></script>
7
5
  <script type="text/javascript" src="{{ "/assets/js/jquery.lazyload.min.js" | prepend: site.baseurl }}"></script>
8
6
  <script type="text/javascript" src="{{ "/assets/js/toc.js" | prepend: site.baseurl }}"></script>
9
7
  <script type="text/javascript" src="{{ "/assets/js/main.js" | prepend: site.baseurl }}"></script>
10
- <script type="text/javascript">
11
- $(function() {
12
- $('#search-query').lunrSearch({
13
- indexUrl : '{{ "/js/index.json" | prepend: site.baseurl }}', // url for the .json file containing search index data
14
- results : '#search-results', // selector for containing search results element
15
- template : '#search-results-template', // selector for Mustache.js template
16
- titleMsg : '<li><a class="subheader">Search results</a></li>', // message attached in front of results (can be empty)
17
- emptyMsg : '<li><a class="subheader">Nothing found.</a></li>' // shown message if search returns no results
18
- });
19
- $('#nav-search').lunrSearch({
20
- indexUrl : '{{ "/js/index.json" | prepend: site.baseurl }}', // url for the .json file containing search index data
21
- results : '#nav-search-results', // selector for containing search results element
22
- template : '#search-results-nav', // selector for Mustache.js template
23
- titleMsg : '', // message attached in front of results (can be empty)
24
- emptyMsg : '<li class="post-list"><a class="subheader black-text center">Nothing found.</a></li>' // shown message if search returns no results
8
+ <script type="text/javascript" src="{{ "/assets/js/bootstrap3-typeahead.min.js" | prepend: site.baseurl }}"></script>
9
+ <!--<script type="text/javascript" src="{{ "/assets/js/cb-search.js" | prepend: site.baseurl }}"></script>-->
10
+ <script>
11
+ $(document).ready(function () {
12
+ var time1 = 0;
13
+ var show = false;
14
+ var names = new Array(); //文章名字等
15
+ var urls = new Array(); //文章地址
16
+ $.getJSON("{{"/assets/cb-search.json"| prepend: site.baseurl}}").done(function (data) {
17
+ if (data.code == 0) {
18
+ for (var index in data.data) {
19
+ var item = data.data[index];
20
+ names.push(item.title);
21
+ urls.push(item.url);
22
+ }
23
+
24
+ $(".cb-search-content").typeahead({
25
+ source: names,
26
+
27
+ afterSelect: function (item) {
28
+ $(".cb-search-tool").css("display", "none");
29
+ show = false;
30
+ window.location.href = (urls[names.indexOf(item)]);
31
+ return item;
32
+ }
33
+ });
34
+ }
35
+ }).error(function(data, b) { console.log("json解析错误,搜索功能暂不可用,请检查文章title,确保不含有换行等特殊符号"); });
25
36
  });
26
- });
37
+
27
38
  </script>
File without changes
@@ -0,0 +1,17 @@
1
+ ---
2
+ layout: null
3
+ ---
4
+ {
5
+ "code" : 0 ,
6
+ "data" : [
7
+ {% for post in site.posts %}
8
+ {
9
+ "title" : "{{ post.title }}-{% for tag in post.tags %}{% if forloop.rindex != 1 %}{{ tag }}_{% else %}{{ tag }}{% endif %}{% endfor %}",
10
+ "url" : "{{ post.url | prepend: site.baseurl }}"
11
+ }
12
+ {% if forloop.rindex != 1 %}
13
+ ,
14
+ {% endif %}
15
+ {% endfor %}
16
+ ]
17
+ }
data/assets/css/main.css CHANGED
@@ -60,7 +60,7 @@
60
60
  display: block;
61
61
  font-size: 16px;
62
62
  font-weight: 300;
63
- width: 100%;
63
+ width: 265px;
64
64
  height: 45px;
65
65
  margin: 0;
66
66
  padding: 0 45px 0 15px;
@@ -105,4 +105,13 @@
105
105
  }
106
106
  .copyright-row{
107
107
  margin-bottom: 0px;
108
+ }
109
+ .search-strong{
110
+ font-weight: bold;
111
+ }
112
+ .nav-search-wrapper div.card{
113
+ width: 250px;
114
+ }
115
+ .input-field div.card{
116
+ width: 100%;
108
117
  }
@@ -0,0 +1,605 @@
1
+ /* =============================================================
2
+ * bootstrap3-typeahead.js v4.0.2
3
+ * https://github.com/bassjobsen/Bootstrap-3-Typeahead
4
+ * =============================================================
5
+ * Original written by @mdo and @fat
6
+ * =============================================================
7
+ * Copyright 2014 Bass Jobsen @bassjobsen
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the 'License');
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an 'AS IS' BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ * ============================================================ */
21
+
22
+
23
+ (function (root, factory) {
24
+
25
+ 'use strict';
26
+
27
+ // CommonJS module is defined
28
+ if (typeof module !== 'undefined' && module.exports) {
29
+ module.exports = factory(require('jquery'));
30
+ }
31
+ // AMD module is defined
32
+ else if (typeof define === 'function' && define.amd) {
33
+ define(['jquery'], function ($) {
34
+ return factory ($);
35
+ });
36
+ } else {
37
+ factory(root.jQuery);
38
+ }
39
+
40
+ }(this, function ($) {
41
+
42
+ 'use strict';
43
+ // jshint laxcomma: true
44
+
45
+
46
+ /* TYPEAHEAD PUBLIC CLASS DEFINITION
47
+ * ================================= */
48
+
49
+ var Typeahead = function (element, options) {
50
+ this.$element = $(element);
51
+ this.options = $.extend({}, Typeahead.defaults, options);
52
+ this.matcher = this.options.matcher || this.matcher;
53
+ this.sorter = this.options.sorter || this.sorter;
54
+ this.select = this.options.select || this.select;
55
+ this.autoSelect = typeof this.options.autoSelect == 'boolean' ? this.options.autoSelect : true;
56
+ this.highlighter = this.options.highlighter || this.highlighter;
57
+ this.render = this.options.render || this.render;
58
+ this.updater = this.options.updater || this.updater;
59
+ this.displayText = this.options.displayText || this.displayText;
60
+ this.source = this.options.source;
61
+ this.delay = this.options.delay;
62
+ this.$menu = $(this.options.menu);
63
+ this.$appendTo = this.options.appendTo ? $(this.options.appendTo) : null;
64
+ this.fitToElement = typeof this.options.fitToElement == 'boolean' ? this.options.fitToElement : false;
65
+ this.shown = false;
66
+ this.listen();
67
+ this.showHintOnFocus = typeof this.options.showHintOnFocus == 'boolean' || this.options.showHintOnFocus === "all" ? this.options.showHintOnFocus : false;
68
+ this.afterSelect = this.options.afterSelect;
69
+ this.addItem = false;
70
+ this.value = this.$element.val() || this.$element.text();
71
+ this.keyPressed = false;
72
+ };
73
+
74
+ Typeahead.prototype = {
75
+
76
+ constructor: Typeahead,
77
+
78
+ select: function () {
79
+ var val = this.$menu.find('.active').data('value');
80
+ this.$element.data('active', val);
81
+ if (this.autoSelect || val) {
82
+ var newVal = this.updater(val);
83
+ // Updater can be set to any random functions via "options" parameter in constructor above.
84
+ // Add null check for cases when updater returns void or undefined.
85
+ if (!newVal) {
86
+ newVal = '';
87
+ }
88
+ this.$element
89
+ .val(this.displayText(newVal) || newVal)
90
+ .text(this.displayText(newVal) || newVal)
91
+ .change();
92
+ this.afterSelect(newVal);
93
+ }
94
+ return this.hide();
95
+ },
96
+
97
+ updater: function (item) {
98
+ return item;
99
+ },
100
+
101
+ setSource: function (source) {
102
+ this.source = source;
103
+ },
104
+
105
+ show: function () {
106
+ var pos = $.extend({}, this.$element.position(), {
107
+ height: this.$element[0].offsetHeight
108
+ });
109
+
110
+ var scrollHeight = typeof this.options.scrollHeight == 'function' ?
111
+ this.options.scrollHeight.call() :
112
+ this.options.scrollHeight;
113
+
114
+ var element;
115
+ if (this.shown) {
116
+ element = this.$menu;
117
+ } else if (this.$appendTo) {
118
+ element = this.$menu.appendTo(this.$appendTo);
119
+ this.hasSameParent = this.$appendTo.is(this.$element.parent());
120
+ } else {
121
+ element = this.$menu.insertAfter(this.$element);
122
+ this.hasSameParent = true;
123
+ }
124
+
125
+ if (!this.hasSameParent) {
126
+ // We cannot rely on the element position, need to position relative to the window
127
+ element.css("position", "fixed");
128
+ var offset = this.$element.offset();
129
+ pos.top = offset.top;
130
+ pos.left = offset.left;
131
+ }
132
+ // The rules for bootstrap are: 'dropup' in the parent and 'dropdown-menu-right' in the element.
133
+ // Note that to get right alignment, you'll need to specify `menu` in the options to be:
134
+ // '<ul class="typeahead dropdown-menu" role="listbox"></ul>'
135
+ var dropup = $(element).parent().hasClass('dropup');
136
+ var newTop = "";
137
+ var right = $(element).hasClass('dropdown-menu-right');
138
+ var newLeft = "";
139
+ // it seems like setting the css is a bad idea (just let Bootstrap do it), but I'll keep the old
140
+ // logic in place except for the dropup/right-align cases.
141
+ element.css({ top: newTop, left: newLeft }).show();
142
+
143
+ if (this.options.fitToElement === true) {
144
+ element.css("width", this.$element.outerWidth() + "px");
145
+ }
146
+
147
+ this.shown = true;
148
+ return this;
149
+ },
150
+
151
+ hide: function () {
152
+ this.$menu.hide();
153
+ this.shown = false;
154
+ return this;
155
+ },
156
+
157
+ lookup: function (query) {
158
+ var items;
159
+ if (typeof(query) != 'undefined' && query !== null) {
160
+ this.query = query;
161
+ } else {
162
+ this.query = this.$element.val() || this.$element.text() || '';
163
+ }
164
+
165
+ if (this.query.length < this.options.minLength && !this.options.showHintOnFocus) {
166
+ return this.shown ? this.hide() : this;
167
+ }
168
+
169
+ var worker = $.proxy(function () {
170
+
171
+ // Bloodhound (since 0.11) needs three arguments.
172
+ // Two of them are callback functions (sync and async) for local and remote data processing
173
+ // see https://github.com/twitter/typeahead.js/blob/master/src/bloodhound/bloodhound.js#L132
174
+ if ($.isFunction(this.source) && this.source.length === 3) {
175
+ this.source(this.query, $.proxy(this.process, this), $.proxy(this.process, this));
176
+ } else if ($.isFunction(this.source)) {
177
+ this.source(this.query, $.proxy(this.process, this));
178
+ } else if (this.source) {
179
+ this.process(this.source);
180
+ }
181
+ }, this);
182
+
183
+ clearTimeout(this.lookupWorker);
184
+ this.lookupWorker = setTimeout(worker, this.delay);
185
+ },
186
+
187
+ process: function (items) {
188
+ var that = this;
189
+
190
+ items = $.grep(items, function (item) {
191
+ return that.matcher(item);
192
+ });
193
+
194
+ items = this.sorter(items);
195
+
196
+ if (!items.length && !this.options.addItem) {
197
+ return this.shown ? this.hide() : this;
198
+ }
199
+
200
+ if (items.length > 0) {
201
+ this.$element.data('active', items[0]);
202
+ } else {
203
+ this.$element.data('active', null);
204
+ }
205
+
206
+ if (this.options.items != 'all') {
207
+ items = items.slice(0, this.options.items);
208
+ }
209
+
210
+ // Add item
211
+ if (this.options.addItem){
212
+ items.push(this.options.addItem);
213
+ }
214
+
215
+ return this.render(items).show();
216
+ },
217
+
218
+ matcher: function (item) {
219
+ var it = this.displayText(item);
220
+ return ~it.toLowerCase().indexOf(this.query.toLowerCase());
221
+ },
222
+
223
+ sorter: function (items) {
224
+ var beginswith = [];
225
+ var caseSensitive = [];
226
+ var caseInsensitive = [];
227
+ var item;
228
+
229
+ while ((item = items.shift())) {
230
+ var it = this.displayText(item);
231
+ if (!it.toLowerCase().indexOf(this.query.toLowerCase())) beginswith.push(item);
232
+ else if (~it.indexOf(this.query)) caseSensitive.push(item);
233
+ else caseInsensitive.push(item);
234
+ }
235
+
236
+ return beginswith.concat(caseSensitive, caseInsensitive);
237
+ },
238
+
239
+ highlighter: function (item) {
240
+ var text = this.query;
241
+ if(text===""){
242
+ return item;
243
+ }
244
+ var matches = item.match(/(>)([^<]*)(<)/g);
245
+ var first = [];
246
+ var second = [];
247
+ var i;
248
+ if(matches && matches.length){
249
+ //html
250
+ for (i = 0; i < matches.length; ++i) {
251
+ if (matches[i].length > 2) {//escape '><'
252
+ first.push(matches[i]);
253
+ }
254
+ }
255
+ }else{
256
+ //text
257
+ first = [];
258
+ first.push(item);
259
+ }
260
+
261
+ var reg = new RegExp(text, "g");
262
+ var m;
263
+ for (i = 0; i < first.length; ++i) {
264
+ m = first[i].match(reg);
265
+ if(m && m.length>0){//find all text nodes matches
266
+ second.push(first[i]);
267
+ }
268
+ }
269
+ for (i = 0; i < second.length; ++i) {
270
+ item = item.replace(second[i],second[i].replace(reg, '<strong class="search-strong">$&</strong>'));
271
+ }
272
+ return item;
273
+ },
274
+
275
+ render: function (items) {
276
+ var that = this;
277
+ var self = this;
278
+ var activeFound = false;
279
+ var data = [];
280
+ var _category = that.options.separator;
281
+
282
+ $.each(items, function (key,value) {
283
+ // inject separator
284
+ if (key > 0 && value[_category] !== items[key - 1][_category]){
285
+ data.push({
286
+ __type: 'divider'
287
+ });
288
+ }
289
+
290
+ // inject category header
291
+ if (value[_category] && (key === 0 || value[_category] !== items[key - 1][_category])){
292
+ data.push({
293
+ __type: 'category',
294
+ name: value[_category]
295
+ });
296
+ }
297
+ data.push(value);
298
+ });
299
+
300
+ items = $(data).map(function (i, item) {
301
+ if ((item.__type || false) == 'category'){
302
+ return $(that.options.headerHtml).text(item.name)[0];
303
+ }
304
+
305
+ if ((item.__type || false) == 'divider'){
306
+ return $(that.options.headerDivider)[0];
307
+ }
308
+
309
+ var text = self.displayText(item);
310
+ i = $(that.options.item).data('value', item);
311
+ i.find('a').html(that.highlighter(text, item));
312
+ if (text == self.$element.val()) {
313
+ i.addClass('active');
314
+ self.$element.data('active', item);
315
+ activeFound = true;
316
+ }
317
+ return i[0];
318
+ });
319
+
320
+ if (this.autoSelect && !activeFound) {
321
+ items.filter(':not(.dropdown-header)').first().addClass('active');
322
+ this.$element.data('active', items.first().data('value'));
323
+ }
324
+ this.$menu.html(items);
325
+ return this;
326
+ },
327
+
328
+ displayText: function (item) {
329
+ return typeof item !== 'undefined' && typeof item.name != 'undefined' ? item.name : item;
330
+ },
331
+
332
+ next: function (event) {
333
+ var active = this.$menu.find('.active').removeClass('active');
334
+ var next = active.next();
335
+
336
+ if (!next.length) {
337
+ next = $(this.$menu.find('li')[0]);
338
+ }
339
+
340
+ next.addClass('active');
341
+ },
342
+
343
+ prev: function (event) {
344
+ var active = this.$menu.find('.active').removeClass('active');
345
+ var prev = active.prev();
346
+
347
+ if (!prev.length) {
348
+ prev = this.$menu.find('li').last();
349
+ }
350
+
351
+ prev.addClass('active');
352
+ },
353
+
354
+ listen: function () {
355
+ this.$element
356
+ .on('focus', $.proxy(this.focus, this))
357
+ .on('blur', $.proxy(this.blur, this))
358
+ .on('keypress', $.proxy(this.keypress, this))
359
+ .on('propertychange input', $.proxy(this.input, this))
360
+ .on('keyup', $.proxy(this.keyup, this));
361
+
362
+ if (this.eventSupported('keydown')) {
363
+ this.$element.on('keydown', $.proxy(this.keydown, this));
364
+ }
365
+
366
+ this.$menu
367
+ .on('click', $.proxy(this.click, this))
368
+ .on('mouseenter', 'li', $.proxy(this.mouseenter, this))
369
+ .on('mouseleave', 'li', $.proxy(this.mouseleave, this))
370
+ .on('mousedown', $.proxy(this.mousedown,this));
371
+ },
372
+
373
+ destroy : function () {
374
+ this.$element.data('typeahead',null);
375
+ this.$element.data('active',null);
376
+ this.$element
377
+ .off('focus')
378
+ .off('blur')
379
+ .off('keypress')
380
+ .off('propertychange input')
381
+ .off('keyup');
382
+
383
+ if (this.eventSupported('keydown')) {
384
+ this.$element.off('keydown');
385
+ }
386
+
387
+ this.$menu.remove();
388
+ this.destroyed = true;
389
+ },
390
+
391
+ eventSupported: function (eventName) {
392
+ var isSupported = eventName in this.$element;
393
+ if (!isSupported) {
394
+ this.$element.setAttribute(eventName, 'return;');
395
+ isSupported = typeof this.$element[eventName] === 'function';
396
+ }
397
+ return isSupported;
398
+ },
399
+
400
+ move: function (e) {
401
+ if (!this.shown) return;
402
+
403
+ switch (e.keyCode) {
404
+ case 9: // tab
405
+ case 13: // enter
406
+ case 27: // escape
407
+ e.preventDefault();
408
+ break;
409
+
410
+ case 38: // up arrow
411
+ // with the shiftKey (this is actually the left parenthesis)
412
+ if (e.shiftKey) return;
413
+ e.preventDefault();
414
+ this.prev();
415
+ break;
416
+
417
+ case 40: // down arrow
418
+ // with the shiftKey (this is actually the right parenthesis)
419
+ if (e.shiftKey) return;
420
+ e.preventDefault();
421
+ this.next();
422
+ break;
423
+ }
424
+ },
425
+
426
+ keydown: function (e) {
427
+ this.keyPressed = true;
428
+ this.suppressKeyPressRepeat = ~$.inArray(e.keyCode, [40,38,9,13,27]);
429
+ if (!this.shown && e.keyCode == 40) {
430
+ this.lookup();
431
+ } else {
432
+ this.move(e);
433
+ }
434
+ },
435
+
436
+ keypress: function (e) {
437
+ if (this.suppressKeyPressRepeat) return;
438
+ this.move(e);
439
+ },
440
+
441
+ input: function (e) {
442
+ // This is a fixed for IE10/11 that fires the input event when a placehoder is changed
443
+ // (https://connect.microsoft.com/IE/feedback/details/810538/ie-11-fires-input-event-on-focus)
444
+ var currentValue = this.$element.val() || this.$element.text();
445
+ if (this.value !== currentValue) {
446
+ this.value = currentValue;
447
+ this.lookup();
448
+ }
449
+ },
450
+
451
+ keyup: function (e) {
452
+ if (this.destroyed) {
453
+ return;
454
+ }
455
+ switch (e.keyCode) {
456
+ case 40: // down arrow
457
+ case 38: // up arrow
458
+ case 16: // shift
459
+ case 17: // ctrl
460
+ case 18: // alt
461
+ break;
462
+
463
+ case 9: // tab
464
+ if (!this.shown || (this.showHintOnFocus && !this.keyPressed)) return;
465
+ this.select();
466
+ break;
467
+ case 13: // enter
468
+ if (!this.shown) return;
469
+ this.select();
470
+ break;
471
+
472
+ case 27: // escape
473
+ if (!this.shown) return;
474
+ this.hide();
475
+ break;
476
+ }
477
+
478
+ },
479
+
480
+ focus: function (e) {
481
+ if (!this.focused) {
482
+ this.focused = true;
483
+ this.keyPressed = false;
484
+ if (this.options.showHintOnFocus && this.skipShowHintOnFocus !== true) {
485
+ if(this.options.showHintOnFocus === "all") {
486
+ this.lookup("");
487
+ } else {
488
+ this.lookup();
489
+ }
490
+ }
491
+ }
492
+ if (this.skipShowHintOnFocus) {
493
+ this.skipShowHintOnFocus = false;
494
+ }
495
+ },
496
+
497
+ blur: function (e) {
498
+ if (!this.mousedover && !this.mouseddown && this.shown) {
499
+ this.hide();
500
+ this.focused = false;
501
+ this.keyPressed = false;
502
+ } else if (this.mouseddown) {
503
+ // This is for IE that blurs the input when user clicks on scroll.
504
+ // We set the focus back on the input and prevent the lookup to occur again
505
+ this.skipShowHintOnFocus = true;
506
+ this.$element.focus();
507
+ this.mouseddown = false;
508
+ }
509
+ },
510
+
511
+ click: function (e) {
512
+ e.preventDefault();
513
+ this.skipShowHintOnFocus = true;
514
+ this.select();
515
+ this.$element.focus();
516
+ this.hide();
517
+ },
518
+
519
+ mouseenter: function (e) {
520
+ this.mousedover = true;
521
+ this.$menu.find('.active').removeClass('active');
522
+ $(e.currentTarget).addClass('active');
523
+ },
524
+
525
+ mouseleave: function (e) {
526
+ this.mousedover = false;
527
+ if (!this.focused && this.shown) this.hide();
528
+ },
529
+
530
+ /**
531
+ * We track the mousedown for IE. When clicking on the menu scrollbar, IE makes the input blur thus hiding the menu.
532
+ */
533
+ mousedown: function (e) {
534
+ this.mouseddown = true;
535
+ this.$menu.one("mouseup", function(e){
536
+ // IE won't fire this, but FF and Chrome will so we reset our flag for them here
537
+ this.mouseddown = false;
538
+ }.bind(this));
539
+ }
540
+
541
+ };
542
+
543
+
544
+ /* TYPEAHEAD PLUGIN DEFINITION
545
+ * =========================== */
546
+
547
+ var old = $.fn.typeahead;
548
+
549
+ $.fn.typeahead = function (option) {
550
+ var arg = arguments;
551
+ if (typeof option == 'string' && option == 'getActive') {
552
+ return this.data('active');
553
+ }
554
+ return this.each(function () {
555
+ var $this = $(this);
556
+ var data = $this.data('typeahead');
557
+ var options = typeof option == 'object' && option;
558
+ if (!data) $this.data('typeahead', (data = new Typeahead(this, options)));
559
+ if (typeof option == 'string' && data[option]) {
560
+ if (arg.length > 1) {
561
+ data[option].apply(data, Array.prototype.slice.call(arg, 1));
562
+ } else {
563
+ data[option]();
564
+ }
565
+ }
566
+ });
567
+ };
568
+
569
+ Typeahead.defaults = {
570
+ source: [],
571
+ items: 8,
572
+ menu: '<div class="card" style="position: absolute; min-width: 250px; z-index: 99;max-width: 100%;"></div>',
573
+ item: '<li class="nav-search post-list"><a class="waves-effect post-list black-text" href="#" role="option"></a></li>',
574
+ minLength: 1,
575
+ scrollHeight: 0,
576
+ autoSelect: true,
577
+ afterSelect: $.noop,
578
+ addItem: false,
579
+ delay: 0,
580
+ separator: 'category',
581
+ headerHtml: '<li class="dropdown-header"></li>',
582
+ headerDivider: '<li class="divider" role="separator"></li>'
583
+ };
584
+
585
+ $.fn.typeahead.Constructor = Typeahead;
586
+
587
+ /* TYPEAHEAD NO CONFLICT
588
+ * =================== */
589
+
590
+ $.fn.typeahead.noConflict = function () {
591
+ $.fn.typeahead = old;
592
+ return this;
593
+ };
594
+
595
+
596
+ /* TYPEAHEAD DATA-API
597
+ * ================== */
598
+
599
+ $(document).on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) {
600
+ var $this = $(this);
601
+ if ($this.data('typeahead')) return;
602
+ $this.typeahead($this.data());
603
+ });
604
+
605
+ }));
@@ -0,0 +1,26 @@
1
+ $(document).ready(function () {
2
+ var time1 = 0;
3
+ var show = false;
4
+ var names = new Array(); //文章名字等
5
+ var urls = new Array(); //文章地址
6
+ $.getJSON("assets/cb-search.json").done(function (data) {
7
+ if (data.code == 0) {
8
+ for (var index in data.data) {
9
+ var item = data.data[index];
10
+ names.push(item.title);
11
+ urls.push(item.url);
12
+ }
13
+
14
+ $(".cb-search-content").typeahead({
15
+ source: names,
16
+
17
+ afterSelect: function (item) {
18
+ $(".cb-search-tool").css("display", "none");
19
+ show = false;
20
+ window.location.href = (urls[names.indexOf(item)]);
21
+ return item;
22
+ }
23
+ });
24
+ }
25
+ }).error(function(data, b) { console.log("json解析错误,搜索功能暂不可用,请检查文章title,确保不含有换行等特殊符号"); });
26
+ });
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-theme-materialize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - KeJun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-06 00:00:00.000000000 Z
11
+ date: 2017-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.4'
27
- - !ruby/object:Gem::Dependency
28
- name: jekyll-lunr-js-search
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '3.2'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '3.2'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -87,11 +73,12 @@ files:
87
73
  - _layouts/about.html
88
74
  - _layouts/archive.html
89
75
  - _layouts/default.html
90
- - _layouts/index.html
76
+ - _layouts/home.html
91
77
  - _layouts/links.html
92
78
  - _layouts/page.html
93
79
  - _layouts/post.html
94
80
  - _layouts/tags.html
81
+ - assets/cb-search.json
95
82
  - assets/css/gallery-materialize.min.opt.css
96
83
  - assets/css/main.css
97
84
  - assets/css/materialize.min.css
@@ -143,6 +130,8 @@ files:
143
130
  - assets/images/links/viosey.png
144
131
  - assets/images/tx.jpg
145
132
  - assets/images/userbg.png
133
+ - assets/js/bootstrap3-typeahead.min.js
134
+ - assets/js/cb-search.js
146
135
  - assets/js/gallery.min.opt.js
147
136
  - assets/js/jquery.lazyload.min.js
148
137
  - assets/js/jquery.scrollToTop.min.js
@@ -169,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
158
  version: '0'
170
159
  requirements: []
171
160
  rubyforge_project:
172
- rubygems_version: 2.6.10
161
+ rubygems_version: 2.6.8
173
162
  signing_key:
174
163
  specification_version: 4
175
164
  summary: jekyll-materializecss-theme