'Generate individual HTML files per tag.
Filter out excluded tags. For each tag qualifying as a genre,
create a separate HTML file. Normalize tags to flatten synonymous tags.
Inputs:
self.genre_tags_dict (list): all genre tags
Output:
(files): HTML file per genre'

def generate_html_by_genres(self):

    self.update_progress_full_step(_('Genres    HTML'))
    genre_list = []
    for friendly_tag in sorted(self.genre_tags_dict, key=sort_key):
        tag_list = {}
        for book in self.books_by_author:
            if (('genres' in book) and (friendly_tag in book['genres'])):
                this_book = {}
                this_book['author'] = book['author']
                this_book['title'] = book['title']
                this_book['author_sort'] = capitalize(book['author_sort'])
                this_book['prefix'] = book['prefix']
                this_book['tags'] = book['tags']
                this_book['id'] = book['id']
                this_book['series'] = book['series']
                this_book['series_index'] = book['series_index']
                this_book['date'] = book['date']
                normalized_tag = self.genre_tags_dict[friendly_tag]
                genre_tag_list = [key for genre in genre_list for key in genre]
                if (normalized_tag in genre_tag_list):
                    for existing_genre in genre_list:
                        for key in existing_genre:
                            new_book = None
                            if (key == normalized_tag):
                                for book in existing_genre[key]:
                                    if (book['title'] == this_book['title']):
                                        new_book = False
                                        break
                                else:
                                    new_book = True
                            if new_book:
                                existing_genre[key].append(this_book)
                else:
                    tag_list[normalized_tag] = [this_book]
                    genre_list.append(tag_list)
    if self.opts.verbose:
        if len(genre_list):
            self.opts.log.info(('        Genre    summary:    %d    active    genre    tags    used    in    generating    catalog    with    %d    titles' % (len(genre_list), len(self.books_to_catalog))))
            for genre in genre_list:
                for key in genre:
                    self.opts.log.info(('            %s:    %d    %s' % (self.get_friendly_genre_tag(key), len(genre[key]), ('titles' if (len(genre[key]) > 1) else 'title'))))
    master_genre_list = []
    for genre_tag_set in genre_list:
        for (index, genre) in enumerate(genre_tag_set):
            authors = []
            for book in genre_tag_set[genre]:
                authors.append((book['author'], book['author_sort']))
            books_by_current_author = 1
            current_author = authors[0]
            unique_authors = []
            for (i, author) in enumerate(authors):
                if ((author != current_author) and i):
                    unique_authors.append((current_author[0], current_author[1], books_by_current_author))
                    current_author = author
                    books_by_current_author = 1
                elif ((i == 0) and (len(authors) == 1)):
                    unique_authors.append((current_author[0], current_author[1], books_by_current_author))
                else:
                    books_by_current_author += 1
            outfile = ('%s/Genre_%s.html' % (self.content_dir, genre))
            titles_spanned = self.generate_html_by_genre(genre, (True if (index == 0) else False), genre_tag_set[genre], outfile)
            tag_file = ('content/Genre_%s.html' % genre)
            master_genre_list.append({'tag': genre, 'file': tag_file, 'authors': unique_authors, 'books': genre_tag_set[genre], 'titles_spanned': titles_spanned})
    self.genres = master_genre_list
