Skip to content
Permalink
Browse files

Update pkgindex plugins for themes site

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Feb 21, 2017
1 parent 2d5abe5 commit b7e5e922d27eea7f066c64dd270b3ff7c48fde9a
@@ -0,0 +1,4 @@
This site requires:

* Nikola
* site-requirements.txt installed
@@ -37,6 +37,7 @@
PKGINDEX_CONFIG = {
'extension': '.plugin',
'versions_supported': [7],
'json_filename': 'plugins.json',
}

plugins_submenu = (
@@ -9,4 +9,10 @@ Package indexes are sites like <https://plugins.getnikola.com/>. They provide
both a human-friendly interface (website), and a computer-friendly interface
(JSON file). The generated package indexes are compatible with Nikola’s plugin
and theme install features; however, they can be modified to work with any
other packaging system (with some Python code)
other packaging system (with some Python code modification).

Users
-----

* [Nikola Plugins](https://plugins.getnikola.com/) — uses default plugin set [(source)](https://github.com/getnikola/plugins/tree/master/site)
* [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)
@@ -9,6 +9,8 @@ PKGINDEX_DIRS = {
# * dirname_as_title takes post title (package name) from directory name
# * parse_plugin_file parse .plugin file and other Nikola-specific data
# (used on plugins.getnikola.com)
# * parse_theme_info parse files related to Nikola themes
# (used on themes.getnikola.com)
# * add_category add category meta data (useful with functools.partial)
# You may add custom callables to those lists.
PKGINDEX_HANDLERS = {
@@ -22,6 +24,7 @@ PKGINDEX_HANDLERS = {
PKGINDEX_CONFIG = {
'extension': '.plugin',
'versions_supported': [7],
'json_filename': 'plugins.json',
}

# Required supporting config. You may change `.plugin` to anything else.
@@ -8,6 +8,6 @@ MinVersion = 7.8.2

[Documentation]
Author = Chris Warrick
Version = 0.1.0
Version = 0.2.0
Website = https://plugins.getnikola.com/
Description = Generate package indexes (meta-plugin)
@@ -12,4 +12,4 @@
class PackageIndex(ConfigPlugin):
"""Generate package indexes (meta-plugin)."""

name = "pkgindex_scan"
name = "pkgindex"
@@ -8,6 +8,6 @@ MinVersion = 7.8.1+

[Documentation]
Author = Chris Warrick, Roberto Alsina
Version = 0.1.0
Version = 0.2.0
Website = https://plugins.getnikola.com/
Description = Compile pages in package indexes
@@ -139,13 +139,61 @@ def parse_plugin_file(post, pkg_dir, config):
return data


def parse_theme_info(post, pkg_dir, config):
theme = os.path.basename(pkg_dir)
data = {}
data['name'] = theme
data['tags'] = 'theme'
out_path = post.folder_relative + '/' + theme
demo_dir = config['demo_screenshots_map'].get(out_path, out_path)
data['previewimage'] = '/' + demo_dir + '.png'
data['previewimage_thumbnail'] = '/' + demo_dir + '.thumbnail.png'
data['demo_link'] = '/' + demo_dir + '/demo/'
conf_sample = os.path.join(pkg_dir, 'conf.py.sample')
engine = os.path.join(pkg_dir, 'engine')
parent = os.path.join(pkg_dir, 'parent')

if os.path.exists(conf_sample):
with io.open(conf_sample, 'r', encoding='utf-8') as f:
data['confpy'] = pygments.highlight(
f.read(),
PythonLexer(), utils.NikolaPygmentsHTML(theme + '_conf_sample', linenos=False))
else:
data['confpy'] = None

if os.path.exists(engine):
with io.open(engine, 'r', encoding='utf-8') as f:
data['engine'] = f.read().strip()
else:
data['engine'] = 'mako'

if os.path.exists(parent):
with io.open(parent, 'r', encoding='utf-8') as f:
data['parent'] = f.read().strip()
elif theme == 'base':
pass
else:
raise ValueError("Theme {0} has no parent.".format(theme))

data['chain'] = utils.get_theme_chain(theme, [os.path.dirname(pkg_dir), 'themes'])
data['chain'] = [os.path.basename(i) for i in reversed(data['chain'])]
data['bootswatch'] = (('bootstrap' in data['chain'] or
'bootstrap-jinja' in data['chain'] or
'bootstrap3-jinja' in data['chain'] or
'bootstrap3' in data['chain']) and
'bootstrap3-gradients' not in data['chain'])

return data


def add_category(post, pkg_dir, config, args):
return {'category': args}


BUILTIN_HANDLERS = {
'dirname_as_title': dirname_as_title,
'parse_plugin_file': parse_plugin_file,
'parse_theme_info': parse_theme_info,
'add_category': add_category
}

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

pkg_dir = os.path.split(post.source_path)[0]
top_dir = os.path.dirname(pkg_dir)
top_dir = post.folder_relative
metadata = {'slug': os.path.basename(pkg_dir)}
for handler in self.site.config['PKGINDEX_HANDLERS'][top_dir]:
if isinstance(handler, tuple):
@@ -8,6 +8,6 @@ MinVersion = 7.8.1+

[Documentation]
Author = Chris Warrick
Version = 0.1.0
Version = 0.2.0
Website = https://plugins.getnikola.com/
Description = Scan packages for package indexes
@@ -49,7 +49,7 @@ def scan(self):
if 'PKGINDEX_CONFIG' not in self.site.config:
return []
config = self.site.config['PKGINDEX_CONFIG']
plugin_compiler = self.site.get_compiler('sample' + config['extension'])
compiler = self.site.get_compiler('sample' + config['extension'])
if not self.site.quiet:
print("Scanning package index posts...", end='', file=sys.stderr)
timeline = []
@@ -68,7 +68,22 @@ def scan(self):
False,
self.site.MESSAGES,
template_name,
plugin_compiler
compiler
)
post.is_two_file = True
timeline.append(post)
self.site.pkgindex_entries[topdir].append(post)

if 'special_entries' in config:
for source_path, destination, template_name, topdir in config['special_entries']:
post = Post(
source_path,
self.site.config,
destination,
False,
self.site.MESSAGES,
template_name,
compiler
)
post.is_two_file = True
timeline.append(post)
@@ -8,6 +8,6 @@ MinVersion = 7.8.1+

[Documentation]
Author = Chris Warrick
Version = 0.1.0
Version = 0.2.0
Website = https://plugins.getnikola.com/
Description = Generate ZIP (and JSON) files for package indexes
@@ -80,6 +80,8 @@ def gen_tasks(self):
for post in posts:
directory = os.path.dirname(post.source_path)
pkg_name = os.path.basename(directory)
if pkg_name in self.kw['pkgindex_config'].get('zip_ignore', []):
continue
destination = os.path.join(
self.kw['output_folder'],
self.kw['pkgindex_dirs'][dir][0],
@@ -98,7 +100,7 @@ def gen_tasks(self):
# Get list of dependencies and files to zip
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(('.pyc', '.DS_Store')):
if file.endswith(('.pyc', '.DS_Store')) or file == '.git':
continue
zip_files.append((os.path.join(root, file),
os.path.join(root[d:], file)))
@@ -118,7 +120,7 @@ def gen_tasks(self):
destination = os.path.join(
self.kw['output_folder'],
self.kw['pkgindex_dirs'][dir][0],
'plugins.json'
self.kw['pkgindex_config']['json_filename']
)
yield utils.apply_filters({
'basename': self.name,

0 comments on commit b7e5e92

Please sign in to comment.
You can’t perform that action at this time.