Skip to content

Commit 6669ec7

Browse files
committed
blog index
1 parent 2059f27 commit 6669ec7

12 files changed

+51
-23
lines changed

Rakefile

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
require File.expand_path('../config/boot.rb', __FILE__)
22
require 'padrino-core/cli/rake'
3+
# PadrinoTasks.use(:activerecord)
4+
# PadrinoTasks.use(:seed)
35
PadrinoTasks.init
6+
7+

TODO

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
* file upload bug
2-
* omniauth and google/weibo integration
32
* EpicEditor
43
* ajax tag suggestion
54
* model validation
65

6+
* deploy production environment
7+
8+
* omniauth and google/weibo integration
9+
* show weibo content
10+
* admin panel: change password, upload logo
11+
712
* favicon
813
* original source if article isn't written by me

app/helpers.rb

+12-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
RobbinSite.helpers do
44

5+
# authentication helpers
56
def current_account
67
return @current_account if @current_account
78
return @current_account = Account.find_by_id(session[:account_id]) if session[:account_id]
@@ -19,6 +20,7 @@ def account_admin?
1920
current_account && current_account.admin? ? true : false
2021
end
2122

23+
# blog article url generator for SEO purpose
2224
def blog_url(blog, mime_type = :html)
2325
if blog.slug_url.blank?
2426
slug_url = url(:blog, :show, :id => blog.id)
@@ -29,25 +31,26 @@ def blog_url(blog, mime_type = :html)
2931
slug_url
3032
end
3133

34+
# blog search ping for SEO purpose
3235
def ping_search_engine(blog)
3336
# http://www.google.cn/intl/zh-CN/help/blogsearch/pinging_API.html
3437
# http://www.baidu.com/search/blogsearch_help.html
38+
baidu = XMLRPC::Client.new2("http://ping.baidu.com/ping/RPC2")
39+
baidu.timeout = 5 # set timeout 5 seconds
40+
baidu.call("weblogUpdates.extendedPing",
41+
APP_CONFIG['site_title'],
42+
APP_CONFIG['site_url'],
43+
APP_CONFIG['site_url'] + '/' + blog_url(blog),
44+
APP_CONFIG['site_url'] + '/rss')
45+
3546
google = XMLRPC::Client.new2("http://blogsearch.google.com/ping/RPC2")
3647
google.timeout = 5 # set timeout 5 seconds
3748
google.call("weblogUpdates.extendedPing",
38-
APP_CONFIG['site_title'],
49+
APP_CONFIG['site_title'],
3950
APP_CONFIG['site_url'],
4051
APP_CONFIG['site_url'] + '/' + blog_url(blog),
4152
APP_CONFIG['site_url'] + '/rss',
4253
blog.cached_tag_list.gsub(/,/, '|'))
43-
44-
baidu = XMLRPC::Client.new2("http://ping.baidu.com/ping/RPC2")
45-
baidu.timeout = 5 # set timeout 5 seconds
46-
baidu.call("weblogUpdates.extendedPing",
47-
APP_CONFIG['site_title'],
48-
APP_CONFIG['site_url'],
49-
APP_CONFIG['site_url'] + '/' + blog_url(blog),
50-
APP_CONFIG['site_url'] + '/rss')
5154
rescue Exception => e
5255
logger.error e
5356
end

app/views/layouts/application.erb

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@
1414
<div class="warp">
1515
<div class="user_img"><img src="/skins/data/100.png" width="80" height="80"></div>
1616
<h1><span class="blog_name">Robbin</span><span class="blog_title">的自言自语</span></h1>
17-
<% if account_admin? %>
1817
<div class="write">
18+
<% unless account_login? %>
19+
<%= link_to '登录', url(:login) %>
20+
<% else %>
1921
<%= current_account.name %>
22+
<% if account_admin? %>
2023
<%= link_to '写博客', url(:admin, :new_blog) %>
24+
<%= link_to '设置', url(:admin, :index) %>
25+
<% end %>
2126
<%= button_to '退出', url(:logout), :method => :delete %>
22-
</div>
2327
<% end %>
28+
</div>
2429
<h2>Small is beautiful, constraint is liberty.</h2>
2530
</div>
2631
</div><!-- header -->

db/migrate/001_create_accounts.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ class CreateAccounts < ActiveRecord::Migration
22
def self.up
33
create_table :accounts do |t|
44
t.string :name
5-
t.string :surname
65
t.string :email
76
t.string :crypted_password
87
t.string :role
98
t.datetime :created_at
109
end
10+
add_index :email, :unique => true
1111
end
1212

1313
def self.down

db/migrate/002_create_blog_contents.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class CreateBlogContents < ActiveRecord::Migration
22
def self.up
33
create_table :blog_contents do |t|
4+
# set limit 64k+1 to force column type longtext
45
t.text :content, :null => false, :limit => 64.kilobytes + 1
56
end
67
end

db/migrate/003_create_blogs.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def self.up
33
create_table :blogs do |t|
44
t.string :title, :limit => 255, :null => false
55
t.string :slug_url, :limit => 255
6-
t.integer :view_count, :default => 0
6+
t.integer :view_count, :default => 0, :null => false
77
t.references :blog_content, :null => false
88
t.timestamps
99
end

db/migrate/007_add_counter_to_blogs.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class AddCounterToBlogs < ActiveRecord::Migration
22
def self.up
3-
add_column :blogs, :comments_count, :integer, :default => 0
4-
add_column :accounts, :blogs_count, :integer, :default => 0
3+
add_column :blogs, :comments_count, :integer, :default => 0, :null => false
4+
add_column :accounts, :blogs_count, :integer, :default => 0, :null => false
55
end
66

77
def self.down

db/migrate/013_add_index_to_blogs.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class AddIndexToBlogs < ActiveRecord::Migration
2+
def self.up
3+
add_index :blogs, :content_updated_at
4+
remove_index :blogs, :blog_content_id
5+
end
6+
7+
def self.down
8+
remove_index :blogs, :content_updated_at
9+
add_index :blogs, :blog_content_id
10+
end
11+
end

db/schema.rb

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@
1111
#
1212
# It's strongly recommended to check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(:version => 12) do
14+
ActiveRecord::Schema.define(:version => 13) do
1515

1616
create_table "accounts", :force => true do |t|
1717
t.string "name"
18-
t.string "surname"
1918
t.string "email"
2019
t.string "crypted_password"
2120
t.string "role"
2221
t.datetime "created_at", :null => false
23-
t.datetime "updated_at", :null => false
2422
t.integer "blogs_count", :default => 0
2523
end
2624

@@ -39,7 +37,6 @@
3937
t.integer "blog_id"
4038
t.text "content"
4139
t.datetime "created_at", :null => false
42-
t.datetime "updated_at", :null => false
4340
end
4441

4542
add_index "blog_comments", ["account_id"], :name => "index_blog_comments_on_account_id"
@@ -65,7 +62,7 @@
6562
end
6663

6764
add_index "blogs", ["account_id"], :name => "index_blogs_on_account_id"
68-
add_index "blogs", ["blog_content_id"], :name => "index_blogs_on_blog_content_id"
65+
add_index "blogs", ["content_updated_at"], :name => "index_blogs_on_content_updated_at"
6966

7067
create_table "taggings", :force => true do |t|
7168
t.integer "tag_id"

db/seeds.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66
# shell.say name
77
#
88
email = shell.ask "Which email do you want use for logging into admin?"
9+
name = shell.ask "What is your name?"
910
password = shell.ask "Tell me the password to use:"
1011

1112
shell.say ""
1213

13-
account = Account.create(:email => email, :name => "Foo", :surname => "Bar", :password => password, :password_confirmation => password, :role => "admin")
14+
account = Account.create(:email => email, :name => name, :password => password, :password_confirmation => password, :role => "admin")
1415

1516
if account.valid?
1617
shell.say "================================================================="
1718
shell.say "Account has been successfully created, now you can login with:"
1819
shell.say "================================================================="
1920
shell.say " email: #{email}"
21+
shell.say " name: #{name}"
2022
shell.say " password: #{password}"
2123
shell.say "================================================================="
2224
else

public/skins/default/content.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ body{ background:#bebebe url(bg.gif);}
1111
.header h1 .blog_name{ font-size:50px; line-height:50px; }
1212
.header h1 .blog_title{ font-size:30px; line-height:30px;}
1313
.header h2{ color:#fff; font-size:18px; font-weight:bold; }
14-
.header .write{ float:right; color:#fff; width:200px; text-align:right;}
14+
.header .write{ float:right; color:#fff; width:220px; text-align:right;}
1515
.header .write a{color:#fff; margin-right:20px; display:inline-block; height:20px; line-height:20px; vertical-align:middle; background:url(y.png) 0px -240px no-repeat; padding-left:20px;}
1616
.header .write a:hover{background:url(y.png) 0px -270px no-repeat; color:#f87b00;}
1717
.header .write input{ background:none; border:none; color:#fff;background: url(y.png) 0px -716px no-repeat; padding-left:20px;}

0 commit comments

Comments
 (0)