Commit d4cbe192 authored by Hans-Christoph Steiner's avatar Hans-Christoph Steiner

Merge branch 'category-browser-paging' into 'master'

Add pagination to app category detail pages

Add pagination to the app category detail pages as suggested in !52.

This could in sum be a solution for the issues #18 and #5.

See merge request !58

closes fdroid-website#479
closes #5
closes #18
parents ca8ec29a 8b0d38f5
Pipeline #217476345 passed with stage
in 2 minutes and 7 seconds
---
layout: page
title: " "
permalink: filled_by_script
pagination:
enabled: true
collection: filled_by_script
per_page: 30
trail:
before: 4
after: 4
permalink: '/:num/'
title: ':title'
sort_field: 'last_updated'
sort_reverse: true
---
{% assign app_category_escaped = page.app_category | escape %}
{% assign filtered_packages = site.packages | where_exp: "item", "item.categories contains app_category_escaped" | sort: "last_updated" | reverse %}
<h3>{{ site.data.strings.app_categories[page.app_category] }}</h3>
<div id="package-list">
{% for package in filtered_packages %}
{% for package in paginator.posts %}
{% include package-list-item.html package=package %}
{% endfor %}
{% include_cached browse-paginator-navigation.html paginator=paginator permalink=page.dir %}
</div>
---
layout: page
title: " "
permalink: /packages/
---
{% for app_category in site.app_categories %}
{% assign app_category_escaped = app_category | escape %}
......
......@@ -85,6 +85,10 @@ module FDroid
return code
end
def categories
return field('categories')
end
# Generates a hash of dumb strings to be used in templates.
# If a specific value is not present, then it will have a nil value.
# If a value can be localized, then it will choose the most appropriate
......
......@@ -20,18 +20,20 @@ module Jekyll
# @param [Jekyll::Site] site
# @param [string] base
# @param [string] app_category
def initialize(site, base, app_category)
# @param [string] app_category_id
def initialize(site, base, app_category, app_category_id)
@site = site
@base = base
@dir = 'categories'
# Avoid special characters in URL, otherwise language support doesn't work
app_category_url = Utils.slugify(app_category)
@name = "#{app_category_url}/index.html"
@name = "#{app_category_id}/index.html"
self.process(@name)
self.read_yaml(get_layout_dir, 'category-packages.html')
self.data['app_category'] = app_category
self.data['permalink'] = "/categories/#{app_category_id}/"
self.data['pagination']['collection'] = app_category_id
end
def get_layout_dir()
......
......@@ -37,8 +37,21 @@ module Jekyll
site.config["sass"]["load_paths"] << (File.expand_path "../../_sass", File.dirname(__FILE__))
end
# Enable pagination
if site.config["pagination"].nil? || site.config["pagination"].empty?
site.config["pagination"] = Hash.new
end
site.config["pagination"]["enabled"] = true
index = FDroid::IndexV1.download(site.config["fdroid-repo"], site.active_lang || 'en_US')
# Generate collection and detail page for every category
site.config["app_categories"].each do |app_category|
app_category_id = Utils.slugify(app_category)
site.collections[app_category_id] = Collection.new(site, app_category_id)
site.pages << FDroidCategoryDetailPage.new(site, site.source, app_category, app_category_id)
end
# Generate detail page for every package
site.collections["packages"] = Collection.new(site, "packages")
index.apps.each do |package|
......@@ -49,11 +62,17 @@ module Jekyll
# https://gitlab.com/fdroid/jekyll-fdroid/issues/38
site.pages << FDroidPackageDetailPage.new(site, site.source, package)
site.collections["packages"].docs << FDroidPackageDetailPage.new(site, site.source, package)
end
# Generate category pages with filtered package list
site.config["app_categories"].each do |category|
site.pages << FDroidCategoryDetailPage.new(site, site.source, category)
package.categories.each do |app_category|
app_category_id = app_category.dup
app_category_id.sub!('&amp;', '&')
app_category_id = Utils.slugify(app_category_id)
if site.collections[app_category_id].nil?
puts("Warning: App '#{package.package_name}' has unknown category '#{app_category}', will be ignored")
else
site.collections[app_category_id].docs << FDroidPackageDetailPage.new(site, site.source, package)
end
end
end
# Generate browsing pages
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment