<% local left_start = math.max(1, current_page - 5) %> <% local right_end = math.min(page_count, current_page + 5) %>
Page: <% if current_page > 5 then %> 1 <% if left_start > 2 then %> <% end %> <% end %> <% for i = left_start, current_page - 1 do%> <%= i %> <% end %> <% if page_count > 0 then %> <%= current_page %> <% end %> <% for i = current_page + 1, right_end do %> <%= i %> <% end %> <% if right_end < page_count then %> <% if right_end < page_count - 1 then %> <% end %> <%= page_count %> <% end %>