forked from publify/publify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:fdv/publify
- Loading branch information
Showing
12 changed files
with
160 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,45 @@ | ||
class Admin::SeoController < Admin::BaseController | ||
cache_sweeper :blog_sweeper | ||
before_filter :set_setting, only: [:index, :titles] | ||
|
||
def index | ||
load_settings | ||
if File.exists? "#{::Rails.root.to_s}/public/robots.txt" | ||
@setting.robots = "" | ||
file = File.readlines("#{::Rails.root.to_s}/public/robots.txt") | ||
file.each do |line| | ||
@setting.robots << line | ||
end | ||
else | ||
build_robots | ||
end | ||
@setting.robots = Robot.new.rules | ||
end | ||
|
||
def permalinks | ||
if request.post? | ||
if params[:setting]['permalink_format'] and params[:setting]['permalink_format'] == 'custom' | ||
params[:setting]['permalink_format'] = params[:setting]['custom_permalink'] | ||
update_settings | ||
else | ||
set_setting | ||
if @setting.permalink_format != '/%year%/%month%/%day%/%title%' and | ||
@setting.permalink_format != '/%year%/%month%/%title%' and | ||
@setting.permalink_format != '/%title%' | ||
@setting.custom_permalink = @setting.permalink_format | ||
@setting.permalink_format = 'custom' | ||
end | ||
update | ||
return | ||
end | ||
|
||
load_settings | ||
if @setting.permalink_format != '/%year%/%month%/%day%/%title%' and | ||
@setting.permalink_format != '/%year%/%month%/%title%' and | ||
@setting.permalink_format != '/%title%' | ||
@setting.custom_permalink = @setting.permalink_format | ||
@setting.permalink_format = 'custom' | ||
end | ||
end | ||
|
||
def titles | ||
load_settings | ||
end | ||
|
||
def update | ||
if request.post? | ||
Blog.transaction do | ||
params[:setting].each { |k,v| this_blog.send("#{k.to_s}=", v) } | ||
this_blog.save | ||
flash[:notice] = _('config updated.') | ||
end | ||
|
||
save_robots unless params[:setting][:robots].blank? | ||
|
||
redirect_to :action => params[:from] | ||
end | ||
update_settings if request.post? | ||
rescue ActiveRecord::RecordInvalid | ||
render params[:from] | ||
end | ||
|
||
private | ||
def load_settings | ||
@setting = this_blog | ||
end | ||
|
||
def save_robots | ||
if File.writable? "#{::Rails.root.to_s}/public/robots.txt" | ||
robots = File.new("#{::Rails.root.to_s}/public/robots.txt", "r+") | ||
robots.write(params[:setting][:robots]) | ||
robots.close | ||
def update_settings | ||
if params[:setting]['permalink_format'] and params[:setting]['permalink_format'] == 'custom' | ||
params[:setting]['permalink_format'] = params[:setting]['custom_permalink'] | ||
end | ||
update_settings_with!(params) | ||
if params[:setting][:robots].present? | ||
Robot.new.add(params[:setting][:robots]) | ||
end | ||
redirect_to action: params[:from] | ||
end | ||
|
||
def build_robots | ||
robots = File.new("#{::Rails.root.to_s}/public/robots.txt", "w+") | ||
line = "User-agent: *\nAllow: /\nDisallow: /admin\n" | ||
robots.write(line) | ||
robots.close | ||
@setting.robots = line | ||
def set_setting | ||
@setting = this_blog | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class Robot | ||
|
||
FILE = "#{::Rails.root.to_s}/public/robots.txt" | ||
DEFAULT_LINE = "User-agent: *\nAllow: /\nDisallow: /admin\n" | ||
|
||
attr_reader :robots | ||
|
||
def initialize | ||
unless File.exists?(FILE) | ||
robots = File.new(FILE, "w+") | ||
robots.write(DEFAULT_LINE) | ||
robots.close | ||
end | ||
@robots = File.new(FILE, "r+") | ||
end | ||
|
||
def add(rules) | ||
if File.writable?(FILE) | ||
robots.write(rules) | ||
robots.close | ||
end | ||
end | ||
|
||
def rules | ||
robots.readlines.join('') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.