Skip to content

Commit 2059f27

Browse files
committed
add google cse
1 parent 7a30ea9 commit 2059f27

File tree

9 files changed

+53
-331
lines changed

9 files changed

+53
-331
lines changed

TODO

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
* file upload bug
22
* omniauth and google/weibo integration
33
* EpicEditor
4+
* ajax tag suggestion
45
* model validation
56

67
* favicon
7-
* ferret search
88
* original source if article isn't written by me

app/controllers/admin.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
if @blog.save
2323
@blog.attach!(current_account)
2424
flash[:notice] = "创建成功"
25-
# TODO test blog search ping in production environment.
26-
# ping_search_engine(@blog)
25+
ping_search_engine(@blog) if APP_CONFIG['blog_search_ping'] # only ping search engine in production environment
2726
redirect url(:blog, :show, :id => @blog.id)
2827
else
2928
render 'admin/new_blog'

app/controllers/home.rb

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
get :me do
1919
render 'home/me'
2020
end
21+
22+
get :search do
23+
24+
render 'home/search'
25+
end
2126

2227
get :rss do
2328
content_type :xml

app/views/home/search.erb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div id="search_result">
2+
<div id="cse-search-results"></div>
3+
<script type="text/javascript">
4+
var googleSearchIframeName = "cse-search-results";
5+
var googleSearchFormName = "cse-search-box";
6+
var googleSearchFrameWidth = 950;
7+
var googleSearchDomain = "www.google.com";
8+
var googleSearchPath = "/cse";
9+
</script>
10+
<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
11+
</div>

app/views/layouts/application.erb

+8-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@
2828
<div class="nav">
2929
<div class="warp clearfix">
3030
<div class="search fr">
31-
<input name="search" type="text" placeholder="Search"><button></button>
31+
<form action="/search" id="cse-search-box" method="get">
32+
<input type="hidden" name="cx" value="<%= APP_CONFIG['google_cse'] %>" />
33+
<input type="hidden" name="cof" value="FORID:10" />
34+
<input type="hidden" name="ie" value="UTF-8" />
35+
<input id="search-box" name="q" type="text" placeholder="Search" value="<%= params[:q] %>">
36+
<button id="search-button">
37+
</form>
3238
</div>
3339
<ul>
3440
<li><a href="/" <%= "class='current'".html_safe if @nav == 'home' %>>Home</a></li>
@@ -55,4 +61,4 @@
5561
</div><!-- footer -->
5662
<%= javascript_include_tag 'jquery', 'jquery-ujs', 'application' %>
5763
</body>
58-
</html>
64+
</html>

public/javascripts/application.js

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ $(function(){
33
$('button.close').click(function() {
44
$('div.box').hide();
55
});
6+
7+
$('button#search-button').click(function() {
8+
var keyword = $.trim($('input#search-box').val());
9+
if (keyword != null && keyword != '') {
10+
$('form#cse-search-box').submit();
11+
}
12+
});
13+
14+
$('input#search-box').keyup(function(event) {
15+
if (event.keyCode == 13) {
16+
var keyword = $.trim($('input#search-box').val());
17+
if (keyword != null && keyword != '') {
18+
$('form#cse-search-box').submit();
19+
}
20+
}
21+
});
622
});
723

824
(function($){

public/lost_search.html

-76
This file was deleted.

public/robots.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2+
User-agent: *
3+
Disallow: /login
4+
Disallow: /search
5+
Disallow: /rss
6+
Disallow: /admin/
7+
Disallow: /uploads/
8+
Disallow: /stylesheets/
9+
Disallow: /javascripts/
10+
Disallow: /images/
11+
Disallow: /skins/

0 commit comments

Comments
 (0)