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/nikola
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2f7dd8ff3ba7
Choose a base ref
...
head repository: getnikola/nikola
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bf8f58f3999e
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on May 9, 2015

  1. more refactoring

    ralsina committed May 9, 2015
    Copy the full SHA
    835b860 View commit details
  2. almost there

    ralsina committed May 9, 2015
    Copy the full SHA
    bf8f58f View commit details
Showing with 73 additions and 70 deletions.
  1. +67 −2 nikola/nikola.py
  2. +6 −68 nikola/plugins/task/scan_posts.py
69 changes: 67 additions & 2 deletions nikola/nikola.py
Original file line number Diff line number Diff line change
@@ -698,6 +698,7 @@ def __init__(self, **config):
plugin_info.plugin_object.short_help = plugin_info.description
self._commands[plugin_info.name] = plugin_info.plugin_object

self._activate_plugins_of_category("PostScanner")
self._activate_plugins_of_category("Task")
self._activate_plugins_of_category("LateTask")
self._activate_plugins_of_category("TaskMultiplier")
@@ -1355,11 +1356,75 @@ def flatten(task):
def scan_posts(self):
"""Scan all the posts."""
# FIXME this is temporary while moving things out to a plugin
# Why doesn't getPluginByName work????
if self._scanned:
return

# Reset things
self.global_data = {}
self.posts = []
self.all_posts = []
self.posts_per_year = defaultdict(list)
self.posts_per_month = defaultdict(list)
self.posts_per_tag = defaultdict(list)
self.posts_per_category = defaultdict(list)
self.post_per_file = {}
self.timeline = []
self.pages = []

for p in self.plugin_manager.getPluginsOfCategory('PostScanner'):
p.plugin_object.scan()
timeline, global_data = p.plugin_object.scan()
# FIXME: can there be conflicts here?
self.timeline.extend(timeline)
self.global_data.update(global_data)

# Classify posts per year/tag/month/whatever
slugged_tags = set([])
for post in self.timeline:
if post.use_in_feeds:
self.posts.append(post)
self.posts_per_year[str(post.date.year)].append(post)
self.posts_per_month[
'{0}/{1:02d}'.format(post.date.year, post.date.month)].append(post)
for tag in post.alltags:
_tag_slugified = utils.slugify(tag)
if _tag_slugified in slugged_tags:
if tag not in self.posts_per_tag:
# Tags that differ only in case
other_tag = [existing for existing in self.posts_per_tag.keys() if utils.slugify(existing) == _tag_slugified][0]
utils.LOGGER.error('You have tags that are too similar: {0} and {1}'.format(tag, other_tag))
utils.LOGGER.error('Tag {0} is used in: {1}'.format(tag, post.source_path))
utils.LOGGER.error('Tag {0} is used in: {1}'.format(other_tag, ', '.join([p.source_path for p in self.posts_per_tag[other_tag]])))
quit = True
else:
slugged_tags.add(utils.slugify(tag, force=True))
self.posts_per_tag[tag].append(post)
self.posts_per_category[post.meta('category')].append(post)

if post.is_post:
# unpublished posts
self.all_posts.append(post)
else:
self.pages.append(post)

for lang in self.config['TRANSLATIONS'].keys():
self.post_per_file[post.destination_path(lang=lang)] = post
self.post_per_file[post.destination_path(lang=lang, extension=post.source_ext())] = post

# Sort everything.

for thing in self.timeline, self.posts, self.all_posts, self.pages:
thing.sort(key=lambda p: p.date)
thing.reverse()

for i, p in enumerate(self.posts[1:]):
p.next_post = self.posts[i]
for i, p in enumerate(self.posts[:-1]):
p.prev_post = self.posts[i + 1]
self._scanned = True
if not self.quiet:
print("done!", file=sys.stderr)

signal('scanned').send(self)

def generic_page_renderer(self, lang, post, filters):
"""Render post fragments to final HTML pages."""
74 changes: 6 additions & 68 deletions nikola/plugins/task/scan_posts.py
Original file line number Diff line number Diff line change
@@ -51,23 +51,14 @@ def scan(self):
"show_untranslated_posts": self.site.config['SHOW_UNTRANSLATED_POSTS'],
"demote_headers": self.site.config['DEMOTE_HEADERS'],
}
self.site.global_data = {}
self.site.posts = []
self.site.all_posts = []
self.site.posts_per_year = defaultdict(list)
self.site.posts_per_month = defaultdict(list)
self.site.posts_per_tag = defaultdict(list)
self.site.posts_per_category = defaultdict(list)
self.site.post_per_file = {}
self.site.timeline = []
self.site.pages = []

seen = set([])
if not self.site.quiet:
print("Scanning posts", end='', file=sys.stderr)

slugged_tags = set([])
quit = False
timeline = []
global_data = {}

for wildcard, destination, template_name, use_in_feeds in \
self.site.config['post_pages']:
if not self.site.quiet:
@@ -115,60 +106,7 @@ def scan(self):
template_name,
self.site.get_compiler(base_path)
)
self.site.timeline.append(post)
self.site.global_data[post.source_path] = post
if post.use_in_feeds:
self.site.posts.append(post)
self.site.posts_per_year[
str(post.date.year)].append(post)
self.site.posts_per_month[
'{0}/{1:02d}'.format(post.date.year, post.date.month)].append(post)
for tag in post.alltags:
_tag_slugified = utils.slugify(tag)
if _tag_slugified in slugged_tags:
if tag not in self.site.posts_per_tag:
# Tags that differ only in case
other_tag = [existing for existing in self.site.posts_per_tag.keys() if utils.slugify(existing) == _tag_slugified][0]
utils.LOGGER.error('You have tags that are too similar: {0} and {1}'.format(tag, other_tag))
utils.LOGGER.error('Tag {0} is used in: {1}'.format(tag, post.source_path))
utils.LOGGER.error('Tag {0} is used in: {1}'.format(other_tag, ', '.join([p.source_path for p in self.site.posts_per_tag[other_tag]])))
quit = True
else:
slugged_tags.add(utils.slugify(tag, force=True))
self.site.posts_per_tag[tag].append(post)
self.site.posts_per_category[post.meta('category')].append(post)

if post.is_post:
# unpublished posts
self.site.all_posts.append(post)
else:
self.site.pages.append(post)

for lang in self.site.config['TRANSLATIONS'].keys():
self.site.post_per_file[post.destination_path(lang=lang)] = post
self.site.post_per_file[post.destination_path(lang=lang, extension=post.source_ext())] = post

# Sort everything.
self.site.timeline.sort(key=lambda p: p.date)
self.site.timeline.reverse()
self.site.posts.sort(key=lambda p: p.date)
self.site.posts.reverse()
self.site.all_posts.sort(key=lambda p: p.date)
self.site.all_posts.reverse()
self.site.pages.sort(key=lambda p: p.date)
self.site.pages.reverse()

for i, p in enumerate(self.site.posts[1:]):
p.next_post = self.site.posts[i]
for i, p in enumerate(self.site.posts[:-1]):
p.prev_post = self.site.posts[i + 1]
self.site._scanned = True
if not self.site.quiet:
print("done!", file=sys.stderr)

signal('scanned').send(self)

if quit and not ignore_quit:
sys.exit(1)
timeline.append(post)
global_data[post.source_path] = post

yield self.group_task()
return timeline, global_data