Skip to content

Commit

Permalink
support local search,close flysnow-org#55
Browse files Browse the repository at this point in the history
  • Loading branch information
flysnoworg committed Dec 2, 2019
1 parent 64423e0 commit 00004c9
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 9 deletions.
43 changes: 36 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Maupassant

[![【阿里云双11】热门产品低至1折,全年冰点钜惠,再赢100万红包](./aliyun_2019.jpg "【阿里云双11】热门产品低至1折,全年冰点钜惠,再赢100万红包")](https://www.aliyun.com/1111/2019/home?source=5176.11533457&userCode=jdg9oj97&type=copy)

Maupassant theme, ported to Hugo.

1. 预览效果:[飞雪无情的博客](http://www.flysnow.org)
Expand All @@ -15,11 +13,12 @@ Maupassant theme, ported to Hugo.

## 功能特性

1. 最近发表的文章支持,显示最近的10篇
2. 分类支持,并且可以显示分类内的文章数量
3. 标签云支持
4. 文章目录支持
4. 一键回到页面顶部
1. 支持Local Search 站内搜索
2. 最近发表的文章支持,显示最近的10篇
3. 分类支持,并且可以显示分类内的文章数量
4. 标签云支持
5. 文章目录支持
6. 一键回到页面顶部
13. 支持关键字SEO优化
6. 自定义菜单支持,不限个数,自定义排序
7. 自定义友情链接支持
Expand Down Expand Up @@ -65,6 +64,14 @@ languageCode = "zh-CN"
title = "飞雪无情的博客"
theme = "maupassant"

## 保持分类的原始名字(false会做转小写处理)
preserveTaxonomyNames = true
## 是否禁止URL Path转小写
disablePathToLower = true

hasCJKLanguage = true
summaryLength = 140

[author]
name = "飞雪无情"

Expand All @@ -73,6 +80,8 @@ theme = "maupassant"
subtitle = "专注于Android、Java、Go语言(golang)、移动互联网、项目管理、软件架构"
keywords = "golang,go语言,go语言笔记,飞雪无情,java,android,博客,项目管理,python,软件架构,公众号,小程序"
description = "专注于IT互联网,包括但不限于Go语言(golang)、Java、Android、Python、项目管理、抖音分析、软件架构等"
busuanzi = true
localSearch = true
```

基本配置大家都比较熟悉,这是我的博客的配置,仅供参考。
Expand Down Expand Up @@ -112,6 +121,26 @@ theme = "maupassant"
toc = true
```
当左侧空白空间宽度超过100px时,则显示悬浮目录。

#### Local Search 站内搜索

站内搜索默认是关闭的,如果需要使用需要以下步骤开启。

1. 检查`config.toml``disableKinds`配置项,是否禁用了RSS,如果禁用需要开启。
2.`config.toml`中找到`[params]`配置段落,增加`localSearch = true`开启站内搜索
3.`content`目录下新建`search`目录,并且在`search`目录中新建`index.md`文件,内容如下

```
---
title: "搜索"
description: "搜索页面"
type: "search"
---
```

然后`hugo server`启动,打开你的站点,就可以在右上角的搜索框里输入关键字进行站内搜索了。


#### 友情链接

```toml
Expand Down
22 changes: 21 additions & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,27 @@ TOC support in Front Matter .
```toml
toc = true
```
If the left blank space more than 100px, it will display Floating TOC. here is preview [https://kkua.github.io/post/java-util-code-snippet/](https://kkua.github.io/post/java-util-code-snippet/)
If the left blank space more than 100px, it will display Floating TOC.


#### Local Search

If you want to use local search , please following steps:

1. enabled rss,you can visit `http://127.0.0.1:1313/index.xml` check it.
2. edit `config.toml` file,add `localSearch = true` under the `[params]`.
3. new `index.md` file in your `content/search/` dir,and write content for:

```
---
title: "搜索"
description: "搜索页面"
type: "search"
---
```

Now ,run `hugo server` and try local search.

#### Ads

```toml
Expand Down
Binary file removed aliyun_2019.jpg
Binary file not shown.
2 changes: 1 addition & 1 deletion layouts/partials/search_form.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form id="search" action="//www.google.com/search" method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
<form id="search" action="{{if .Site.Params.localSearch }}/search/{{else}}//www.google.com/search{{end}}" method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
{{/** the keywords **/}}
<input type="text" name="q" maxlength="20" placeholder="Search">
<input type="hidden" name="sitesearch" value="{{ .Site.BaseURL }}">
Expand Down
85 changes: 85 additions & 0 deletions layouts/search/single.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{{ partial "head" . }}

<body>
{{ partial "header" . }}

<div id="body">
<div class="container">
<div class="col-group">

<div class="col-8" id="main">
<div class="res-cons">
<h3 class="archive-title">
搜索
<span class="keyword">哈哈</span>
的结果
</h3>

<article class="post">
<header>
<h1 class="post-title">
<a href="链接">标题</a>
</h1>
</header>
<date class="post-meta meta-date">
2019年12月01日
</date>
<div class="post-content">
概要……
<p class="readmore"><a href="链接">阅读全文</a></p>
</div>
</article>

</div>
</div>

{{ partial "sidebar" . }}
</div>
</div>
</div>
{{ partial "footer" . }}

<script type="text/javascript">

var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;

for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');

if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
}
}
};

$(document).ready(function() {
var q = getUrlParameter("q");
$("span.keyword").text(q);
$("article.post").remove();
$.ajax({
url: "/index.xml",
dataType: "xml",
success: function(data) {
$(data).find("item").each(function () {
var item=$(this);
var title=item.find("title").text();
if (title.indexOf(q) > 0){
var url = item.find("link").text();
var searchItem=`<article class="post"><header><h1 class="post-title"><a href="`+url+`">`+title+`</a></h1></header>`;
var pubDate = new Date(item.find("pubDate").text())
searchItem+=`<date class="post-meta meta-date">`+pubDate.getFullYear()+`年`+(pubDate.getMonth()+1)+`月`+pubDate.getDate()+`日</date>`;
searchItem+=`<div class="post-content">`+item.find("description").text()+`……<p class="readmore"><a href="`+url+`">阅读全文</a></p></div></article>`;

$("div.res-cons").append(searchItem);
}
});
}
});
});
</script>
</body>
</html>

0 comments on commit 00004c9

Please sign in to comment.