positions for the index and not found pages were messed up when importing site
This commit is contained in:
parent
02039159d7
commit
2402ef2cd4
@ -1,6 +1,6 @@
|
||||
GIT
|
||||
remote: git://github.com/floehopper/mocha.git
|
||||
revision: ef4439904bb8476a661ec184a406e7f19714642e
|
||||
revision: cc436649221e1895b5fc392247ce108db5ba8244
|
||||
specs:
|
||||
mocha (0.9.10.20101125155727)
|
||||
rake
|
||||
@ -157,7 +157,7 @@ GEM
|
||||
mimetype-fu (0.1.2)
|
||||
mongo (1.2.0)
|
||||
bson (>= 1.2.0)
|
||||
mongoid (2.0.0.rc.6)
|
||||
mongoid (2.0.0.rc.7)
|
||||
activemodel (~> 3.0)
|
||||
mongo (~> 1.2)
|
||||
tzinfo (~> 0.3.22)
|
||||
|
@ -5,7 +5,7 @@ module Locomotive
|
||||
def process
|
||||
context[:done] = {} # initialize the hash storing pages already processed
|
||||
|
||||
self.add_index_and_404
|
||||
self.add_page('index')
|
||||
|
||||
Dir[File.join(theme_path, 'templates', '**/*')].each do |template_path|
|
||||
|
||||
@ -16,6 +16,8 @@ module Locomotive
|
||||
self.add_page(fullpath)
|
||||
end
|
||||
|
||||
self.add_page('404')
|
||||
|
||||
# make sure all the pages were processed (redirection pages without template for instance)
|
||||
self.pages.each { |fullpath, attributes| self.add_page_without_template(fullpath.to_s) }
|
||||
end
|
||||
@ -95,6 +97,8 @@ module Locomotive
|
||||
end
|
||||
|
||||
def find_parent(fullpath)
|
||||
return nil if %w(index 404).include?(fullpath) # avoid cyclic issue
|
||||
|
||||
segments = fullpath.split('/')
|
||||
|
||||
return site.pages.root.first if segments.size == 1
|
||||
@ -109,28 +113,6 @@ module Locomotive
|
||||
parent || self.add_page(parent_fullpath)
|
||||
end
|
||||
|
||||
def add_index_and_404
|
||||
%w(index 404).each_with_index do |slug, position|
|
||||
page = site.pages.where({ :slug => slug, :depth => 0 }).first
|
||||
|
||||
page ||= sites.pages.build(:slug => slug, :parent => nil)
|
||||
|
||||
template = File.read(File.join(theme_path, 'templates', "#{slug}.liquid"))
|
||||
|
||||
self.replace_images!(template)
|
||||
|
||||
page.attributes = { :raw_template => template }.merge(self.pages[slug] || {})
|
||||
|
||||
page.position = position
|
||||
|
||||
page.save! rescue nil # TODO better error handling
|
||||
|
||||
site.reload
|
||||
|
||||
context[:done][slug] = page
|
||||
end
|
||||
end
|
||||
|
||||
def replace_images!(template)
|
||||
return if template.blank?
|
||||
|
||||
@ -160,7 +142,9 @@ module Locomotive
|
||||
position = nil
|
||||
fullpath = data.keys.first.to_s
|
||||
|
||||
unless %w(index 404).include?(fullpath)
|
||||
if %w(index 404).include?(fullpath)
|
||||
position = fullpath == 'index' ? 0 : 1
|
||||
else
|
||||
(segments = fullpath.split('/')).pop
|
||||
position_key = segments.empty? ? 'index' : segments.join('/')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user