Repository: getnikola/nikola

Issue:
Emoji shortcode fails with an encoding error on Windows
### Environment

**Python Version:** 3.7.2

**Nikola Version:** 8.0.2

**Operating System:** Windows 7

### Description:

When using the `{{% emoji %}}` shortcode, Nikola crashes with an encoding error:

```
.  render_posts:cache\posts\creating-a-website-using-nikola.html
TaskError - taskid:render_posts:cache\posts\creating-a-website-using-nikola.html
PythonAction Error
Traceback (most recent call last):
  File "c:\work\projects\website2\.venv\lib\site-packages\doit\action.py", line 424, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "c:\work\projects\website2\.venv\lib\site-packages\nikola\post.py", line 645, in compile
    lang)
  File "c:\work\projects\website2\.venv\lib\site-packages\nikola\plugins\compile\rest\__init__.py", line 152, in compile
    output, error_level, deps, shortcode_deps = self.compile_string(data, source, is_two_file, post, lang)
  File "c:\work\projects\website2\.venv\lib\site-packages\nikola\plugins\compile\rest\__init__.py", line 142, in compile_string
    output, shortcode_deps = self.site.apply_shortcodes_uuid(output, shortcodes, filename=source_path, extra_context={'post': post})
  File "c:\work\projects\website2\.venv\lib\site-packages\nikola\nikola.py", line 1638, in apply_shortcodes_uuid
    replacement, _deps = shortcodes.apply_shortcodes(v, self.shortcode_registry, self, filename, lang=lang, extra_context=extra_context)
  File "c:\work\projects\website2\.venv\lib\site-packages\nikola\shortcodes.py", line 371, in apply_shortcodes
    res = f(*args, **kw)
  File "c:\work\projects\website2\.venv\lib\site-packages\nikola\plugins\shortcode\emoji\__init__.py", line 39, in handler
    _populate()
  File "c:\work\projects\website2\.venv\lib\site-packages\nikola\plugins\shortcode\emoji\__init__.py", line 21, in _populate
    data = json.load(inf)
  File "C:\Users\uk03306\AppData\Local\Programs\Python\Python37\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\uk03306\AppData\Local\Programs\Python\Python37\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 175: character maps to <undefined>
```

This is because `nikola\plugins\shortcode\emoji\__init__.py` opens the JSON data files using the default text mode, which on Windows, is *not* UTF-8. The fix is simple - just add an `encoding="utf-8"` argument to the `open()` call. If you need me to, I can submit a PR for this, but it'll have to wait a while as I don't have a development environment that I can use set up right now.


Discussion:

Resolving patch:
diff --git a/nikola/plugins/shortcode/emoji/__init__.py b/nikola/plugins/shortcode/emoji/__init__.py
--- a/nikola/plugins/shortcode/emoji/__init__.py
+++ b/nikola/plugins/shortcode/emoji/__init__.py
@@ -17,7 +17,7 @@
 
 def _populate():
     for fname in glob.glob(os.path.join(os.path.dirname(__file__), 'data', '*.json')):
-        with open(fname) as inf:
+        with open(fname, encoding="utf-8") as inf:
             data = json.load(inf)
             data = data[list(data.keys())[0]]
             data = data[list(data.keys())[0]]


Test patch: