@@ -227,6 +227,48 @@ def make_list(config, posts, dst, list_layout, item_layout, **params):
227
227
fwrite (dst_path , output )
228
228
229
229
230
+ def paginate_list (config , posts , dst_template , list_layout , item_layout , per_page , ** params ):
231
+ """Generate paginated blog list pages"""
232
+ total_pages = (len (posts ) + per_page - 1 ) // per_page
233
+
234
+ for page_num in range (total_pages ):
235
+ start_idx = page_num * per_page
236
+ end_idx = start_idx + per_page
237
+ page_posts = posts [start_idx :end_idx ]
238
+
239
+ items = []
240
+ for post in page_posts :
241
+ item_params = dict (params , ** post )
242
+ item_params ['summary' ] = truncate (post ['content' ], int (config ['general' ].get ('preview_words' , 150 )))
243
+ items .append (render (item_layout , ** item_params ))
244
+
245
+ page_params = dict (params )
246
+ page_params ['content' ] = '' .join (items )
247
+ page_params ['current_page' ] = page_num + 1
248
+ page_params ['total_pages' ] = total_pages
249
+ page_params ['prev_page' ] = page_num if page_num > 0 else None
250
+ page_params ['next_page' ] = page_num + 2 if page_num + 1 < total_pages else None
251
+
252
+
253
+ pagination_html = ""
254
+ if page_params ['prev_page' ]:
255
+ prev_link = "index.html" if page_params ['prev_page' ] == 1 else f"page{ page_params ['prev_page' ]} .html"
256
+ pagination_html += f'<a href="{ prev_link } ">Previous</a> '
257
+ if page_params ['next_page' ]:
258
+ pagination_html += f'<a href="page{ page_params ["next_page" ]} .html">Next</a>'
259
+
260
+ page_params ['pagination' ] = pagination_html
261
+
262
+ if page_num == 0 :
263
+ dst_path = render (dst_template , ** page_params )
264
+ else :
265
+ dst_path = dst_template .replace ("index.html" , f"page{ page_num + 1 } .html" )
266
+
267
+ output = render (list_layout , ** page_params )
268
+ log ('Rendering list page {} => {} ...' , page_num + 1 , dst_path )
269
+ fwrite (dst_path , output )
270
+
271
+
230
272
def main ():
231
273
""" Run manpageblog """
232
274
arguments = parse_arguments ()
@@ -289,8 +331,10 @@ def main():
289
331
# Create blogs
290
332
blog_posts = make_pages ('content/blog/*.md' , config ['processing' ]['output_path' ]+ '/blog/{{ slug }}/index.html' , post_layout , blog = 'blog' , ** params )
291
333
292
- # Create blog list pages
293
- make_list (config , blog_posts , config ['processing' ]['output_path' ]+ '/blog/index.html' , list_layout , item_layout , blog = 'blog' , title = 'Blog' , ** params )
334
+ # Create paginated blog list pages (3 posts per page)
335
+ paginate_list (config , blog_posts , config ['processing' ]['output_path' ]+ '/blog/index.html' ,
336
+ list_layout , item_layout , per_page = int (config ['general' ].get ('pagination' , 10 )), blog = 'blog' , title = 'Blog' , ** params )
337
+
294
338
295
339
# Create RSS feeds
296
340
make_list (config , blog_posts , config ['processing' ]['output_path' ]+ '/blog/rss.xml' , feed_xml , item_xml , blog = 'blog' , title = 'Blog' , ** params )
0 commit comments