Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: getnikola/plugins
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: edc950fd67fc
Choose a base ref
...
head repository: getnikola/plugins
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d4440340cf69
Choose a head ref
  • 3 commits
  • 3 files changed
  • 2 contributors

Commits on Jan 26, 2015

  1. Add the subindexes plugin.

    bwinton committed Jan 26, 2015
    Copy the full SHA
    782d380 View commit details
  2. Add a license.

    bwinton committed Jan 26, 2015

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    2b9f0d3 View commit details

Commits on Jul 5, 2015

  1. Merge pull request #67 from bwinton/master

    Add the subindexes plugin.
    Kwpolska committed Jul 5, 2015
    Copy the full SHA
    d444034 View commit details
Showing with 110 additions and 0 deletions.
  1. +3 −0 v7/subindexes/README.md
  2. +9 −0 v7/subindexes/subindexes.plugin
  3. +98 −0 v7/subindexes/subindexes.py
3 changes: 3 additions & 0 deletions v7/subindexes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This plugin generates an index page for each subdirectory of the posts.

It uses the standard index configuration options.
9 changes: 9 additions & 0 deletions v7/subindexes/subindexes.plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Core]
Name = render_subindexes
Module = subindexes

[Documentation]
Author = Blake Winton
Version = 0.1
Website = http://plugins.getnikola.com/#subindexes
Description = Generates the index pages for each subdirectory in the blog.
98 changes: 98 additions & 0 deletions v7/subindexes/subindexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# -*- coding: utf-8 -*-

# Copyright © 2012-2014 Blake Winton <bwinton@latte.ca>.

# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the
# Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the
# Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice
# shall be included in all copies or substantial portions of
# the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from __future__ import unicode_literals
from collections import defaultdict
import os

from nikola.plugin_categories import Task
from nikola.utils import config_changed


class SubIndexes(Task):
"""Render the indexes for each subdirectory in the blog."""

name = "render_subindexes"

def gen_tasks(self):
self.site.scan_posts()
yield self.group_task()

kw = {
"output_folder": self.site.config['OUTPUT_FOLDER'],
"filters": self.site.config['FILTERS'],
"index_file": self.site.config['INDEX_FILE'],
"strip_indexes": self.site.config['STRIP_INDEXES'],
"index_teasers": self.site.config['INDEX_TEASERS'],
}
template_name = "index.tmpl"
for lang in self.site.config['TRANSLATIONS']:
groups = defaultdict(list)
for p in self.site.timeline:
if p.is_post:
dirname = os.path.dirname(p.destination_path(lang))
dirname = [part for part in os.path.split(dirname) if part]
if dirname == ["."]:
continue
dirname.reverse()
part = ''
while len(dirname):
part = os.path.join(part, dirname.pop())
groups[part].append(p)

for dirname, post_list in groups.items():
context = {}
context["items"] = []
should_render = True
output_name = os.path.join(kw['output_folder'], dirname, kw['index_file'])
short_destination = os.path.join(dirname, kw['index_file'])
link = short_destination.replace('\\', '/')
index_len = len(kw['index_file'])
if kw['strip_indexes'] and link[-(1 + index_len):] == '/' + kw['index_file']:
link = link[:-index_len]
context["permalink"] = link

for post in post_list:
# If there is an index.html pending to be created from
# a story, do not generate the STORY_INDEX
if post.destination_path(lang) == short_destination:
should_render = False
else:
context["items"].append((post.title(lang),
post.permalink(lang)))

context['index_teasers'] = kw['index_teasers']

if should_render:
task = self.site.generic_post_list_renderer(lang, post_list,
output_name,
template_name,
kw['filters'],
context)
task_cfg = {1: task['uptodate'][0].config, 2: kw}
task['uptodate'] = [config_changed(task_cfg)]
task['basename'] = self.name
yield task