# Buggy code
def _follow(config_line, url_context, use_dir_urls, header=None, title=None):
    if isinstance(config_line, str):
        path = os.path.normpath(config_line)
        page = _path_to_page(path, title, url_context, use_dir_urls)

        if header:
            page.ancestors = [header]
            header.children.append(page)

        yield page
        raise StopIteration

    elif not isinstance(config_line, dict):
        msg = (
            "Line in 'page' config is of type {0}, dict or string expected. Config: {1}"
        ).format(type(config_line), config_line)
        raise exceptions.ConfigurationError(msg)

    if len(config_line) > 1:
        raise exceptions.ConfigurationError(
            "Page configs should be in the format 'name: markdown.md'. The "
            "config contains an invalid entry: {0}".format(config_line)
        )
    elif len(config_line) == 0:
        log.warning("Ignoring empty line in the pages config.")
        raise StopIteration

    next_cat_or_title, subpages_or_path = next(iter(config_line.items()))

    if isinstance(subpages_or_path, str):
        path = subpages_or_path
        for sub in _follow(
            path, url_context, use_dir_urls, header=header, title=next_cat_or_title
        ):
            yield sub
        raise StopIteration

    elif not isinstance(subpages_or_path, list):
        msg = (
            "Line in 'page' config is of type {0}, list or string "
            "expected for sub pages. Config: {1}"
        ).format(type(config_line), config_line)
        raise exceptions.ConfigurationError(msg)

    next_header = Header(title=next_cat_or_title, children=[])
    if header:
        next_header.ancestors = [header]
        header.children.append(next_header)
    yield next_header

    subpages = subpages_or_path

    for subpage in subpages:
        for sub in _follow(subpage, url_context, use_dir_urls, next_header):
            yield sub


# Traceback (UnicodeDecodeError)
Traceback (most recent call last):
File "/Users/maemual/Workspace/mkdocs/env/bin/mkdocs", line 9, in <module>
load_entry_point('mkdocs==0.13.0.dev0', 'console_scripts', 'mkdocs')()
File "/Users/maemual/Workspace/mkdocs/env/lib/python2.7/site-packages/click/core.py", line 664, in __call__
return self.main(*args, **kwargs)
File "/Users/maemual/Workspace/mkdocs/env/lib/python2.7/site-packages/click/core.py", line 644, in main
rv = self.invoke(ctx)
File "/Users/maemual/Workspace/mkdocs/env/lib/python2.7/site-packages/click/core.py", line 991, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/maemual/Workspace/mkdocs/env/lib/python2.7/site-packages/click/core.py", line 837, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/maemual/Workspace/mkdocs/env/lib/python2.7/site-packages/click/core.py", line 464, in invoke
return callback(*args, **kwargs)
File "/Users/maemual/Workspace/mkdocs/mkdocs/cli.py", line 83, in serve_command
livereload=livereload,
File "/Users/maemual/Workspace/mkdocs/mkdocs/serve.py", line 77, in serve
config = builder()
File "/Users/maemual/Workspace/mkdocs/mkdocs/serve.py", line 73, in builder
build(config, live_server=True)
File "/Users/maemual/Workspace/mkdocs/mkdocs/build.py", line 306, in build
build_pages(config)
File "/Users/maemual/Workspace/mkdocs/mkdocs/build.py", line 252, in build_pages
if not build_template('search.html', env, config, site_navigation):
File "/Users/maemual/Workspace/mkdocs/mkdocs/build.py", line 166, in build_template
output_content = template.render(context)
File "/Users/maemual/Workspace/mkdocs/env/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
return self.environment.handle_exception(exc_info, True)
File "/Users/maemual/Workspace/mkdocs/env/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/maemual/Workspace/mkdocs/mkdocs/themes/readthedocs/search.html", line 1, in top-level template code
{% extends "base.html" %}
File "/Users/maemual/Workspace/mkdocs/mkdocs/themes/readthedocs/base.html", line 62, in top-level template code
<li>{% include "toc.html" %}<li>
File "/Users/maemual/Workspace/mkdocs/mkdocs/themes/readthedocs/toc.html", line 3, in top-level template code
<li><span>{{ nav_item.title }}</span></li>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)

# Fixed code
def _follow(config_line, url_context, use_dir_urls, header=None, title=None):
    if isinstance(config_line, six.string_types):
        path = os.path.normpath(config_line)
        page = _path_to_page(path, title, url_context, use_dir_urls)

        if header:
            page.ancestors = [header]
            header.children.append(page)

        yield page
        raise StopIteration

    elif not isinstance(config_line, dict):
        msg = (
            "Line in 'page' config is of type {0}, dict or string expected. Config: {1}"
        ).format(type(config_line), config_line)
        raise exceptions.ConfigurationError(msg)

    if len(config_line) > 1:
        raise exceptions.ConfigurationError(
            "Page configs should be in the format 'name: markdown.md'. The "
            "config contains an invalid entry: {0}".format(config_line)
        )
    elif len(config_line) == 0:
        log.warning("Ignoring empty line in the pages config.")
        raise StopIteration

    next_cat_or_title, subpages_or_path = next(iter(config_line.items()))

    if isinstance(subpages_or_path, six.string_types):
        path = subpages_or_path
        for sub in _follow(
            path, url_context, use_dir_urls, header=header, title=next_cat_or_title
        ):
            yield sub
        raise StopIteration

    elif not isinstance(subpages_or_path, list):
        msg = (
            "Line in 'page' config is of type {0}, list or string "
            "expected for sub pages. Config: {1}"
        ).format(type(config_line), config_line)
        raise exceptions.ConfigurationError(msg)

    next_header = Header(title=next_cat_or_title, children=[])
    if header:
        next_header.ancestors = [header]
        header.children.append(next_header)
    yield next_header

    subpages = subpages_or_path

    for subpage in subpages:
        for sub in _follow(subpage, url_context, use_dir_urls, next_header):
            yield sub