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 += ( "
" + entry["small"] + "
" if "small" in entry else "" tags = ( ( ' " ) if repeated_tags else "" ) tags = "" # No tags for now return common.print_html( f""" {common.head} {head}