2121require 'jekyll/reader'
2222require 'jekyll/cleaner'
2323require 'fileutils'
24+ require 'pathname'
2425
2526module Jekyll
2627
@@ -64,7 +65,7 @@ def read
6465 read_directories
6566
6667 if @site . config [ 'shared_dir' ]
67- read_directories @site . config [ 'shared_dir' ]
68+ read_directories File . join ( '..' , @site . config [ 'shared_dir' ] )
6869 end
6970
7071 sort_files!
@@ -74,6 +75,11 @@ def read
7475
7576 end
7677
78+
79+ # Move the _shared directories to the correct location
80+ # (very hacky - we move all the files to the correct
81+ # location with a hook after the site is written/rendered)
82+
7783 def self . sync_dir ( cur , base , dest )
7884 Dir . glob ( File . join ( cur , '*' ) , File ::FNM_DOTMATCH ) . each do |f |
7985
@@ -83,20 +89,17 @@ def self.sync_dir(cur, base, dest)
8389 if File . basename ( f ) == '.' or File . basename ( f ) == '..'
8490 next
8591 elsif File . directory? ( f )
86- if not File . exists? ( dest_dir )
87- Dir . mkdir ( dest_dir )
88- end
92+ if not File . exists? ( dest_dir )
93+ Dir . mkdir ( dest_dir )
94+ end
8995 sync_dir ( f , base , dest )
90- Dir . rmdir ( f )
96+ Dir . rmdir ( f )
9197 else
92- FileUtils . mv ( f , dest_dir )
98+ FileUtils . mv ( f , dest_dir )
9399 end
94100 end
95101 end
96102
97- # Move the _shared directories to the correct location
98- # (very hacky)
99-
100103 Jekyll ::Hooks . register :site , :post_write do |site |
101104 base_shared = File . basename ( site . config [ 'shared_dir' ] )
102105 shared_dir = File . join ( site . dest , base_shared )
@@ -132,29 +135,26 @@ def paginate(site, page)
132135 if num_page > 1
133136
134137 # Here is our monkey patch
135- if site . config [ 'shared_pagination' ] == true
136- base = File . expand_path ( File . join ( site . source , '..' ) )
138+ if site . config [ 'shared_pagination' ] == true
139+ base = File . expand_path ( File . join ( site . source , '..' ) )
137140 newpage = Page . new ( site , base , page . dir , page . name )
138141 else
139- newpage = Page . new ( site , site . source , page . dir , page . name )
140- end
141- newpage . pager = pager
142+ newpage = Page . new ( site , site . source , page . dir , page . name )
143+ end
144+
145+ newpage . pager = pager
142146 newpage . dir = Pager . paginate_path ( site , num_page )
143147 site . pages << newpage
144148 else
145149 page . pager = pager
146150 end
151+ end
147152 end
148153 end
149-
150- end
151154
152155 end
153-
154156 rescue LoadError
155157 # not installed
156158 end
157159
158-
159-
160160end
0 commit comments