jekyll-fdroid 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff2200559758f5c1f554c9d15b459692c6e67903
4
- data.tar.gz: 5346cf8b97ccdad7a363011e7ca5c55baf4afbc2
3
+ metadata.gz: 7d4628ad929d42b592bd9096caf753b7b0d4b811
4
+ data.tar.gz: ecc2b389a4768ba6ba7119fc1e6f044148c85291
5
5
  SHA512:
6
- metadata.gz: bfe955e63ed0c000938dc4d8a6492ff9e1e0b9eb4fe0294081489c85e23b0733942c054e8b5cd28749f9087466ebb45f65fbf2e3d9f193c3049bb1a46f99ad20
7
- data.tar.gz: 111e04d6070a328b4c35a68e39177e48003dae2916f1c1a6c80572c24f424b5ea006615eb71a4cb060576dc4186e6b9cad6a76183ad4bb5992846ec837d3e15d
6
+ metadata.gz: aa109fd573b0bc32dae7904af8185f05765ccccf5f29becaca0e9ea0c5f0aed262235ce2c99bfd24b2e425cddeeea3442a39ab15f3bd9a58efa756cac563060c
7
+ data.tar.gz: 405296432079dc71309eb57bf37f3133d93d17080288c89ecfbcf8c3bcd9755001752c2b6b80b72d69f9be3f6f9c439ecd9549f08afb1cf78cd927f6b4dd71f1
@@ -0,0 +1,26 @@
1
+ # F-Droid's Jekyll Plugin
2
+ #
3
+ # Copyright (C) 2017 Nico Alt
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as
7
+ # published by the Free Software Foundation, either version 3 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require 'nokogiri'
19
+ require 'open-uri'
20
+
21
+ class FDroidIndex
22
+ def getIndex(repo)
23
+ index = open(URI.parse(repo + '/index.xml')).read
24
+ Nokogiri::XML(index).xpath('fdroid').xpath('application')
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ # F-Droid's Jekyll Plugin
2
+ #
3
+ # Copyright (C) 2017 Nico Alt
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as
7
+ # published by the Free Software Foundation, either version 3 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "fdroid/FDroidIndex"
19
+ require "jekyll/ReadYamlPage"
20
+ require "jekyll/FDroidBrowsingPage"
21
+ require "jekyll/FDroidFilters"
22
+ require "jekyll/FDroidLastUpdatedPackagesTag"
23
+ require "jekyll/FDroidLatestPackagesTag"
24
+ require "jekyll/FDroidPackageDetailGenerator"
25
+ require "jekyll/FDroidPackageDetailPage"
26
+ require "jekyll/FDroidSearchAutocompleteTag"
27
+ require "lunr/LunrIndexer"
28
+ require "lunr/SearchIndexFile"
29
+ require "lunr/Javascript"
@@ -0,0 +1,31 @@
1
+ # F-Droid's Jekyll Plugin
2
+ #
3
+ # Copyright (C) 2017 Nico Alt
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as
7
+ # published by the Free Software Foundation, either version 3 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module Jekyll
19
+
20
+ class FDroidBrowsingPage < ReadYamlPage
21
+ def initialize(site, base)
22
+ @site = site
23
+ @base = base
24
+ @dir = "packages"
25
+ @name = "index.html"
26
+
27
+ self.process(@name)
28
+ self.read_yaml((File.expand_path "../../_pages", File.dirname(__FILE__)), 'browse.html')
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,179 @@
1
+ # F-Droid's Jekyll Plugin
2
+ #
3
+ # Copyright (C) 2017 Nico Alt
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as
7
+ # published by the Free Software Foundation, either version 3 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module Jekyll
19
+
20
+ module Filters
21
+
22
+ # Convert an Android SDK level into an Android version.
23
+ #
24
+ # input - Android SDK Level.
25
+ #
26
+ # Returns the Android version.
27
+ def android_sdk_level_to_version(input)
28
+ sdkLevel = @@AndroidSdkLevelToVersionRelation[input]
29
+ if not sdkLevel.nil?
30
+ return sdkLevel
31
+ end
32
+ return '?'
33
+ end
34
+
35
+ # Hash with relation between Android SDK Level and Android version
36
+ @@AndroidSdkLevelToVersionRelation = {
37
+ '1' => '1.0',
38
+ '2' => '1.1',
39
+ '3' => '1.5',
40
+ '4' => '1.6',
41
+ '5' => '2.0',
42
+ '6' => '2.0.1',
43
+ '7' => '2.1',
44
+ '8' => '2.2',
45
+ '9' => '2.3',
46
+ '10' => '2.3.3',
47
+ '11' => '3.0',
48
+ '12' => '3.1',
49
+ '13' => '3.2',
50
+ '14' => '4.0',
51
+ '15' => '4.0.3',
52
+ '16' => '4.1',
53
+ '17' => '4.2',
54
+ '18' => '4.3',
55
+ '19' => '4.4',
56
+ '20' => '4.4W',
57
+ '21' => '5.0',
58
+ '22' => '5.1',
59
+ '23' => '6.0',
60
+ '24' => '7.0',
61
+ '25' => '7.1'
62
+ }
63
+
64
+ # Convert a file size to a human-readable String.
65
+ # Source: https://codereview.stackexchange.com/q/9107
66
+ #
67
+ # input - File size in Bytes.
68
+ #
69
+ # Returns human-readable String.
70
+ def file_size_human_readable(input)
71
+ input = input.to_f
72
+ i = PREFIX.length - 1
73
+ while input > 512 && i > 0
74
+ i -= 1
75
+ input /= 1024
76
+ end
77
+ return ((input > 9 || input.modulo(1) < 0.1 ? '%d' : '%.1f') % input) + ' ' + PREFIX[i]
78
+ end
79
+ PREFIX = %W(TiB GiB MiB KiB B).freeze
80
+
81
+ # Convert a SPDX license identifier to its full name.
82
+ #
83
+ # input - SPDX license identifier.
84
+ #
85
+ # Returns full license name.
86
+ def get_license_name(input)
87
+ if input.nil? or input.empty?
88
+ return 'Unknown'
89
+ end
90
+ spdxLicense = @@SpdxLicenseNameToGnuUrlRelation[input]
91
+ if input.end_with? "+"
92
+ spdxLicense = @@SpdxLicenseNameToGnuUrlRelation[input.chomp('+')]
93
+ end
94
+ if not spdxLicense.nil?
95
+ if input.end_with? "+"
96
+ return spdxLicense['name'] + ' or later version'
97
+ end
98
+ return spdxLicense['name']
99
+ end
100
+ return input
101
+ end
102
+
103
+ # Convert a SPDX license identifier to its URL on GNU.org.
104
+ #
105
+ # input - SPDX license identifier.
106
+ #
107
+ # Returns URL on GNU.org.
108
+ def get_license_url(input)
109
+ if input.nil? or input.empty?
110
+ return ''
111
+ end
112
+ if input.end_with? "+"
113
+ input = input.chomp('+')
114
+ end
115
+ spdxLicense = @@SpdxLicenseNameToGnuUrlRelation[input]
116
+ if not spdxLicense.nil?
117
+ return spdxLicense['url']
118
+ end
119
+ return 'https://spdx.org/licenses/' + input + '.html'
120
+ end
121
+
122
+ # Hash with relation between SPDX license identifier and its full name and URL, mostly on GNU.org.
123
+ # For the beginning, I only used OSI approved and frequently used licenses.
124
+ @@SpdxLicenseNameToGnuUrlRelation = {
125
+ 'AGPL-3.0' => {
126
+ 'name' => 'GNU Affero General Public License v3.0',
127
+ 'url' => 'https://www.gnu.org/licenses/license-list.html#AGPLv3.0'
128
+ },
129
+ 'Apache-2.0' => {
130
+ 'name' => 'Apache License 2.0',
131
+ 'url' => 'https://www.gnu.org/licenses/license-list.html#apache2'
132
+ },
133
+ 'BSD-2-Clause' => {
134
+ 'name' => 'BSD 2-clause "Simplified" License',
135
+ 'url' => 'https://www.gnu.org/licenses/license-list.html#FreeBSD'
136
+ },
137
+ 'BSD-3-Clause' => {
138
+ 'name' => 'BSD 3-clause "New" or "Revised" License',
139
+ 'url' => 'https://www.gnu.org/licenses/license-list.html#ModifiedBSD'
140
+ },
141
+ 'GPL-2.0' => {
142
+ 'name' => 'GNU General Public License v2.0',
143
+ 'url' => 'https://www.gnu.org/licenses/license-list.html#GPLv2'
144
+ },
145
+ 'GPL-3.0' => {
146
+ 'name' => 'GNU General Public License v3.0',
147
+ 'url' => 'https://www.gnu.org/licenses/license-list.html#GNUGPLv3'
148
+ },
149
+ 'ISC' => {
150
+ 'name' => 'ISC License',
151
+ 'url' => 'https://www.gnu.org/licenses/license-list.en.html#ISC'
152
+ },
153
+ 'LGPL-2.1' => {
154
+ 'name' => 'GNU Lesser General Public License v2.1',
155
+ 'url' => 'https://www.gnu.org/licenses/license-list.html#LGPLv2.1'
156
+ },
157
+ 'LGPL-3.0' => {
158
+ 'name' => 'GNU Lesser General Public License v3.0',
159
+ 'url' => 'https://www.gnu.org/licenses/license-list.html#LGPLv3'
160
+ },
161
+ 'MIT' => {
162
+ 'name' => 'MIT License',
163
+ 'url' => 'https://www.gnu.org/licenses/license-list.html#X11License'
164
+ },
165
+ 'MPL-1.1' => {
166
+ 'name' => 'Mozilla Public License 1.1',
167
+ 'url' => 'https://www.gnu.org/licenses/license-list.html#MPL'
168
+ },
169
+ 'MPL-2.0' => {
170
+ 'name' => 'Mozilla Public License 2.0',
171
+ 'url' => 'https://www.gnu.org/licenses/license-list.html#MPL-2.0'
172
+ }
173
+ }
174
+ end
175
+ end
176
+
177
+ Liquid::Template.register_filter(
178
+ Jekyll::Filters
179
+ )
@@ -0,0 +1,33 @@
1
+ # F-Droid's Jekyll Plugin
2
+ #
3
+ # Copyright (C) 2017 Nico Alt
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as
7
+ # published by the Free Software Foundation, either version 3 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module Jekyll
19
+
20
+ class FDroidLastUpdatedPackagesTag < Liquid::Tag
21
+
22
+ def initialize(tag_name, text, tokens)
23
+ super
24
+ end
25
+
26
+ def render(context)
27
+ template = Liquid::Template.parse(IO.read((File.expand_path "../../_layouts/sidebar-lastupdated-packages.html", File.dirname(__FILE__))))
28
+ template.render(context)
29
+ end
30
+ end
31
+ end
32
+
33
+ Liquid::Template.register_tag('fdroid_show_last_updated_packages', Jekyll::FDroidLastUpdatedPackagesTag)
@@ -0,0 +1,33 @@
1
+ # F-Droid's Jekyll Plugin
2
+ #
3
+ # Copyright (C) 2017 Nico Alt
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as
7
+ # published by the Free Software Foundation, either version 3 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module Jekyll
19
+
20
+ class FDroidLatestPackagesTag < Liquid::Tag
21
+
22
+ def initialize(tag_name, text, tokens)
23
+ super
24
+ end
25
+
26
+ def render(context)
27
+ template = Liquid::Template.parse(IO.read((File.expand_path "../../_layouts/sidebar-latest-packages.html", File.dirname(__FILE__))))
28
+ template.render(context)
29
+ end
30
+ end
31
+ end
32
+
33
+ Liquid::Template.register_tag('fdroid_show_latest_packages', Jekyll::FDroidLatestPackagesTag)
@@ -0,0 +1,68 @@
1
+ # F-Droid's Jekyll Plugin
2
+ #
3
+ # Copyright (C) 2017 Nico Alt
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as
7
+ # published by the Free Software Foundation, either version 3 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module Jekyll
19
+
20
+ class FDroidPackagesGenerator < Generator
21
+ attr_accessor :alreadyBuilt
22
+
23
+ safe true
24
+ priority :highest
25
+
26
+ def generate(site)
27
+ # generator will only run on first build, not because of auto-regeneration
28
+ if @alreadyBuilt != true
29
+ @alreadyBuilt = true
30
+
31
+ # Add plugin's SASS directory so site's list of SASS directories
32
+ if site.config["sass"].nil? || site.config["sass"].empty?
33
+ site.config["sass"] = Hash.new
34
+ end
35
+ if site.config["sass"]["load_paths"].nil? || site.config["sass"]["load_paths"].empty?
36
+ site.config["sass"]["load_paths"] = ["_sass", (File.expand_path "../../_sass", File.dirname(__FILE__))]
37
+ else
38
+ site.config["sass"]["load_paths"] << (File.expand_path "../../_sass", File.dirname(__FILE__))
39
+ end
40
+
41
+ # Enable pagination
42
+ if site.config["pagination"].nil? || site.config["pagination"].empty?
43
+ site.config["pagination"] = Hash.new
44
+ end
45
+ site.config["pagination"]["enabled"] = true
46
+
47
+ packages = FDroidIndex.new.getIndex(site.config["fdroid-repo"])
48
+
49
+ Jekyll::LunrJsSearch::Indexer.new.generate(site, packages)
50
+
51
+ # Generate detail page for every package
52
+ site.collections["packages"] = Collection.new(site, "packages")
53
+ packages.each do |package|
54
+ # This page needs to be created twice, once for site.pages, and once for site.collections.
55
+ # If not, then the i18n code in jekyll-polyglot will end up processing the page twice, as
56
+ # it iterates over all pages and all packages. The end result is a double prefix for "/en/en"
57
+ # for any links in the page.
58
+ # https://gitlab.com/fdroid/jekyll-fdroid/issues/38
59
+ site.pages << FDroidPackageDetailPage.new(site, site.source, package)
60
+ site.collections["packages"].docs << FDroidPackageDetailPage.new(site, site.source, package)
61
+ end
62
+ # Generate browsing pages
63
+ site.includes_load_paths << (File.expand_path "../../_includes", File.dirname(__FILE__))
64
+ site.pages << FDroidBrowsingPage.new(site, site.source)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,123 @@
1
+ # F-Droid's Jekyll Plugin
2
+ #
3
+ # Copyright (C) 2017 Nico Alt
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as
7
+ # published by the Free Software Foundation, either version 3 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module Jekyll
19
+
20
+ class FDroidPackageDetailPage < ReadYamlPage
21
+ def initialize(site, base, package)
22
+ $package = package
23
+ @site = site
24
+ @base = base
25
+ @dir = "packages"
26
+ @name = $package.at_xpath('id').content + "/index.html"
27
+
28
+ self.process(@name)
29
+ self.read_yaml(getLayoutDir(), 'package.html')
30
+
31
+ getGeneralFrontMatterData
32
+ getPackagesFrontMatterData
33
+ end
34
+
35
+ def getLayoutDir()
36
+ layout_dir_override = File.join(site.source, "_layouts")
37
+ if File.exists? File.join(layout_dir_override, "package.html")
38
+ return layout_dir_override
39
+ else
40
+ return File.expand_path "../../_layouts", File.dirname(__FILE__)
41
+ end
42
+ end
43
+
44
+ def getGeneralFrontMatterData
45
+ # Hash with relation between Jekyll and XML variable name
46
+ assignments = {
47
+ "added" => "added",
48
+ "antifeatures" => "antifeatures",
49
+ "bitcoin" => "bitcoin",
50
+ "categories" => "categories",
51
+ "changelog" => "changelog",
52
+ "description" => "desc",
53
+ "donate" => "donate",
54
+ "flattr" => "flattr",
55
+ "icon" => "icon",
56
+ "issueTracker" => "tracker",
57
+ "lastUpdated" => "lastupdated",
58
+ "license" => "license",
59
+ "suggestedVersionCode" => "marketvercode",
60
+ "suggestedVersion" => "marketversion",
61
+ "package" => "id",
62
+ "sourceCode" => "source",
63
+ "summary" => "summary",
64
+ "title" => "name",
65
+ "webSite" => "web"
66
+ }
67
+ # Add information from XML to front matter
68
+ assignments.each do |jekyll, xml|
69
+ addGeneralFrontMatterData(jekyll, xml)
70
+ end
71
+ self.data["beautifulURL"] = "/packages/" + self.data["package"]
72
+ end
73
+
74
+ def addGeneralFrontMatterData(jekyll, xml)
75
+ xmlData = $package.at_xpath(xml)
76
+ if xmlData != nil
77
+ self.data[jekyll] = xmlData.content
78
+ end
79
+ end
80
+
81
+ # Hash with relation between Jekyll and XML variable names for the package metadata
82
+ @@jekyllToXmlPackageAssignments = {
83
+ "added" => "added",
84
+ "apkName" => "apkname",
85
+ "hash" => "hash",
86
+ "nativeCode" => "nativecode",
87
+ "maxSDKVersion" => "maxsdkver",
88
+ "permissions" => "permissions",
89
+ "sdkVersion" => "sdkver",
90
+ "sig" => "sig",
91
+ "size" => "size",
92
+ "srcName" => "srcname",
93
+ "targetSdkVersion" => "targetSdkVersion",
94
+ "version" => "version",
95
+ "versionCode" => "versioncode",
96
+ }
97
+
98
+ def getPackagesFrontMatterData
99
+ self.data["packages"] = $package.xpath('package').map { |package| getPackageFromXml(package) }
100
+ end
101
+
102
+ def getPackageFromXml(packageXml)
103
+ packageInformation = Hash.new
104
+
105
+ # Add information from XML to front matter
106
+ @@jekyllToXmlPackageAssignments.each do |jekyll, xml|
107
+ xmlData = packageXml.at_xpath(xml)
108
+ if xmlData == nil
109
+ next
110
+ end
111
+
112
+ # nativeCode and permissions can be comma separated arrays
113
+ if ["nativeCode", "permissions"].include? jekyll
114
+ packageInformation[jekyll] = xmlData.content.split(",")
115
+ else
116
+ packageInformation[jekyll] = xmlData.content
117
+ end
118
+ end
119
+
120
+ return packageInformation
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,45 @@
1
+ # F-Droid's Jekyll Plugin
2
+ #
3
+ # Copyright (C) 2017 Peter Serwylo
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as
7
+ # published by the Free Software Foundation, either version 3 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module Jekyll
19
+
20
+ class FDroidSearchTemplateableAutocompleteBlock < Liquid::Block
21
+ def self.render_template(context, template)
22
+ context['result_item_template'] = template
23
+ context['search_id'] = rand(1000000)
24
+
25
+ path = "../../_layouts/search-autocomplete.html"
26
+ template = Liquid::Template.parse(IO.read((File.expand_path path, File.dirname(__FILE__))))
27
+ template.render(context)
28
+ end
29
+
30
+ def render(context)
31
+ FDroidSearchTemplateableAutocompleteBlock.render_template(context, super.to_s)
32
+ end
33
+ end
34
+
35
+ class FDroidSearchAutocompleteTag < Liquid::Tag
36
+ def render(context)
37
+ path = "../../_includes/search-autocomplete-default-result-template.html"
38
+ result_item_template = IO.read((File.expand_path path, File.dirname(__FILE__)))
39
+ FDroidSearchTemplateableAutocompleteBlock.render_template(context, result_item_template)
40
+ end
41
+ end
42
+ end
43
+
44
+ Liquid::Template.register_tag('fdroid_search_autocomplete', Jekyll::FDroidSearchAutocompleteTag)
45
+ Liquid::Template.register_tag('fdroid_search_autocomplete_with_template', Jekyll::FDroidSearchTemplateableAutocompleteBlock)
@@ -0,0 +1,40 @@
1
+ # F-Droid's Jekyll Plugin
2
+ #
3
+ # Copyright (C) 2017 Nico Alt
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as
7
+ # published by the Free Software Foundation, either version 3 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ # Found at https://github.com/ggreer/jekyll-gallery-generator/blob/master/lib/jekyll-gallery-generator.rb#L69
19
+
20
+ module Jekyll
21
+
22
+ class ReadYamlPage < Page
23
+ # We need do define it ourself because the templates are in the plugin's directory
24
+ def read_yaml(base, name, opts = {})
25
+ begin
26
+ self.content = File.read(File.join(base.to_s, name.to_s), (site ? site.file_read_opts : {}).merge(opts))
27
+ if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
28
+ self.content = $POSTMATCH
29
+ self.data = SafeYAML.load($1)
30
+ end
31
+ rescue SyntaxError => e
32
+ Jekyll.logger.warn "YAML Exception reading #{File.join(base.to_s, name.to_s)}: #{e.message}"
33
+ rescue Exception => e
34
+ Jekyll.logger.warn "Error reading file #{File.join(base.to_s, name.to_s)}: #{e.message}"
35
+ end
36
+
37
+ self.data ||= {}
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ # From the MIT licensed file here:
3
+ #
4
+ # https://github.com/slashdotdash/jekyll-lunr-js-search/blob/master/lib/jekyll_lunr_js_search/javascript.rb
5
+ #
6
+
7
+ require "v8"
8
+ require "json"
9
+
10
+ class V8::Object
11
+ def to_json
12
+ @context['JSON']['stringify'].call(self)
13
+ end
14
+
15
+ def to_hash
16
+ JSON.parse(to_json, :max_nesting => false)
17
+ end
18
+ end
@@ -0,0 +1,109 @@
1
+ #
2
+ # Adapted from the MIT licensed Jekyll.LunrJsSearch.Indexer class at:
3
+ #
4
+ # https://github.com/slashdotdash/jekyll-lunr-js-search/blob/master/lib/jekyll_lunr_js_search/indexer.rb
5
+ #
6
+ # The intent is to stay as close to that as possible, so that future patches could potentially be applied.
7
+ #
8
+
9
+ require 'fileutils'
10
+ require 'net/http'
11
+ require 'json'
12
+ require 'uri'
13
+ require 'v8'
14
+
15
+ module Jekyll
16
+ module LunrJsSearch
17
+ class Indexer
18
+ def generate(site, packages)
19
+ @js_dir = 'js'
20
+
21
+ ctx = V8::Context.new
22
+ ctx.load(Indexer.path_to_asset('bower_components/lunr.js/lunr.js'))
23
+
24
+ ctx['indexer'] = proc do |this|
25
+ this.ref('id')
26
+ this.field('name')
27
+ this.field('summary')
28
+ end
29
+
30
+ ctx.eval('builder = new lunr.Builder')
31
+ ctx.eval('builder.pipeline.add(lunr.trimmer, lunr.stopWordFilter)')
32
+ ctx.eval('indexer.call(builder, builder)')
33
+
34
+ @lunr_version = ctx.eval('lunr.version')
35
+ @docs = {}
36
+
37
+ Jekyll.logger.info "Lunr:", "Creating search index (lunr.js version #{@lunr_version})..."
38
+
39
+ @site = site
40
+
41
+ packages.each_with_index do |package, i|
42
+ package_name = package['id']
43
+ name = Indexer.content_from_xml(package, 'name')
44
+ icon = Indexer.content_from_xml(package, 'icon')
45
+ summary = Indexer.content_from_xml(package, 'summary')
46
+
47
+ doc = {
48
+ 'id' => i,
49
+ 'packageName' => package_name,
50
+ 'icon' => icon,
51
+ 'name' => name,
52
+ 'summary' => summary
53
+ }
54
+
55
+ ctx['builder'].add(doc)
56
+ @docs[i] = doc
57
+
58
+ Jekyll.logger.debug "Lunr:", package_name
59
+ end
60
+
61
+ @index = ctx.eval('builder.build()')
62
+
63
+ FileUtils.mkdir_p(File.join(site.dest, @js_dir))
64
+ filename = File.join(@js_dir, 'index.json')
65
+
66
+ total = {
67
+ "docs" => @docs,
68
+ "index" => @index.to_hash
69
+ }
70
+
71
+ filepath = File.join(site.dest, filename)
72
+ File.open(filepath, "w") { |f| f.write(JSON.dump(total)) }
73
+ Jekyll.logger.info "Lunr:", "Index ready (lunr.js v#{@lunr_version})"
74
+ added_files = [filename]
75
+
76
+ site_js = File.join(site.dest, @js_dir)
77
+ extras = [
78
+ 'assets/fdroid-search-autocomplete.js',
79
+ 'bower_components/lunr.js/lunr.js',
80
+ 'bower_components/mustache.js/mustache.min.js',
81
+ 'bower_components/awesomplete/awesomplete.min.js',
82
+ 'bower_components/awesomplete/awesomplete.css'
83
+ ]
84
+ Jekyll.logger.info "Lunr:", "Added required assets to #{@js_dir}"
85
+ extras.each do |path|
86
+ src = Indexer.path_to_asset(path)
87
+ Jekyll.logger.debug "Lunr:", "Copying asset from #{src} to #{site_js}"
88
+ FileUtils.cp(src, site_js)
89
+ added_files.push(File.join(@js_dir, File.basename(src)))
90
+ end
91
+
92
+ # Keep the written files from being cleaned by Jekyll
93
+ added_files.each do |filename|
94
+ site.static_files << SearchIndexFile.new(site, site.dest, "/", filename)
95
+ end
96
+ end
97
+
98
+ def self.path_to_asset(path)
99
+ return File.join(File.dirname(__FILE__), "../../#{path}")
100
+ end
101
+
102
+ def self.content_from_xml(xml_node, element_name)
103
+ xml_data = xml_node.at_xpath(element_name)
104
+ return xml_data == nil ? nil : xml_data.content
105
+ end
106
+
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,16 @@
1
+ #
2
+ # From the MIT licensed file here:
3
+ #
4
+ # https://github.com/slashdotdash/jekyll-lunr-js-search/blob/master/lib/jekyll_lunr_js_search/search_index_file.rb
5
+ #
6
+
7
+ module Jekyll
8
+ module LunrJsSearch
9
+ class SearchIndexFile < Jekyll::StaticFile
10
+ # Override write as the index.json index file has already been created
11
+ def write(dest)
12
+ true
13
+ end
14
+ end
15
+ end
16
+ end
metadata CHANGED
@@ -1,22 +1,90 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-fdroid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nico Alt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-14 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2017-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jekyll-include-cache
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jekyll-paginate-v2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "<="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.7.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "<="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.7.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: therubyracer
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.12'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.12'
13
69
  description: Browse packages of a F-Droid repository.
14
70
  email: nicoalt@posteo.org
15
71
  executables: []
16
72
  extensions: []
17
73
  extra_rdoc_files: []
18
74
  files:
19
- - lib/fdroid.rb
75
+ - lib/fdroid/FDroidIndex.rb
76
+ - lib/jekyll-fdroid.rb
77
+ - lib/jekyll/FDroidBrowsingPage.rb
78
+ - lib/jekyll/FDroidFilters.rb
79
+ - lib/jekyll/FDroidLastUpdatedPackagesTag.rb
80
+ - lib/jekyll/FDroidLatestPackagesTag.rb
81
+ - lib/jekyll/FDroidPackageDetailGenerator.rb
82
+ - lib/jekyll/FDroidPackageDetailPage.rb
83
+ - lib/jekyll/FDroidSearchAutocompleteTag.rb
84
+ - lib/jekyll/ReadYamlPage.rb
85
+ - lib/lunr/Javascript.rb
86
+ - lib/lunr/LunrIndexer.rb
87
+ - lib/lunr/SearchIndexFile.rb
20
88
  homepage: https://gitlab.com/fdroid/jekyll-fdroid
21
89
  licenses:
22
90
  - AGPL-3.0
@@ -1,5 +0,0 @@
1
- class FDroid
2
- def self.hi
3
- puts "Welcome to F-Droid!"
4
- end
5
- end