Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapse tags with same slug #1029

Merged
merged 4 commits into from Feb 6, 2014
Merged

Collapse tags with same slug #1029

merged 4 commits into from Feb 6, 2014

Conversation

ralsina
Copy link
Member

@ralsina ralsina commented Feb 5, 2014

Fix #1022 by declaring that two tags that generate the same slug is an error.

if tag not in self.posts_per_tag:
# Tags that differ only in case
other_tag = [k for k in self.posts_per_tag.keys() if k.lower() == tag.lower()][0]
utils.LOGGER.error('You have cases that differ only in upper/lower case: {0} and {1}'.format(tag, other_tag))
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make it so we show all the posts that have the tag? Like this:

  • keep a list of conflicts internally
  • while done, show it at once and exit

Also, how does this work with 3-way conflicts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, reporting them all at once is a bit harder. I could make it continue so it reports them all and then fail on the repeated target error tho.

3-way conflicts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3-way conflicts, as in:

>>> map(nikola.utils.slugify, [u'foo.bar', u'foo,bar', u'foobar'])
['foobar', 'foobar', 'foobar']

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remove the exit, you get this:

Scanning posts.[2014-02-05T19:40:28Z] ERROR: Nikola: You have tags that are too similar: foo and fOo
[2014-02-05T19:40:28Z] ERROR: Nikola: Tag foo is used in: posts/foo.rst
[2014-02-05T19:40:28Z] ERROR: Nikola: Tag fOo is used in: posts/foo.rst
[2014-02-05T19:40:28Z] ERROR: Nikola: You have tags that are too similar: Foo and fOo
[2014-02-05T19:40:28Z] ERROR: Nikola: Tag Foo is used in: posts/foo.rst
[2014-02-05T19:40:28Z] ERROR: Nikola: Tag fOo is used in: posts/foo.rst
...done!
ERROR: Task generation 'render_site' has duplicated definition of 'render_tags:output/categories/foo.xml'

That's not horrible ;-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though if you want that ugly doit ERROR dead:

 utils.LOGGER.error('Tag {0} is used in: {1}'.format(other_tag, ', '.join(self.posts_per_tag[other_tag])))
+quit = 1+if quit:
+    sys.exit(1)

(define quit = 0 earlier)

ralsina added a commit that referenced this pull request Feb 6, 2014
@ralsina ralsina merged commit 791742e into master Feb 6, 2014
@Kwpolska Kwpolska deleted the collapse-tags-with-same-slug branch March 14, 2014 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Act sanely with tags that have different “real” names but the same slugs
2 participants