@@ -5,67 +5,43 @@ module PaginateV2::AutoPages
55 # This function is called right after the main generator is triggered by Jekyll
66 # This code is adapted from Stephen Crosby's code https://github.com/stevecrozz
77 def self . create_autopages ( site )
8-
98 # Get the configuration for the auto pages
10- autopage_config = Jekyll :: Utils . deep_merge_hashes ( DEFAULT , site . config [ 'autopages' ] || { } )
9+ autopage_config = site . config [ 'autopages' ] || { }
1110 pagination_config = Jekyll ::Utils . deep_merge_hashes ( Jekyll ::PaginateV2 ::Generator ::DEFAULT , site . config [ 'pagination' ] || { } )
1211
12+ # Simply gather all documents across all pages/posts/collections that we have
13+ # and store them under each collection name
14+ coll_docs = Utils . collect_all_docs ( site . collections )
15+ # we don't use the posts collection
16+ coll_docs . delete ( "posts" )
17+ coll_names = coll_docs . keys
18+
1319 # If disabled then don't do anything
1420 if !autopage_config [ 'enabled' ] || autopage_config [ 'enabled' ] . nil?
1521 Jekyll . logger . info "AutoPages:" , "Disabled/Not configured in site.config."
1622 return
1723 end
1824
19- autopages_log ( autopage_config , 'tags' , 'categories' , 'collections' )
20-
21- # TODO: Should I detect here and disable if we're running the legacy paginate code???!
22-
23- # Simply gather all documents across all pages/posts/collections that we have
24- # we could be generating quite a few empty pages but the logic is just vastly simpler than trying to
25- # figure out what tag/category belong to which collection.
26- posts_to_use = Utils . collect_all_docs ( site . collections )
25+ autopages_log ( autopage_config , *coll_names )
2726
28- ###############################################
29- # Generate the Tag pages if enabled
30- createtagpage_lambda = lambda do | autopage_tag_config , pagination_config , layout_name , tag , tag_original_name |
31- site . pages << TagAutoPage . new ( site , site . dest , autopage_tag_config , pagination_config , layout_name , tag , tag_original_name )
32- end
33- autopage_create ( autopage_config , pagination_config , posts_to_use , 'tags' , 'tags' , createtagpage_lambda ) # Call the actual function
34-
27+ coll_docs . each do |coll_name , coll_data |
28+ createcolpage_lambda = lambda do |autopage_col_config , doc |
29+ site . pages << AutoPage . new ( site , autopage_col_config , pagination_config , coll_name , doc )
30+ end
3531
36- ###############################################
37- # Generate the category pages if enabled
38- createcatpage_lambda = lambda do | autopage_cat_config , pagination_config , layout_name , category , category_original_name |
39- site . pages << CategoryAutoPage . new ( site , site . dest , autopage_cat_config , pagination_config , layout_name , category , category_original_name )
40- end
41- autopage_create ( autopage_config , pagination_config , posts_to_use , 'categories' , 'categories' , createcatpage_lambda ) # Call the actual function
42-
43- ###############################################
44- # Generate the Collection pages if enabled
45- createcolpage_lambda = lambda do | autopage_col_config , pagination_config , layout_name , coll_name , coll_original_name |
46- site . pages << CollectionAutoPage . new ( site , site . dest , autopage_col_config , pagination_config , layout_name , coll_name , coll_original_name )
32+ autopage_create ( autopage_config , coll_name , coll_data , createcolpage_lambda )
4733 end
48- autopage_create ( autopage_config , pagination_config , posts_to_use , 'collections' , '__coll' , createcolpage_lambda ) # Call the actual function
49-
5034 end # create_autopages
5135
52-
5336 # STATIC: this function actually performs the steps to generate the autopages. It uses a lambda function to delegate the creation of the individual
5437 # page types to the calling code (this way all features can reuse the logic).
5538 #
56- def self . autopage_create ( autopage_config , pagination_config , posts_to_use , configkey_name , indexkey_name , createpage_lambda )
57- if ! autopage_config [ configkey_name ] . nil?
39+ def self . autopage_create ( autopage_config , configkey_name , coll_data , createpage_lambda )
40+ unless autopage_config [ configkey_name ] . nil?
5841 ap_sub_config = autopage_config [ configkey_name ]
59- if ap_sub_config [ 'enabled' ]
60- # Roll through all documents in the posts collection and extract the tags
61- index_keys = Utils . ap_index_posts_by ( posts_to_use , indexkey_name ) # Cannot use just the posts here, must use all things.. posts, collections...
62-
63- index_keys . each do |index_key , value |
64- # Iterate over each layout specified in the config
65- ap_sub_config [ 'layouts' ] . each do | layout_name |
66- # Use site.dest here as these pages are never created in the actual source but only inside the _site folder
67- createpage_lambda . call ( ap_sub_config , pagination_config , layout_name , index_key , value [ -1 ] ) # the last item in the value array will be the display name
68- end
42+ if ap_sub_config [ 'enabled' ]
43+ coll_data . each do |doc |
44+ createpage_lambda . call ( ap_sub_config , doc )
6945 end
7046 end
7147 end
0 commit comments