'Write the metainfo file toc.ncx.'

def build_toc(self, outdir, outname):

    logger.info('writing    %s    file...', outname)
    if (self.config.epub_tocscope == 'default'):
        doctree = self.env.get_and_resolve_doctree(self.config.master_doc, self, prune_toctrees=False, includehidden=False)
        refnodes = self.get_refnodes(doctree, [])
        self.toc_add_files(refnodes)
    else:
        refnodes = self.refnodes
    navpoints = self.build_navpoints(refnodes)
    level = max((item['level'] for item in self.refnodes))
    level = min(level, self.config.epub_tocdepth)
    copy_asset_file(path.join(self.template_dir, 'toc.ncx_t'), path.join(outdir, outname), self.toc_metadata(level, navpoints))
