Skip to content

Commit

Permalink
feat: add algolia docsearch (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
QWRDA authored Mar 29, 2024
1 parent fd3621d commit 44c8742
Show file tree
Hide file tree
Showing 10 changed files with 783 additions and 20 deletions.
5 changes: 5 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ webmaster_verifications:
google: WFu5M6w9XiYrf3hgUBLxCA1Jrgb_CWTzXTPycVIqngg
bing: EDFBFE217D2B905D82BE1D5A1BC9AB28
baidu: code-emsTMHxQLF
algolia:
app_id: T25W3F5EZF
api_key: b6d7e64ad9d29597614562aa723ea028
index_name: qweather
container: "#docsearch"

defaults:
- scope:
Expand Down
6 changes: 2 additions & 4 deletions _includes/main-nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@
<li class="mr-auto mr-md-2 {%- if page.ref=="price" %} active{%- endif %}">
<a class="dark-link no-underline" href="{%- if page.lang == "en" %}/en{%- endif %}/price/">{{ site.data.t[page.lang].price }}</a>
</li>
{%- comment -%}
<li class="d-none d-md-block">
<a class="dark-link no-underline" target="_blank" rel="noopener noreferrer" href="{{site.links.blog}}">{{ site.data.t[page.lang].blog }}</a>
<li class="mr-auto mr-md-2">
<div id="docsearch"></div>
</li>
{%- endcomment -%}
</ul>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions _includes/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script src="/assets/js/docsearch@3.js"></script><script>{%-if page.lang=="zh"-%}const docSearchTranslations={modal:{searchBox:{resetButtonTitle:'清空',cancelButtonText:'取消',},errorScreen:{titleText:'无法获取结果',helpText:'请检查你的网络连接。',},footer:{selectText:'选择',navigateText:'移动',closeText:'关闭',},noResultsScreen:{noResultsText:'找不到',suggestedQueryText:'试试搜索',},},};{%-endif-%}docsearch({container:'{{ site.algolia.container }}',appId:'{{ site.algolia.app_id }}',indexName:'{{ site.algolia.index_name }}',apiKey:'{{ site.algolia.api_key }}',disableUserPersonalization:true,{%-if page.lang=="zh"-%}placeholder:'搜索文档',translations:docSearchTranslations{%-endif-%}});</script>
2 changes: 2 additions & 0 deletions _layouts/html.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<meta name="google-site-verification" content="{{ site.webmaster_verifications.google }}" />
<meta name="msvalidate.01" content="{{ site.webmaster_verifications.bing }}" />
<meta name="baidu-site-verification" content="{{ site.webmaster_verifications.baidu }}" />
<link rel="preconnect" href="https://{{- site.algolia.app_id -}}-dsn.algolia.net" crossorigin />
{% include gtm.html %}
</head>
<body>
Expand All @@ -43,5 +44,6 @@
{% endif %}
{{ content }}
{% include footer.html %}
{% include search.html %}
</body>
</html>
Loading

0 comments on commit 44c8742

Please sign in to comment.