import common def links_to_nearby_entries(id): earlier_entries = [ e for e in reversed(list(common.entries)[: list(common.entries).index(id)]) ] later_entries = [ e for e in list(common.entries)[1 + list(common.entries).index(id) :] ] relevant_earlier_entries = {} relevant_later_entries = {} for other_entry in earlier_entries: if earlier_entries.index(other_entry) == 0: relevant_earlier_entries[other_entry] = relevant_earlier_entries.get( other_entry, {} ) relevant_earlier_entries[other_entry].update({"rel": "prev"}) if "series" in common.entries[id] and "series" in common.entries[other_entry]: if common.slugify(common.entries[id]["series"]) == common.slugify( common.entries[other_entry]["series"] ): if other_entry == common.offset_id( common.entries_in_series(common.entries[id]["series"]), id, -1 ): relevant_earlier_entries[ other_entry ] = relevant_earlier_entries.get(other_entry, {}) relevant_earlier_entries[other_entry].update({"rel": "prev"}) if "tags" in common.entries[id] and "tags" in common.entries[other_entry]: for tag_string in [ tag_string for tag_string in common.entries[id]["tags"] if common.slugify(tag_string) in map(common.slugify, common.entries[other_entry]["tags"]) ]: entries_with_this_tag = common.entries_with_tag(tag_string) if other_entry == common.offset_id(entries_with_this_tag, id, -1): relevant_earlier_entries[ other_entry ] = relevant_earlier_entries.get(other_entry, {}) relevant_earlier_entries[other_entry][ "labels" ] = relevant_earlier_entries[other_entry].get("labels", []) relevant_earlier_entries[other_entry]["labels"] += [tag_string] relevant_earlier_entries[other_entry].update({"rel": "prev"}) for other_entry in later_entries: if later_entries.index(other_entry) == 0: relevant_later_entries[other_entry] = relevant_later_entries.get( other_entry, {} ) relevant_later_entries[other_entry].update({"rel": "next"}) if "series" in common.entries[id] and "series" in common.entries[other_entry]: if common.slugify(common.entries[id]["series"]) == common.slugify( common.entries[other_entry]["series"] ): if other_entry == common.offset_id( common.entries_in_series(common.entries[id]["series"]), id, +1 ): relevant_later_entries[other_entry] = relevant_later_entries.get( other_entry, {} ) relevant_later_entries[other_entry].update({"rel": "next"}) if "tags" in common.entries[id] and "tags" in common.entries[other_entry]: for tag_string in [ tag_string for tag_string in common.entries[id]["tags"] if common.slugify(tag_string) in map(common.slugify, common.entries[other_entry]["tags"]) ]: entries_with_this_tag = common.entries_with_tag(tag_string) if other_entry == common.offset_id(entries_with_this_tag, id, +1): relevant_later_entries[other_entry] = relevant_later_entries.get( other_entry, {} ) relevant_later_entries[other_entry][ "labels" ] = relevant_later_entries[other_entry].get("labels", []) relevant_later_entries[other_entry]["labels"] += [tag_string] relevant_later_entries[other_entry].update({"rel": "next"}) links = "" if len(relevant_earlier_entries) > 0: links += ( "

Earlier:

" + "" ) if len(relevant_later_entries) > 0: links += ( "

Later:

" + "" ) return links def html(entries, id): entry = entries[id] byline = ( ( '
' + "from " + f'' + entry["series"] + "" + "
" if "series" in entry else "" ) + '
' + 'by Grey Nicholson' + "
" + '
' + ("published " if "modified" in entry else "") + f'" + ( "
" + "edited " + f'" + "
" if "modified" in entry else "" ) + "
" ) colour_class = ( common.slugify(entry["series"]) if "series" in entry else f'month-{entry["date"].month:02d}' ) decoration = ( f"""
' if "image" in entry else '
' if "series" in entry else "" ) description = ( ( '
' + common.convert_to_html(entry["description"]) + "
" ) if "description" in entry else "" ) entry_links = ( ( "
" + "" ) if "links" in entry else "" ) repeated_tags = ( list( common.slugify(tag) for tag in entry["tags"] if common.slugify(tag) in common.repeated_tags ) if "tags" in entry else [] ) head = "".join( f"""""" + "\n" for tag in repeated_tags ) small = "

" + entry["small"] + "

" if "small" in entry else "" tags = ( ( '
tags: ' + ", ".join( f'" for tag in repeated_tags ) + "" + "
" ) if repeated_tags else "" ) tags = "" # No tags for now return common.print_html( f""" {common.head} {head} {entry['title']}
{decoration}

{entry['title']}


{common.convert_to_html(entry.content)}
{common.footer} """ )