'Set document[\'title\'] metadata title from the following
sources, listed in order of priority:
* Existing document[\'title\'] attribute.
* "title" setting.
* Document title node (as promoted by promote_title).'

def set_metadata(self):

    if (not self.document.hasattr('title')):
        if (self.document.settings.title is not None):
            self.document['title'] = self.document.settings.title
        elif (len(self.document) and isinstance(self.document[0], nodes.title)):
            self.document['title'] = self.document[0].astext()
