给小站安排上OpenSearch

尚寂新
尚寂新
2020/06/30 17:08

刚刚在V站看到了这个
https://www.v2ex.com/t/685678
看到下面给出了相关的实现方法
https://developer.mozilla.org/en-US/docs/Web/OpenSearch
https://developer.mozilla.org/zh-CN/docs/Mozilla/Add-ons/Creating_OpenSearch_plugins_for_Firefox
于是抱着不习惯看英文文档的原因(明明是当时没想到特意找到中文文档),然后就抄了一下Github的
实现起来也很简单。第一步:建个文件opensearch.xml,然后内容如下,把里面关于Github的文本和链接替换成自己的就可

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>GitHub</ShortName>
<Description>Search GitHub</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/x-icon">https://github.com/favicon.ico</Image>
<Url type="text/html" method="get" template="https://github.com/search?q={searchTerms}&ref=opensearch"/>
<moz:SearchForm>https://github.com/search</moz:SearchForm>
</OpenSearchDescription>

下面的是我的,可供参考

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
                       xmlns:moz="http://www.mozilla.org/2006/browser/search/">
  <ShortName>尚寂新博客</ShortName>
  <Description>搜索 尚寂新博客</Description>
  <InputEncoding>UTF-8</InputEncoding>
  <Image width="16" height="16" type="image/x-icon">https://shangjixin.com/favicon.ico</Image>
  <Url type="text/html" method="get" template="https://shangjixin.com/search/{searchTerms}/?ref=opensearch"/>
  <moz:SearchForm>https://shangjixin.com/search/</moz:SearchForm>
</OpenSearchDescription>

第二步(对于Typecho):在header.php<head>标签内新增如下一行,仍旧需要按照自己的情况进行修改,根据自己在第一步的文件位置改hreftitle的话写自己博客名字即可,其他的不需要动

<link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="GitHub">

然后就大功告成了

OpenSearch.gif
OpenSearch.gif

已有 0 条评论 (旧评论在前)
  1. 暂无评论 / 0 Comment
添加新评论 (Markdown Supported)
(ノ°ο°)ノ