Skip to content

Commit b7e5e92

Browse files
committedFeb 21, 2017
Update pkgindex plugins for themes site
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
1 parent 2d5abe5 commit b7e5e92

12 files changed

+90
-11
lines changed
 

‎site/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This site requires:
2+
3+
* Nikola
4+
* site-requirements.txt installed

‎site/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
PKGINDEX_CONFIG = {
3838
'extension': '.plugin',
3939
'versions_supported': [7],
40+
'json_filename': 'plugins.json',
4041
}
4142

4243
plugins_submenu = (

‎v7/pkgindex/README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@ Package indexes are sites like <https://plugins.getnikola.com/>. They provide
99
both a human-friendly interface (website), and a computer-friendly interface
1010
(JSON file). The generated package indexes are compatible with Nikola’s plugin
1111
and theme install features; however, they can be modified to work with any
12-
other packaging system (with some Python code)
12+
other packaging system (with some Python code modification).
13+
14+
Users
15+
-----
16+
17+
* [Nikola Plugins](https://plugins.getnikola.com/) — uses default plugin set [(source)](https://github.com/getnikola/plugins/tree/master/site)
18+
* [Nikola Themes](https://themes.getnikola.com/) — uses default plugin set and a custom plugin for screenshots and demos [(source)](https://github.com/getnikola/nikola-themes/tree/master/site)

‎v7/pkgindex/conf.py.sample

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ PKGINDEX_DIRS = {
99
# * dirname_as_title takes post title (package name) from directory name
1010
# * parse_plugin_file parse .plugin file and other Nikola-specific data
1111
# (used on plugins.getnikola.com)
12+
# * parse_theme_info parse files related to Nikola themes
13+
# (used on themes.getnikola.com)
1214
# * add_category add category meta data (useful with functools.partial)
1315
# You may add custom callables to those lists.
1416
PKGINDEX_HANDLERS = {
@@ -22,6 +24,7 @@ PKGINDEX_HANDLERS = {
2224
PKGINDEX_CONFIG = {
2325
'extension': '.plugin',
2426
'versions_supported': [7],
27+
'json_filename': 'plugins.json',
2528
}
2629

2730
# Required supporting config. You may change `.plugin` to anything else.

‎v7/pkgindex/pkgindex.plugin

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ MinVersion = 7.8.2
88

99
[Documentation]
1010
Author = Chris Warrick
11-
Version = 0.1.0
11+
Version = 0.2.0
1212
Website = https://plugins.getnikola.com/
1313
Description = Generate package indexes (meta-plugin)

‎v7/pkgindex/pkgindex.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
class PackageIndex(ConfigPlugin):
1313
"""Generate package indexes (meta-plugin)."""
1414

15-
name = "pkgindex_scan"
15+
name = "pkgindex"

‎v7/pkgindex_compiler/pkgindex_compiler.plugin

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ MinVersion = 7.8.1+
88

99
[Documentation]
1010
Author = Chris Warrick, Roberto Alsina
11-
Version = 0.1.0
11+
Version = 0.2.0
1212
Website = https://plugins.getnikola.com/
1313
Description = Compile pages in package indexes

‎v7/pkgindex_compiler/pkgindex_compiler.py

+49-1
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,61 @@ def parse_plugin_file(post, pkg_dir, config):
139139
return data
140140

141141

142+
def parse_theme_info(post, pkg_dir, config):
143+
theme = os.path.basename(pkg_dir)
144+
data = {}
145+
data['name'] = theme
146+
data['tags'] = 'theme'
147+
out_path = post.folder_relative + '/' + theme
148+
demo_dir = config['demo_screenshots_map'].get(out_path, out_path)
149+
data['previewimage'] = '/' + demo_dir + '.png'
150+
data['previewimage_thumbnail'] = '/' + demo_dir + '.thumbnail.png'
151+
data['demo_link'] = '/' + demo_dir + '/demo/'
152+
conf_sample = os.path.join(pkg_dir, 'conf.py.sample')
153+
engine = os.path.join(pkg_dir, 'engine')
154+
parent = os.path.join(pkg_dir, 'parent')
155+
156+
if os.path.exists(conf_sample):
157+
with io.open(conf_sample, 'r', encoding='utf-8') as f:
158+
data['confpy'] = pygments.highlight(
159+
f.read(),
160+
PythonLexer(), utils.NikolaPygmentsHTML(theme + '_conf_sample', linenos=False))
161+
else:
162+
data['confpy'] = None
163+
164+
if os.path.exists(engine):
165+
with io.open(engine, 'r', encoding='utf-8') as f:
166+
data['engine'] = f.read().strip()
167+
else:
168+
data['engine'] = 'mako'
169+
170+
if os.path.exists(parent):
171+
with io.open(parent, 'r', encoding='utf-8') as f:
172+
data['parent'] = f.read().strip()
173+
elif theme == 'base':
174+
pass
175+
else:
176+
raise ValueError("Theme {0} has no parent.".format(theme))
177+
178+
data['chain'] = utils.get_theme_chain(theme, [os.path.dirname(pkg_dir), 'themes'])
179+
data['chain'] = [os.path.basename(i) for i in reversed(data['chain'])]
180+
data['bootswatch'] = (('bootstrap' in data['chain'] or
181+
'bootstrap-jinja' in data['chain'] or
182+
'bootstrap3-jinja' in data['chain'] or
183+
'bootstrap3' in data['chain']) and
184+
'bootstrap3-gradients' not in data['chain'])
185+
186+
return data
187+
188+
142189
def add_category(post, pkg_dir, config, args):
143190
return {'category': args}
144191

145192

146193
BUILTIN_HANDLERS = {
147194
'dirname_as_title': dirname_as_title,
148195
'parse_plugin_file': parse_plugin_file,
196+
'parse_theme_info': parse_theme_info,
149197
'add_category': add_category
150198
}
151199

@@ -182,7 +230,7 @@ def read_metadata(self, post, file_metadata_regexp=None, unslugify_titles=False,
182230
raise Exception("PKGINDEX_CONFIG not found")
183231

184232
pkg_dir = os.path.split(post.source_path)[0]
185-
top_dir = os.path.dirname(pkg_dir)
233+
top_dir = post.folder_relative
186234
metadata = {'slug': os.path.basename(pkg_dir)}
187235
for handler in self.site.config['PKGINDEX_HANDLERS'][top_dir]:
188236
if isinstance(handler, tuple):

‎v7/pkgindex_scan/pkgindex_scan.plugin

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ MinVersion = 7.8.1+
88

99
[Documentation]
1010
Author = Chris Warrick
11-
Version = 0.1.0
11+
Version = 0.2.0
1212
Website = https://plugins.getnikola.com/
1313
Description = Scan packages for package indexes

‎v7/pkgindex_scan/pkgindex_scan.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def scan(self):
4949
if 'PKGINDEX_CONFIG' not in self.site.config:
5050
return []
5151
config = self.site.config['PKGINDEX_CONFIG']
52-
plugin_compiler = self.site.get_compiler('sample' + config['extension'])
52+
compiler = self.site.get_compiler('sample' + config['extension'])
5353
if not self.site.quiet:
5454
print("Scanning package index posts...", end='', file=sys.stderr)
5555
timeline = []
@@ -68,7 +68,22 @@ def scan(self):
6868
False,
6969
self.site.MESSAGES,
7070
template_name,
71-
plugin_compiler
71+
compiler
72+
)
73+
post.is_two_file = True
74+
timeline.append(post)
75+
self.site.pkgindex_entries[topdir].append(post)
76+
77+
if 'special_entries' in config:
78+
for source_path, destination, template_name, topdir in config['special_entries']:
79+
post = Post(
80+
source_path,
81+
self.site.config,
82+
destination,
83+
False,
84+
self.site.MESSAGES,
85+
template_name,
86+
compiler
7287
)
7388
post.is_two_file = True
7489
timeline.append(post)

‎v7/pkgindex_zip/pkgindex_zip.plugin

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ MinVersion = 7.8.1+
88

99
[Documentation]
1010
Author = Chris Warrick
11-
Version = 0.1.0
11+
Version = 0.2.0
1212
Website = https://plugins.getnikola.com/
1313
Description = Generate ZIP (and JSON) files for package indexes

‎v7/pkgindex_zip/pkgindex_zip.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ def gen_tasks(self):
8080
for post in posts:
8181
directory = os.path.dirname(post.source_path)
8282
pkg_name = os.path.basename(directory)
83+
if pkg_name in self.kw['pkgindex_config'].get('zip_ignore', []):
84+
continue
8385
destination = os.path.join(
8486
self.kw['output_folder'],
8587
self.kw['pkgindex_dirs'][dir][0],
@@ -98,7 +100,7 @@ def gen_tasks(self):
98100
# Get list of dependencies and files to zip
99101
for root, dirs, files in os.walk(directory):
100102
for file in files:
101-
if file.endswith(('.pyc', '.DS_Store')):
103+
if file.endswith(('.pyc', '.DS_Store')) or file == '.git':
102104
continue
103105
zip_files.append((os.path.join(root, file),
104106
os.path.join(root[d:], file)))
@@ -118,7 +120,7 @@ def gen_tasks(self):
118120
destination = os.path.join(
119121
self.kw['output_folder'],
120122
self.kw['pkgindex_dirs'][dir][0],
121-
'plugins.json'
123+
self.kw['pkgindex_config']['json_filename']
122124
)
123125
yield utils.apply_filters({
124126
'basename': self.name,

0 commit comments

Comments
 (0)
Please sign in to comment.