From a3961d9cd3958141cebf8f02c13c9849fe7cf421 Mon Sep 17 00:00:00 2001 From: Tommy Chen <tommy351@gmail.com> Date: Wed, 30 Dec 2015 01:20:16 +0800 Subject: [PATCH] Try algolia search --- _config.yml | 6 ++- package.json | 4 +- scripts/helpers.js | 4 +- themes/navy/layout/page.swig | 6 +-- themes/navy/layout/partial/after_footer.swig | 16 ++++---- themes/navy/layout/partial/head.swig | 5 +-- themes/navy/layout/partial/header.swig | 17 +++----- themes/navy/layout/partial/post.swig | 6 +-- themes/navy/source/css/_partial/header.styl | 40 ++++++++++--------- .../navy/source/css/_partial/mobile_nav.styl | 36 +---------------- 10 files changed, 52 insertions(+), 88 deletions(-) diff --git a/_config.yml b/_config.yml index 824fa2e..149c170 100644 --- a/_config.yml +++ b/_config.yml @@ -24,6 +24,8 @@ deploy: disqus_shortname: hexojs google_analytics: UA-4910098-10 fb_admins: 100000247608790 -swiftype_key: EwN4HMy_KMxTK_GMjV1z +algolia: + api_key: c3d5d4c995b5e0c2ffb5623900279a66 + index_name: hexo twitter: hexojs -github: hexojs/hexo \ No newline at end of file +github: hexojs/hexo diff --git a/package.json b/package.json index 97d9246..6ca0831 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "private": true, "hexo": { - "version": "3.1.1" + "version": "3.2.0-beta.2" }, "scripts": { "build": "hexo generate && gulp", @@ -40,4 +40,4 @@ "optionalDependencies": { "hexo-browsersync": "^0.2.0" } -} +} \ No newline at end of file diff --git a/scripts/helpers.js b/scripts/helpers.js index 28d62f3..bdecb84 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -74,9 +74,7 @@ hexo.extend.helper.register('header_menu', function(className){ _.each(menu, function(path, title){ if (!isEnglish && ~localizedPath.indexOf(title)) path = lang + path; - result += '<li class="' + className + '-item">'; result += '<a href="' + self.url_for(path) + '" class="' + className + '-link">' + self.__('menu.' + title) + '</a>'; - result += '</li>'; }); return result; @@ -154,4 +152,4 @@ hexo.extend.helper.register('disqus_lang', function(){ var data = this.site.data.languages[lang]; return data.disqus_lang || lang; -}); \ No newline at end of file +}); diff --git a/themes/navy/layout/page.swig b/themes/navy/layout/page.swig index fb20e2a..12c887d 100644 --- a/themes/navy/layout/page.swig +++ b/themes/navy/layout/page.swig @@ -6,10 +6,10 @@ <div class="article"> <div class="inner"> <header class="article-header"> - <h1 class="article-title" itemprop="name" data-swiftype-name="title" data-swiftype-type="string">{{ page.title }}</h1> + <h1 class="article-title" itemprop="name">{{ page.title }}</h1> <a href="{{ raw_link(page.source) }}" class="article-edit-link" title="{{ __('page.improve') }}"><i class="fa fa-pencil"></i></a> </header> - <div class="article-content" itemprop="articleBody" data-swiftype-name="body" data-swiftype-type="text"> + <div class="article-content" itemprop="articleBody"> {{ page_anchor(page.content) }} </div> <footer class="article-footer"> @@ -31,4 +31,4 @@ {{ partial('partial/sidebar') }} </div> </div> -</div> \ No newline at end of file +</div> diff --git a/themes/navy/layout/partial/after_footer.swig b/themes/navy/layout/partial/after_footer.swig index c767ac3..7c32d01 100644 --- a/themes/navy/layout/partial/after_footer.swig +++ b/themes/navy/layout/partial/after_footer.swig @@ -12,12 +12,12 @@ {{ js('js/plugins') }} <!-- endbuild --> {% endif %} -<!-- Swiftype --> +<!-- Algolia --> +<script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script> <script type="text/javascript"> - (function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){ - (w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t); - e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e); - })(window,document,'script','https://s.swiftypecdn.com/install/v2/st.js','_st'); - - _st('install','{{ config.swiftype_key }}','2.0.0'); -</script> \ No newline at end of file +docsearch({ + apiKey: '{{ config.algolia.api_key }}', + indexName: '{{ config.algolia.index_name }}', + inputSelector: '#search-input' +}); +</script> diff --git a/themes/navy/layout/partial/head.swig b/themes/navy/layout/partial/head.swig index c50b6d3..36ed9d9 100644 --- a/themes/navy/layout/partial/head.swig +++ b/themes/navy/layout/partial/head.swig @@ -33,6 +33,7 @@ <!-- endbuild --> <link href="https://fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet" type="text/css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> + <link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css"> <!-- RSS --> {{ feed_tag('atom.xml') }} <!-- Open Graph --> @@ -40,8 +41,6 @@ fb_admins: config.fb_admins, twitter_site: config.twitter }) }} - <!-- Swiftype --> - <meta name="st:title" content="{{ page.title || config.title }}"> <!-- Google Analytics --> {{ partial('google_analytics') }} -</head> \ No newline at end of file +</head> diff --git a/themes/navy/layout/partial/header.swig b/themes/navy/layout/partial/header.swig index badefaf..5773239 100644 --- a/themes/navy/layout/partial/header.swig +++ b/themes/navy/layout/partial/header.swig @@ -4,13 +4,12 @@ <a href="{{ url_for_lang('') }}" id="logo">Hexo</a> </h1> <nav id="main-nav"> - <ul> - {{ header_menu('main-nav') }} - <li class="main-nav-item"> - <a href="https://github.com/{{ config.github }}" class="main-nav-link"><i class="fa fa-github-alt"></i></a> - </li> - </ul> + {{ header_menu('main-nav') }} + <a href="https://github.com/{{ config.github }}" class="main-nav-link"><i class="fa fa-github-alt"></i></a> </nav> + <div id="search-input-wrap"> + <input type="search" id="search-input" placeholder="Search..."> + </div> <div id="lang-select-wrap"> <label id="lang-select-label"><i class="fa fa-globe"></i><span>{{ lang_name(page.lang) }}</span></label> <select id="lang-select" data-canonical="{{ canonical_path_for_nav() }}"> @@ -19,14 +18,10 @@ {% endfor %} </select> </div> - <div id="search-btn-wrap" class="main-nav-item"> - <a id="search-btn" class="main-nav-link st-search-show-outputs"><i class="fa fa-search"></i></a> - </div> <a id="mobile-nav-toggle"> <span class="mobile-nav-toggle-bar"></span> <span class="mobile-nav-toggle-bar"></span> <span class="mobile-nav-toggle-bar"></span> </a> - <a id="mobile-search-btn" class="st-search-launcher"></a> </div> -</header> \ No newline at end of file +</header> diff --git a/themes/navy/layout/partial/post.swig b/themes/navy/layout/partial/post.swig index 2785ef6..ace5b9f 100644 --- a/themes/navy/layout/partial/post.swig +++ b/themes/navy/layout/partial/post.swig @@ -1,7 +1,7 @@ <article class="article post" itemscope itemtype="http://schema.org/Article"> <header class="article-header"> {% if is_post() %} - <h1 class="article-title" itemprop="name" data-swiftype-name="title" data-swiftype-type="string">{{ post.title }}</h1> + <h1 class="article-title" itemprop="name">{{ post.title }}</h1> {% else %} <h1> <a href="{{ url_for(post.path) }}" class="article-title" itemprop="name">{{ post.title }}</a> @@ -9,8 +9,8 @@ {% endif %} <a href="{{ url_for(post.path) }}" class="article-date">{{ time_tag(post.date) }}</a> </header> - <div class="article-content" itemprop="articleBody" data-swiftype-name="body" data-swiftype-type="text"> + <div class="article-content" itemprop="articleBody"> {{ page_anchor(post.content) }} </div> {{ partial('partial/comment') }} -</article> \ No newline at end of file +</article> diff --git a/themes/navy/source/css/_partial/header.styl b/themes/navy/source/css/_partial/header.styl index f133e3b..5188487 100644 --- a/themes/navy/source/css/_partial/header.styl +++ b/themes/navy/source/css/_partial/header.styl @@ -7,14 +7,16 @@ logo-size = 50px padding: header-padding-normal 0 @media print display: none - .home & - padding: header-padding-max 0 #header-inner - position: relative + display: flex + flex-flow: row nowrap + align-items: center + @media mq-mobile + justify-content: center #logo-wrap - text-align: center + flex: 0 logo-size #logo hide-text() @@ -22,20 +24,15 @@ logo-size = 50px width: logo-size height: logo-size background-size: @width @height - display: inline-block - @media mq-normal - float: left + display: block #main-nav display: none - float: left + flex: 1 auto padding-left: 20px @media mq-normal display: block -.main-nav-item - float: left - .main-nav-link color: #fff text-decoration: none @@ -44,26 +41,33 @@ logo-size = 50px transition: 0.2s font-family: font-title text-transform: uppercase - display: block + display: inline-block padding: 0 20px &:hover opacity: 1 color: color-link-hover -#search-btn-wrap +#search-input-wrap display: none - float: right margin-right: 15px @media mq-normal display: block -#search-btn - cursor: pointer +#search-input + background: none + border-bottom: 1px solid color-gray + font-size: inherit + font-family: font-title + padding: 0.5em 0 + color: #fff + outline: none + transition: border-color 0.2s + &:focus + border-bottom-color: color-link-hover #lang-select-wrap display: none position: relative - float: right @media mq-normal display: block @@ -85,4 +89,4 @@ logo-size = 50px width: 100% height: 100% -webkit-appearance: menulist-button - font-size: inherit \ No newline at end of file + font-size: inherit diff --git a/themes/navy/source/css/_partial/mobile_nav.styl b/themes/navy/source/css/_partial/mobile_nav.styl index bd0beaa..c1742d3 100644 --- a/themes/navy/source/css/_partial/mobile_nav.styl +++ b/themes/navy/source/css/_partial/mobile_nav.styl @@ -64,40 +64,6 @@ lang-select-height = 40px .mobile-nav-on & transform: rotate(-45deg) -#mobile-search-btn - position: absolute - top: 0 - bottom: 0 - right: gutter-width - margin: auto - width: toggle-width - height: @width - transition: 0.2s - opacity: 0.5 - &:before, &:after - content: "" - position: absolute - &:before - width: 18px - height: @width - border-radius: 50% - border: toggle-line solid #fff - top: 0 - left: 0 - &:after - width: 9px - height: toggle-line - background: #fff - top: 15px - right: 0 - border-radius: toggle-line - transform: rotate(45deg) - transform-origin: 0 - &:active - opacity: 1 - @media mq-normal - display: none - .mobile-nav-link color: #fff text-decoration: none @@ -167,4 +133,4 @@ lang-select-height = 40px .mobile-nav-on & opacity: 0.7 transform: translateX(-100%) - transition: opacity transition-duration \ No newline at end of file + transition: opacity transition-duration -- GitLab