Merge pull request #24 from ZeusWPI/search

[WIP] Search, fixes #22
This commit is contained in:
lorin 2016-07-23 17:03:26 +02:00 committed by GitHub
commit 5d76ce5506
13 changed files with 111 additions and 38 deletions

View file

@ -12,13 +12,9 @@ before_install:
- echo -e "Host zeus.ugent.be\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config - echo -e "Host zeus.ugent.be\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
script: script:
- bundle exec nanoc - bundle exec nanoc
- bundle exec nanoc check elinks - bundle exec nanoc check --deploy
- bundle exec nanoc check html
- bundle exec nanoc check ilinks
- bundle exec nanoc check mixed_content
- bundle exec nanoc check stale
after_success: after_success:
- mv deploy_key ~/.ssh/id_rsa - mv deploy_key ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa
- chmod +x .travis/deploy.sh - chmod +x .travis/deploy.sh
- .travis/deploy.sh - '[[ $TRAVIS_BRANCH == "master" ]] && echo "Deploying site"'

View file

@ -1,8 +0,0 @@
#!/bin/bash
if [[ $TRAVIS_BRANCH == 'master' ]]; then
echo "Deploying site..."
bundle exec nanoc deploy --target public
else
echo "Not deploying."
fi

8
Checks Normal file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
deploy_check :elinks
deploy_check :html
deploy_check :ilinks
deploy_check :mixed_content
deploy_check :stale

View file

@ -2,7 +2,8 @@
# A sample Gemfile # A sample Gemfile
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'nanoc', git: 'https://github.com/werthen/nanoc.git', branch: 'add-resources-to-ilinks-check' # gem 'nanoc', git: 'https://github.com/werthen/nanoc.git', branch: 'add-resources-to-ilinks-check'
gem 'nanoc', '4.2.2'
gem 'kramdown' gem 'kramdown'
gem 'coffee-script' gem 'coffee-script'
# Needed for relativize_urls # Needed for relativize_urls

View file

@ -1,13 +1,3 @@
GIT
remote: https://github.com/werthen/nanoc.git
revision: bd3235d8dbae71c5bf0328ba4630070c53a5d3f4
branch: add-resources-to-ilinks-check
specs:
nanoc (4.2.3)
cri (~> 2.3)
hamster (~> 3.0)
ref (~> 2.0)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
@ -23,7 +13,7 @@ GEM
cri (2.7.0) cri (2.7.0)
colored (~> 1.2) colored (~> 1.2)
execjs (2.7.0) execjs (2.7.0)
ffi (1.9.10) ffi (1.9.14)
formatador (0.2.5) formatador (0.2.5)
guard (2.14.0) guard (2.14.0)
formatador (>= 0.2.4) formatador (>= 0.2.4)
@ -42,7 +32,7 @@ GEM
hamster (3.0.0) hamster (3.0.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
json (2.0.1) json (2.0.1)
kramdown (1.10.0) kramdown (1.11.1)
listen (3.1.5) listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4) rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7) rb-inotify (~> 0.9, >= 0.9.7)
@ -50,6 +40,9 @@ GEM
lumberjack (1.0.10) lumberjack (1.0.10)
method_source (0.8.2) method_source (0.8.2)
mini_portile2 (2.1.0) mini_portile2 (2.1.0)
nanoc (4.2.2)
cri (~> 2.3)
hamster (~> 3.0)
nenv (0.3.0) nenv (0.3.0)
nokogiri (1.6.8) nokogiri (1.6.8)
mini_portile2 (~> 2.1.0) mini_portile2 (~> 2.1.0)
@ -58,15 +51,14 @@ GEM
nenv (~> 0.1) nenv (~> 0.1)
shellany (~> 0.0) shellany (~> 0.0)
pkg-config (1.1.7) pkg-config (1.1.7)
pry (0.10.3) pry (0.10.4)
coderay (~> 1.1.0) coderay (~> 1.1.0)
method_source (~> 0.8.1) method_source (~> 0.8.1)
slop (~> 3.4) slop (~> 3.4)
rack (1.6.4) rack (2.0.1)
rb-fsevent (0.9.7) rb-fsevent (0.9.7)
rb-inotify (0.9.7) rb-inotify (0.9.7)
ffi (>= 0.5.0) ffi (>= 0.5.0)
ref (2.0.0)
ruby_dep (1.3.1) ruby_dep (1.3.1)
sass (3.4.22) sass (3.4.22)
shellany (0.0.1) shellany (0.0.1)
@ -84,7 +76,7 @@ DEPENDENCIES
coffee-script coffee-script
guard-nanoc guard-nanoc
kramdown kramdown
nanoc! nanoc (= 4.2.2)
nokogiri nokogiri
sass sass
w3c_validators w3c_validators

41
Rules
View file

@ -1,6 +1,20 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true # frozen_string_literal: true
require 'json'
preprocess do
# Tag all posts with 'article'
@items.find_all('/posts/**/*').each do |i|
i.attributes[:kind] = 'article'
end
@items.create('', {}, '/tipuesearch_content.js', binary: false)
end
# This makes sure this tipuesearch_content doesn't get deleted
passthrough '/tipuesearch_content.js'
# ERB # ERB
compile '/*.erb' do compile '/*.erb' do
layout '/default.*' layout '/default.*'
@ -20,10 +34,7 @@ compile '/assets/stylesheets/**/*.scss' do
end end
# Compile all posts # Compile all posts
compile '/posts/**/*.md' do compile '/posts/**/*' do
# Every post is an article, needed for blogging helper
@item.attributes[:kind] = 'article'
filter :kramdown filter :kramdown
layout '/eventpost.*' layout '/eventpost.*'
@ -33,6 +44,11 @@ compile '/posts/**/*.md' do
filter :relativize_paths, type: :html filter :relativize_paths, type: :html
end end
compile '/posts/**/*', rep: :text do
filter :kramdown
filter :strip_html
end
route '/index.*' do route '/index.*' do
'/index.html' '/index.html'
end end
@ -52,3 +68,20 @@ route '/**/*.{erb,html,md}' do
end end
layout '/**/*', :erb layout '/**/*', :erb
postprocess do
tmp = articles.map do |e|
{
title: e[:title],
url: url_for(e),
text: excerptize(e.reps[:text].compiled_content, length: 200),
tags: ''
}
end
tmp = { pages: tmp }
File.open('output/tipuesearch_content.js', 'w') do |f|
f.write("var tipuesearch = #{tmp.to_json};")
end
end

View file

@ -5,7 +5,7 @@ $event-border-color: #DDD;
$cammie-controls-color: rgba(0, 0, 0, 0.60); $cammie-controls-color: rgba(0, 0, 0, 0.60);
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700); @import url(https://fonts.googleapis.com/css?family=Open+Sans:300,400,700);
html, button, input, select, textarea, html, button, input, select, textarea,
.pure-g [class *= "pure-u"] { .pure-g [class *= "pure-u"] {

View file

@ -3,7 +3,9 @@
<div id="container" class="pure-u-xl-3-5 pure-u-lg-2-3 pure-u-md-3-4 pure-u-sm-5-6 pure-u-11-12"> <div id="container" class="pure-u-xl-3-5 pure-u-lg-2-3 pure-u-md-3-4 pure-u-sm-5-6 pure-u-11-12">
<header> <header>
<div class="header-top"> <div class="header-top">
<a href="/">
<img id="logo" src="https://zeus.ugent.be/wp-content/uploads/2009/05/logo-new.png" alt="" /> <img id="logo" src="https://zeus.ugent.be/wp-content/uploads/2009/05/logo-new.png" alt="" />
</a>
<div id="logos"> <div id="logos">
<a href="https://github.com/ZeusWPI" target="_blank"> <a href="https://github.com/ZeusWPI" target="_blank">
<i class="logo-link fa fa-github fa-3x"></i> <i class="logo-link fa fa-github fa-3x"></i>

31
content/search.erb Normal file
View file

@ -0,0 +1,31 @@
<div class="pure-g">
<div class="pure-u-xl-1-5 pure-u-lg-1-6 pure-u-md-1-8 pure-u-sm-1-12 pure-u-1-24"></div>
<div id="container" class="pure-u-xl-3-5 pure-u-lg-2-3 pure-u-md-3-4 pure-u-sm-5-6 pure-u-11-12">
<div class="header-top">
<a href="/">
<img id="logo" src="https://zeus.ugent.be/wp-content/uploads/2009/05/logo-new.png" alt="" />
</a>
<div id="logos">
<a href="https://github.com/ZeusWPI" target="_blank">
<i class="logo-link fa fa-github fa-3x"></i>
</a>
<a href="https://www.facebook.com/zeus.wpi/" target="_blank">
<i class="logo-link fa fa-facebook fa-3x"></i>
</a>
<a href="#" target="_blank">
<i class="logo-link fa fa-rss fa-3x"></i>
</a>
</div>
</div>
<%= render '/partials/_navbar.*' %>
<form action="?" method="get">
<input type="text" name="q" id="tipue_search_input" autocomplete="off" required>
</form>
<div id="tipue_search_content"></div>
<script>
$(document).ready(function() {
$('#tipue_search_input').tipuesearch();
});
</script>
</div>
</div>

View file

@ -24,6 +24,11 @@
<meta property="fb:app_id" content="597670540410704"> <meta property="fb:app_id" content="597670540410704">
<script src="/tipuesearch_content.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/Tipue-Search/5.0.0/tipuesearch.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Tipue-Search/5.0.0/tipuesearch_set.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Tipue-Search/5.0.0/tipuesearch.min.js"></script>
<%= content_for(@item, :head) %> <%= content_for(@item, :head) %>
</head> </head>
<body> <body>

View file

@ -8,6 +8,9 @@
<a href="#"> <a href="#">
Contact Contact
</a> </a>
<a href="/search">
Search
</a>
<a href="/cammie"> <a href="/cammie">
Cammie Cammie
</a> </a>

9
lib/strip_filter.rb Normal file
View file

@ -0,0 +1,9 @@
include Nanoc::Helpers::Text
class StripFilter < Nanoc::Filter
identifier :strip_html
def run(content, _params = {})
strip_html(content)
end
end

View file

@ -1,4 +1,5 @@
base_url: https://zeus.ugent.be/beta #base_url: https://zeus.ugent.be/beta
base_url: http://localhost:3000
# The syntax to use for patterns in the Rules file. Can be either `"glob"` # The syntax to use for patterns in the Rules file. Can be either `"glob"`
# (default) or `"legacy"`. The former will enable glob patterns, which behave # (default) or `"legacy"`. The former will enable glob patterns, which behave