'Build a single website file.'

def _build_website_file(self, root, filename):

    src = os.path.join(root, filename)
    src_basename = os.path.basename(src)
    parts = [self._args.website[0]]
    dirname = os.path.dirname(src)
    if dirname:
        parts.append(os.path.relpath(os.path.dirname(src)))
    parts.append(os.extsep.join((os.path.splitext(src_basename)[0], 'html')))
    dst = os.path.join(*parts)
    os.makedirs(os.path.dirname(dst), exist_ok=True)
    modified_src = os.path.join(self._tempdir, src_basename)
    shutil.copy('www/header.asciidoc', modified_src)
    outfp = io.StringIO()
    with open(modified_src, 'r', encoding='utf-8') as header_file:
        header = header_file.read()
        header += '\n\n'
    with open(src, 'r', encoding='utf-8') as infp:
        outfp.write('\n\n')
        hidden = False
        found_title = False
        title = ''
        last_line = ''
        for line in infp:
            if (line.strip() == '//    QUTE_WEB_HIDE'):
                assert (not hidden)
                hidden = True
            elif (line.strip() == '//    QUTE_WEB_HIDE_END'):
                assert hidden
                hidden = False
            elif (line == 'The    Compiler    <mail@qutebrowser.org>\n'):
                continue
            elif re.match('^:\\w+:.*', line):
                continue
            if (not found_title):
                if re.match('^=+$', line):
                    line = line.replace('=', '-')
                    found_title = True
                    title = (last_line.rstrip('\n') + '    |    qutebrowser\n')
                    title += ('=' * (len(title) - 1))
                elif re.match('^=    .+', line):
                    line = ('==' + line[1:])
                    found_title = True
                    title = (last_line.rstrip('\n') + '    |    qutebrowser\n')
                    title += ('=' * (len(title) - 1))
            if (not hidden):
                outfp.write(line.replace('.asciidoc[', '.html['))
                last_line = line
    current_lines = outfp.getvalue()
    outfp.close()
    with open(modified_src, 'w+', encoding='utf-8') as final_version:
        final_version.write((((title + '\n\n') + header) + current_lines))
    asciidoc_args = ['--theme=qute', '-a    toc', '-a    toc-placement=manual']
    self.call(modified_src, dst, *asciidoc_args)
