From f8439aa1c99813d229ea1562b3aa64f87c46bcbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B3=A1=E5=B7=9E=E4=BB=99=E5=A3=AB?= Date: Sat, 11 Jul 2020 21:15:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9C=AC=E5=9C=B0=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=A4=87=E7=94=A8=E7=9A=84=E5=A4=96=E9=83=A8=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E6=93=8E=E6=90=9C=E7=B4=A2=EF=BC=88=E8=B0=B7=E6=AD=8C?= =?UTF-8?q?=E3=80=81=E5=BF=85=E5=BA=94=EF=BC=89=20(#89)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update README.md * Update README_en-US.md * external alternative search * external alternative search * external alternative search * external alternative search * docs: update readme.md * feat: add assist_search * docs: add doc for assist_search & update some others * docs: add doc for hexo-submit-urls-to-search-engine Co-authored-by: liuyib <1656081615@qq.com> --- README.md | 2 +- README_en-US.md | 2 +- _config.yml | 15 ++++ docs/zh-CN/advanced/optimize.md | 74 +++++++++++++++++++ docs/zh-CN/advanced/third-part.md | 27 +++++++ languages/en.yml | 8 ++ languages/zh-CN.yml | 8 ++ languages/zh-HK.yml | 8 ++ layout/_partials/config.pug | 14 ++++ layout/_partials/search/algolia.pug | 2 + layout/_partials/search/assist-btns.pug | 16 ++++ layout/_partials/search/localsearch.pug | 2 + layout/_third-party/search/localsearch.pug | 32 ++++++++ .../css/_common/components/search/common.styl | 24 +++++- .../components/search/localsearch.styl | 6 +- 15 files changed, 235 insertions(+), 5 deletions(-) create mode 100644 layout/_partials/search/assist-btns.pug diff --git a/README.md b/README.md index d80a4f0..7d27405 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ - [弥枳's Blog](http://blog2.coor.top/) - [轻尘's Blog](https://qcxitong.xyz/) - [impressionyang's Blog](https://impressionyang.github.io) -- [峡州仙士之页](https://cjh0613.gitee.io/blog/) +- [峡州仙士之页](https://cjh0613.github.io/blog/) - [Cheeks's Blog](https://www.cheeks.top/) - [lingan1996's Blog](https://www.lingan1996.top) - [MikyMing's Blog](https://mikyming.online/) diff --git a/README_en-US.md b/README_en-US.md index 3a016bf..5647c7b 100644 --- a/README_en-US.md +++ b/README_en-US.md @@ -39,7 +39,7 @@ Language: [English](https://github.com/liuyib/hexo-theme-stun/blob/master/README - [弥枳's Blog](http://blog2.coor.top/) - [轻尘's Blog](https://qcxitong.xyz/) - [impressionyang's Blog](https://impressionyang.github.io) -- [峡州仙士之页](https://cjh0613.gitee.io/blog/) +- [峡州仙士之页](https://cjh0613.github.io/en/) - [Cheeks's Blog](https://www.cheeks.top/) - [lingan1996's Blog](https://www.lingan1996.top) - [MikyMing's Blog](https://mikyming.online/) diff --git a/_config.yml b/_config.yml index ff9bb2f..97315b4 100644 --- a/_config.yml +++ b/_config.yml @@ -614,7 +614,20 @@ algolia_search: # Local Search # See: https://github.com/wzpan/hexo-generator-search/ local_search: + enable: true + +# Auxiliary search buttons +# ! ----------------------------------------------------------------------------------------- +# ! This feature can only be enabled if either `algolia_search` or `local_search` is enabled. +# ! ----------------------------------------------------------------------------------------- +assist_search: enable: false + # Show the Google Search button. Use `www.google.com` to search for what you type. + google: true + # Show the Bing Search button. Use `www.bing.com` to search for what you type. + bing: true + # Show the Baidu Search button. Use `www.baidu.com` to search for what you type. + baidu: true # --------------------------------------------------------------- # Background config @@ -838,6 +851,8 @@ icon: notetag_info: fas fa-info-circle notetag_warning: fas fa-exclamation-circle notetag_danger: fas fa-minus-circle + google: fab fa-google + # bing: fab fa-bing # not exist # Set a CDN address for the vendor you want to customize. # ! ------------------------------------------------------------------- diff --git a/docs/zh-CN/advanced/optimize.md b/docs/zh-CN/advanced/optimize.md index 04e9afa..88a14ce 100644 --- a/docs/zh-CN/advanced/optimize.md +++ b/docs/zh-CN/advanced/optimize.md @@ -1,5 +1,79 @@ # 优化建议 +## 优化网站 SEO + +### 移除网址中多余的 `/index.html` + +TODO + +### 向搜索引擎提交 URLs + +为了使博客文章更好的被搜索引擎收录,推荐使用插件 [hexo-submit-urls-to-search-engine](https://github.com/cjh0613/hexo-submit-urls-to-search-engine) 来主动向搜索引擎提交 URLs。使用步骤如下: + +- 安装 + + 在 Hexo 根目录下执行指令: + + ```bash + $ npm install hexo-submit-urls-to-search-engine --save + ``` + +- 使用 + + 在 Hexo 根目录下的 _config.yml 文件中,添加以下配置项: + + ```yaml + hexo_submit_urls_to_search_engine: + # 提交最新的 n 个链接 + count: 10 + # 提交修改时间在 n 秒内的链接,单位秒。例如: + # 有两个文件 a.txt 和 b.txt,分别对应 https://yoursite.com/a.txt 和 https://yoursite.com/b.txt + # 其更新时间距当前分别为 800s 和 1000s(period 字段设为 900) + # 则 https://yoursite.com/a.txt 会被提交,https://yoursite.com/b.txt 不会 + period: 900 + # 提交链接的条件,可选值:count | period。不同取值的含义如下: + # count :应用上述的 count 配置项 + # period:应用上述的 period 配置项 + submit_condition: count + # 是否向 Google 提交,可选值:1 | 0(0:否;1:是) + google: 0 + # 是否向 Bing 提交,可选值:1 | 0(0:否;1:是) + bing: 1 + # 是否向 Baidu 提交,可选值:1 | 0(0:否;1:是) + baidu: 1 + # 文本文档的地址,要推送的链接会保存在此文本文档里 + txt_path: submit_urls.txt + # 在百度站长平台中注册的域名 + baidu_host: https://yoursite.com/ + # 百度自动推送 API 的 token(获取方式见插件文档:https://cjh0613.github.io/blog/20200603HexoSubmitUrlsToSearchEngine.html) + baidu_token: xxxxx + # 在必应站长平台中注册的域名 + bing_host: https://yoursite.com/ + # 必应自动推送 API 的 token(获取方式见插件文档:https://cjh0613.github.io/blog/20200603HexoSubmitUrlsToSearchEngine.html) + bing_token: xxxxx + # 在谷歌站长平台中注册的域名 + google_host: https://yoursite.com/ + # 存放 google key 的 json 文件,放于网站根目录 + google_key_file: google_key.json + ``` + + ::: tip + 当然你也可以使用环境变量记录私钥,这样即使源码放在公开仓库,也不会泄露秘钥。 + ::: + + 完成上述配置后,你需要在 Hexo 根目录下运行 `hexo generate` 指令,该指令会生成一个 .txt 文件来存储要推送的链接。 + + 最后,在 Hexo 根目录下的 _config.yml 文件中,修改以下配置项,即可实现在执行 `hexo deploy` 指令时,自动推送你的链接: + + ```yaml + deploy: + - type: cjh_google_url_submitter + - type: cjh_bing_url_submitter + - type: cjh_baidu_url_submitter + ``` + +如果你使用插件时**遇到了问题**或者想进行**更详细的设置**,请查看插件的[文档](https://cjh0613.github.io/blog/20200603HexoSubmitUrlsToSearchEngine.html)。 + ## 打包、压缩资源文件 ::: danger diff --git a/docs/zh-CN/advanced/third-part.md b/docs/zh-CN/advanced/third-part.md index 901ce19..28ed1b8 100644 --- a/docs/zh-CN/advanced/third-part.md +++ b/docs/zh-CN/advanced/third-part.md @@ -741,6 +741,33 @@ busuanzi: $ hexo clean && hexo s ``` +### 辅助搜索按钮 + +该功能是使用**搜索引擎**和**你输入的关键字**,来搜索你的博客网站。 + +启用该功能的前提是:启用了 [Algolia 搜索](#algolia-搜索) 或 [本地搜索](#本地搜索)。使用步骤如下: + +1. 启用 [Algolia 搜索](#algolia-搜索) 或 [本地搜索](#本地搜索) +2. 修改主题配置文件 + + ```yaml + assist_search: + # 是否启用 + enable: true + # 谷歌搜索的按钮。点击该按钮后,会通过 www.google.com 来搜索你输入的字符。 + google: true + # 必应搜索的按钮。点击该按钮后,会通过 www.bing.com 来搜索你输入的字符。 + bing: true + # 百度搜索的按钮。点击该按钮后,会通过 www.baidu.com 来搜索你输入的字符。 + baidu: true + ``` + +3. 重启 Hexo 服务器 + + ```bash + $ hexo clean && hexo s + ``` + ## 数学公式 想要解析页面中的数学公式,首先,你需要修改主题配置文件,启用该功能,并选择解析引擎(默认是 KaTeX 引擎): diff --git a/languages/en.yml b/languages/en.yml index 874cd66..15d2f8f 100644 --- a/languages/en.yml +++ b/languages/en.yml @@ -76,6 +76,14 @@ local_search: input_placeholder: Search for Posts (Support multiple keywords) hits_empty: We didn't find any results for the search +# Auxiliary search buttons +assist_search: + prompt_label: "Search by:" + prompt_input: Please enter characters + google: Google + bing: Bing + baidu: Baidu + # Reward reward: btn_text: Buy me a coffee diff --git a/languages/zh-CN.yml b/languages/zh-CN.yml index 80915f1..116ce54 100644 --- a/languages/zh-CN.yml +++ b/languages/zh-CN.yml @@ -76,6 +76,14 @@ local_search: input_placeholder: 搜索文章(支持多关键词,请用空格分隔) hits_empty: 没有找到任何搜索结果 +# 搜索的辅助按钮 +assist_search: + prompt_label: "使用搜索:" + prompt_input: 请输入字符 + google: 谷歌 + bing: 必应 + baidu: 百度 + # 打赏 reward: btn_text: 请我喝杯咖啡~ diff --git a/languages/zh-HK.yml b/languages/zh-HK.yml index 9fd8844..9f607e0 100644 --- a/languages/zh-HK.yml +++ b/languages/zh-HK.yml @@ -76,6 +76,14 @@ local_search: input_placeholder: 檢索文章(支持多關鍵字,請用空格分隔) hits_empty: 沒有找到任何檢索結果 +# 搜索的輔助按鈕 +assist_search: + prompt_label: "使用搜索:" + prompt_input: 請輸入字符 + google: 谷歌 + bing: 必應 + baidu: 百度 + # 打賞 reward: btn_text: 請我喝杯咖啡~ diff --git a/layout/_partials/config.pug b/layout/_partials/config.pug index d8b2704..1effce0 100644 --- a/layout/_partials/config.pug +++ b/layout/_partials/config.pug @@ -15,6 +15,19 @@ }); } + var assistSearch = 'undefined'; + if (theme.assist_search.enable) { + assistSearch = []; + + for (var key in theme.assist_search) { + var value = theme.assist_search[key]; + if (value && key !== 'enable') { + assistSearch.push(key); + } + } + assistSearch = JSON.stringify(assistSearch); + } + var fontIcon = 'undefined'; if (theme.icon) { fontIcon = JSON.stringify({ @@ -146,6 +159,7 @@ script. var CONFIG = { root: '!{ config.root }', algolia: !{ algolia }, + assistSearch: !{ assistSearch }, fontIcon: !{ fontIcon }, sidebar: !{ sidebar }, header: !{ header }, diff --git a/layout/_partials/search/algolia.pug b/layout/_partials/search/algolia.pug index 7be4b21..3b2ca79 100644 --- a/layout/_partials/search/algolia.pug +++ b/layout/_partials/search/algolia.pug @@ -4,6 +4,8 @@ div.search-popup span.search-close div.search-input + include ./assist-btns.pug + div.search-results div#algolia-hits diff --git a/layout/_partials/search/assist-btns.pug b/layout/_partials/search/assist-btns.pug new file mode 100644 index 0000000..e2e662f --- /dev/null +++ b/layout/_partials/search/assist-btns.pug @@ -0,0 +1,16 @@ +if theme.assist_search.enable + div.search-btns + = __('assist_search.prompt_label') + + if theme.assist_search.google + span.search-btns-item.search-btns-item--google + i(class=theme.icon.google) + = __('assist_search.google') + if theme.assist_search.bing + span.search-btns-item.search-btns-item--bing + i(class=theme.icon.bing) + = __('assist_search.bing') + if theme.assist_search.baidu + span.search-btns-item.search-btns-item--baidu + i(class=theme.icon.baidu) + = __('assist_search.baidu') diff --git a/layout/_partials/search/localsearch.pug b/layout/_partials/search/localsearch.pug index 142c1a1..9cfbb76 100644 --- a/layout/_partials/search/localsearch.pug +++ b/layout/_partials/search/localsearch.pug @@ -5,4 +5,6 @@ div.search-popup div.search-input input(placeholder= __('local_search.input_placeholder')) + include ./assist-btns.pug + div.search-results diff --git a/layout/_third-party/search/localsearch.pug b/layout/_third-party/search/localsearch.pug index 805aa8b..a1aad22 100644 --- a/layout/_third-party/search/localsearch.pug +++ b/layout/_third-party/search/localsearch.pug @@ -241,3 +241,35 @@ script. 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', '!{ __("assist_search.prompt_input") }'); + } + } + + 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); + }); + } diff --git a/source/css/_common/components/search/common.styl b/source/css/_common/components/search/common.styl index afc981a..ff178cb 100644 --- a/source/css/_common/components/search/common.styl +++ b/source/css/_common/components/search/common.styl @@ -1,6 +1,7 @@ search-popup-padding = 1rem; search-input-height = 2rem; -search-input-padding = 1rem; +search-input-margin = 1rem; +search-assist-height = 2rem; .search { &-mask { @@ -31,7 +32,7 @@ search-input-padding = 1rem; } &-input { - margin: search-input-padding 0; + margin: search-input-margin 0; input { border: 2px solid alpha($blue-light, .5); @@ -89,4 +90,23 @@ search-input-padding = 1rem; background-color: $yellow-light; } } + + &-btns { + height: search-assist-height; + text-align: center; + + &-item { + margin: 0 5px; + border-radius: 5px; + padding: 3px 5px; + line-height: search-assist-height; + color: #fff; + background-color: $blue-lighter; + cursor: pointer; + + i { + margin: 0 3px; + } + } + } } diff --git a/source/css/_common/components/search/localsearch.styl b/source/css/_common/components/search/localsearch.styl index 7b5ddf7..2eb0066 100644 --- a/source/css/_common/components/search/localsearch.styl +++ b/source/css/_common/components/search/localsearch.styl @@ -1,4 +1,8 @@ -search-results-height = search-popup-padding * 2 + search-input-padding * 2 + search-input-height; +if (hexo-config('assist_search.enable')) { + search-results-height = search-popup-padding * 2 + search-input-margin * 2 + search-input-height + search-assist-height; +} else { + search-results-height = search-popup-padding * 2 + search-input-margin * 2 + search-input-height; +} .search { &-input { -- GitLab