Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
merged master
  • Loading branch information
ralsina committed Apr 24, 2015
2 parents e0e1698 + 57d46d2 commit a7e4e96
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 39 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -5,6 +5,7 @@ Features
--------

* Switched from MathJax to KaTeX
* AddThis is no longer added by default to users’ sites
* New translations (az, fil, tl, uk, zh_TW)
* Add reStructuredText transform support (Issue #1647)
* Produce Unicode output in ``nikola init`` (via Issue #1644)
Expand All @@ -17,6 +18,8 @@ Features
Bugfixes
--------

* Encode IDNs to Punycode in ``nikola init`` and in links;
show an error if the site URL is not Punycode (Issue #1644)
* Make ``images`` the default output directory for IMAGE_FOLDERS
(Issue #1663)
* Don't default to any swatch in bootswatch_theme (Issue #1656)
Expand Down
3 changes: 2 additions & 1 deletion docs/manual.txt
Expand Up @@ -1182,7 +1182,8 @@ to one of "disqus", "intensedebate", "livefyre", "moot", "googleplus",
* For Facebook, you need to `create an app
<https://developers.facebook.com/apps>` (turn off sandbox mode!)
and get an **App ID**
* For isso, it is the URL of isso (must be world-accessible and **have a trailing slash**,
* For isso, it is the URL of isso (must be world-accessible, encoded with
Punycode (if using Internationalized Domain Names) and **have a trailing slash**,
default ``http://localhost:8080/``)

To use comments in a visible site, you should register with the service and
Expand Down
37 changes: 19 additions & 18 deletions nikola/conf.py.in
Expand Up @@ -492,28 +492,28 @@ IMAGE_FOLDERS = {'images': 'images'}
# algol
# algol_nu
# arduino
# autumn
# borland
# bw
# colorful
# default
# emacs
# friendly
# fruity
# autumn
# borland
# bw
# colorful
# default
# emacs
# friendly
# fruity
# igor
# lovelace
# manni
# monokai
# murphy
# native
# monokai
# murphy
# native
# paraiso_dark
# paraiso_light
# pastie
# perldoc
# rrt
# tango
# trac
# vim
# pastie
# perldoc
# rrt
# tango
# trac
# vim
# vs
# xcode
# This list MAY be incomplete since pygments adds styles every now and then.
Expand Down Expand Up @@ -721,7 +721,8 @@ COMMENT_SYSTEM_ID = ${COMMENT_SYSTEM_ID}
# PANDOC_OPTIONS = []

# Social buttons. This is sample code for AddThis (which was the default for a
# long time). Insert anything you want here, or even make it empty.
# long time). Insert anything you want here, or even make it empty (which is
# the default right now)
# (translatable)
# SOCIAL_BUTTONS_CODE = """
# <!-- Social buttons -->
Expand Down
48 changes: 30 additions & 18 deletions nikola/nikola.py
Expand Up @@ -37,9 +37,9 @@
import sys
import mimetypes
try:
from urlparse import urlparse, urlsplit, urljoin
from urlparse import urlparse, urlsplit, urlunsplit, urljoin, unquote
except ImportError:
from urllib.parse import urlparse, urlsplit, urljoin # NOQA
from urllib.parse import urlparse, urlsplit, urlunsplit, urljoin, unquote # NOQA

try:
import pyphen
Expand Down Expand Up @@ -407,7 +407,7 @@ def __init__(self, **config):
'SHOW_SOURCELINK': True,
'SHOW_UNTRANSLATED_POSTS': True,
'SLUG_TAG_PATH': True,
'SOCIAL_BUTTONS_CODE': SOCIAL_BUTTONS_CODE,
'SOCIAL_BUTTONS_CODE': '',
'SITE_URL': 'http://getnikola.com/',
'STORY_INDEX': False,
'STRIP_INDEXES': False,
Expand Down Expand Up @@ -625,6 +625,15 @@ def __init__(self, **config):
utils.LOGGER.warn("Your BASE_URL doesn't end in / -- adding it, but please fix it in your config file!")
self.config['BASE_URL'] += '/'

try:
_bnl = urlsplit(self.config['BASE_URL']).netloc
_bnl.encode('ascii')
urlsplit(self.config['SITE_URL']).netloc.encode('ascii')
except (UnicodeEncodeError, UnicodeDecodeError):
utils.LOGGER.error("Your BASE_URL or SITE_URL contains an IDN expressed in Unicode. Please convert it to Punycode.")
utils.LOGGER.error("Punycode of {}: {}".format(_bnl, _bnl.encode('idna')))
sys.exit(1)

# todo: remove in v8
if not isinstance(self.config['DEPLOY_COMMANDS'], dict):
utils.LOGGER.warn("A single list as DEPLOY_COMMANDS is deprecated. DEPLOY_COMMANDS should be a dict, with deploy preset names as keys and lists of commands as values.")
Expand Down Expand Up @@ -984,6 +993,24 @@ def url_replacer(self, src, dst, lang=None, url_type=None):
if dst_url.scheme == 'link': # Magic link
dst = self.link(dst_url.netloc, dst_url.path.lstrip('/'), lang)
else:
print(dst)
if '%' in dst_url.netloc:
# convert lxml percent-encoded garbage to punycode
nl = unquote(dst_url.netloc)
try:
nl = nl.decode('utf-8')
except AttributeError:
# python 3: already unicode
pass

nl = nl.encode('idna')

dst = urlunsplit((dst_url.scheme,
nl,
dst_url.path,
dst_url.query,
dst_url.fragment))
print(dst)
return dst
elif dst_url.scheme == 'link': # Magic absolute path link:
dst = dst_url.path
Expand Down Expand Up @@ -1829,18 +1856,3 @@ def workaround_empty_LC_ALL_posix():
"tr_tr": "Turkish",
"zh_cn": "Chinese_China", # Chinese (Simplified)
}


SOCIAL_BUTTONS_CODE = """
<!-- Social buttons -->
<div id="addthisbox" class="addthis_toolbox addthis_peekaboo_style addthis_default_style addthis_label_style addthis_32x32_style">
<a class="addthis_button_more">Share</a>
<ul><li><a class="addthis_button_facebook"></a>
<li><a class="addthis_button_google_plusone_share"></a>
<li><a class="addthis_button_linkedin"></a>
<li><a class="addthis_button_twitter"></a>
</ul>
</div>
<script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4f7088a56bb93798"></script>
<!-- End of social buttons -->
"""
34 changes: 32 additions & 2 deletions nikola/plugins/command/init.py
Expand Up @@ -39,7 +39,7 @@
import tarfile

import nikola
from nikola.nikola import DEFAULT_TRANSLATIONS_PATTERN, DEFAULT_INDEX_READ_MORE_LINK, DEFAULT_RSS_READ_MORE_LINK, LEGAL_VALUES
from nikola.nikola import DEFAULT_TRANSLATIONS_PATTERN, DEFAULT_INDEX_READ_MORE_LINK, DEFAULT_RSS_READ_MORE_LINK, LEGAL_VALUES, urlsplit, urlunsplit
from nikola.plugin_categories import Command
from nikola.utils import ask, ask_yesno, get_logger, makedirs, STDERR_HANDLER, load_messages
from nikola.packages.tzlocal import get_localzone
Expand Down Expand Up @@ -261,6 +261,36 @@ def create_empty_site(cls, target):
@staticmethod
def ask_questions(target):
"""Ask some questions about Nikola."""
def urlhandler(default, toconf):
answer = ask('Site URL', 'http://getnikola.com/')
try:
answer = answer.decode('utf-8')
except (AttributeError, UnicodeDecodeError):
pass
if not answer.startswith(u'http'):
print(" ERROR: You must specify a protocol (http or https).")
urlhandler(default, toconf)
return
if not answer.endswith('/'):
print(" The URL does not end in '/' -- adding it.")
answer += '/'

dst_url = urlsplit(answer)
try:
dst_url.netloc.encode('ascii')
except (UnicodeEncodeError, UnicodeDecodeError):
# The IDN contains characters beyond ASCII. We must convert it
# to Punycode. (Issue #1644)
nl = dst_url.netloc.encode('idna')
answer = urlunsplit((dst_url.scheme,
nl,
dst_url.path,
dst_url.query,
dst_url.fragment))
print(" Converting to Punycode:", answer)

SAMPLE_CONF['SITE_URL'] = answer

def lhandler(default, toconf, show_header=True):
if show_header:
print("We will now ask you to provide the list of languages you want to use.")
Expand Down Expand Up @@ -375,7 +405,7 @@ def chandler(default, toconf):
('Site author', 'Nikola Tesla', True, 'BLOG_AUTHOR'),
('Site author\'s e-mail', 'n.tesla@example.com', True, 'BLOG_EMAIL'),
('Site description', 'This is a demo site for Nikola.', True, 'BLOG_DESCRIPTION'),
('Site URL', 'http://getnikola.com/', True, 'SITE_URL'),
(urlhandler, None, True, True),
('Questions about languages and locales', None, None, None),
(lhandler, None, True, True),
(tzhandler, None, True, True),
Expand Down

0 comments on commit a7e4e96

Please sign in to comment.