'Process the docinfo part of the doctree as metadata.
Keep processing minimal -- just return what docutils says.'

def process_doc(self, app, doctree):

    md = app.env.metadata[app.env.docname]
    try:
        docinfo = doctree[0]
    except IndexError:
        return
    if (docinfo.__class__ is not nodes.docinfo):
        return
    for node in docinfo:
        if isinstance(node, nodes.authors):
            md['authors'] = [author.astext() for author in node]
        elif isinstance(node, nodes.TextElement):
            md[node.__class__.__name__] = node.astext()
        else:
            (name, body) = node
            md[name.astext()] = body.astext()
    for (name, value) in md.items():
        if (name in ('tocdepth',)):
            try:
                value = int(value)
            except ValueError:
                value = 0
            md[name] = value
    del doctree[0]
