Skip to content
Permalink
Browse files

First try to pass language to slugify and unslugify (see #2273).

  • Loading branch information
felixfontein committed Mar 6, 2016
1 parent 4604211 commit 361ca292b0a06f864e5c434cf5bcaf7ecaf83551
@@ -495,7 +495,7 @@ Here's the relevant code from the tag plugin.
# path elements.
def tag_rss_path(self, name, lang):
return [_f for _f in [self.site.config['TRANSLATIONS'][lang],
self.site.config['TAG_PATH'], self.slugify_name(name) + ".xml"] if
self.site.config['TAG_PATH'], self.slugify_name(name, lang) + ".xml"] if
_f]

Template Hooks
@@ -1722,27 +1722,28 @@ def scan_posts(self, really=False, ignore_quit=False, quiet=False):

quit = False
# Classify posts per year/tag/month/whatever
slugged_tags = set([])
slugged_tags = defaultdict(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))
self.posts_per_tag[tag].append(post)
for lang in self.config['TRANSLATIONS'].keys():
for tag in post.tags_for_language(lang):
_tag_slugified = utils.slugify(tag, lang)
if _tag_slugified in slugged_tags[lang]:
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[lang].add(_tag_slugified)
self.tags_per_language[lang].extend(post.tags_for_language(lang))
self._add_post_to_category(post, post.meta('category'))

@@ -2045,7 +2046,7 @@ def atom_post_text(post, text):
entry_content.text = content
for category in post.tags_for_language(lang):
entry_category = lxml.etree.SubElement(entry_root, "category")
entry_category.set("term", utils.slugify(category))
entry_category.set("term", utils.slugify(category, lang))
entry_category.set("label", category)

dst_dir = os.path.dirname(output_path)
@@ -350,7 +350,7 @@ def show_info_about_mising_module(modulename):
tag_str = tag
except AttributeError:
tag_str = tag
tag = utils.slugify(tag_str)
tag = utils.slugify(tag_str, self.lang)
src_url = '{}tag/{}'.format(self.context['SITE_URL'], tag)
dst_url = self.site.link('tag', tag)
if src_url != dst_url:
@@ -396,7 +396,8 @@ def populate_context(self, channel):
wordpress_namespace = channel.nsmap['wp']

context = SAMPLE_CONF.copy()
context['DEFAULT_LANG'] = get_text_tag(channel, 'language', 'en')[:2]
self.lang = get_text_tag(channel, 'language', 'en')[:2]
context['DEFAULT_LANG'] = self.lang
context['TRANSLATIONS_PATTERN'] = DEFAULT_TRANSLATIONS_PATTERN
context['BLOG_TITLE'] = get_text_tag(channel, 'title',
'PUT TITLE HERE')
@@ -816,7 +817,7 @@ def import_postpage_item(self, item, wordpress_namespace, out_folder=None, attac
else:
if len(pathlist) > 1:
out_folder = os.path.join(*([out_folder] + pathlist[:-1]))
slug = utils.slugify(pathlist[-1])
slug = utils.slugify(pathlist[-1], self.lang)

description = get_text_tag(item, 'description', '')
post_date = get_text_tag(
@@ -293,14 +293,14 @@ def _execute(self, options, args):

title = title.strip()
if not path:
slug = utils.slugify(title)
slug = utils.slugify(title, lang=self.site.default_lang)
else:
if isinstance(path, utils.bytes_str):
try:
path = path.decode(sys.stdin.encoding)
except (AttributeError, TypeError): # for tests
path = path.decode('utf-8')
slug = utils.slugify(os.path.splitext(os.path.basename(path))[0])
slug = utils.slugify(os.path.splitext(os.path.basename(path))[0], lang=self.site.default_lang)

if isinstance(author, utils.bytes_str):
try:
@@ -251,10 +251,10 @@ def author_rss(self, author, lang, posts, kw):
}
return utils.apply_filters(task, kw['filters'])

def slugify_author_name(self, name):
def slugify_author_name(self, name, lang):
"""Slugify an author name."""
if self.site.config['SLUG_AUTHOR_PATH']:
name = utils.slugify(name)
name = utils.slugify(name, lang)
return name

def author_index_path(self, name, lang):
@@ -279,13 +279,13 @@ def author_path(self, name, lang):
return [_f for _f in [
self.site.config['TRANSLATIONS'][lang],
self.site.config['AUTHOR_PATH'],
self.slugify_author_name(name),
self.slugify_author_name(name, lang),
self.site.config['INDEX_FILE']] if _f]
else:
return [_f for _f in [
self.site.config['TRANSLATIONS'][lang],
self.site.config['AUTHOR_PATH'],
self.slugify_author_name(name) + ".html"] if _f]
self.slugify_author_name(name, lang) + ".html"] if _f]

def author_atom_path(self, name, lang):
"""Link to an author's Atom feed.
@@ -295,7 +295,7 @@ def author_atom_path(self, name, lang):
link://author_atom/joe => /authors/joe.atom
"""
return [_f for _f in [self.site.config['TRANSLATIONS'][lang],
self.site.config['AUTHOR_PATH'], self.slugify_author_name(name) + ".atom"] if
self.site.config['AUTHOR_PATH'], self.slugify_author_name(name, lang) + ".atom"] if
_f]

def author_rss_path(self, name, lang):
@@ -306,7 +306,7 @@ def author_rss_path(self, name, lang):
link://author_rss/joe => /authors/joe.rss
"""
return [_f for _f in [self.site.config['TRANSLATIONS'][lang],
self.site.config['AUTHOR_PATH'], self.slugify_author_name(name) + ".xml"] if
self.site.config['AUTHOR_PATH'], self.slugify_author_name(name, lang) + ".xml"] if
_f]

def _add_extension(self, path, extension):
@@ -234,7 +234,7 @@ def gen_tasks(self):
img_titles = []
for fn in image_name_list:
name_without_ext = os.path.splitext(os.path.basename(fn))[0]
img_titles.append(utils.unslugify(name_without_ext))
img_titles.append(utils.unslugify(name_without_ext, lang))
else:
img_titles = [''] * len(image_name_list)

0 comments on commit 361ca29

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