Skip to content

mkdocs_nype.plugins.similar_blog_posts.plugin

Synopsis

MkDocs plugin made to automatically link related Blog posts

The ideation for the plugin was supported by ChatGPT, which suggested the usage of Jaccard Similarity index method to calculate the relation score of the blog posts.

Calculating a static correlative number and ranking the relatedness of the posts allows to avoid random selection purely based on same categories. A purely random selection would change the order of the linked posts between MkDocs builds / deployments creating SEO noise.

If there is not enough similar posts, the plugin allows to fill up the list with not related posts. This is random, but with the seed being the date of the post to prevent same results in similar cases, while still stabilizing the results.

Can be seen in use here:

MIT License 2024 Kamil Krzyśków (HRY) for Nype (npe.cm) and Fiori Tracker (fioritracker.org)

PLUGIN_NAME

PLUGIN_NAME: str = 'similar_blog_posts'

Name of this plugin. Used in logging.

LOG

LOG: PrefixedLogger = PrefixedLogger(PLUGIN_NAME, getLogger(f'mkdocs.plugins.{PLUGIN_NAME}'))

Logger instance for this plugins.

SECTION_TEMPLATE

SECTION_TEMPLATE: str = strip()

SimilarBlogPostsPlugin

SimilarBlogPostsPlugin()

Bases: BasePlugin[SimilarBlogPostsConfig]

blog_instance_map

blog_instance_map: dict[str, BlogPlugin] = {}

sanitized_prefixes

sanitized_prefixes: list[str] = []

on_config

on_config(config: MkDocsConfig) -> MkDocsConfig | None

Sanitize prefixes and load blog instances

on_page_markdown

on_page_markdown(markdown: str, /, *, page: Page, config: MkDocsConfig, files: Files) -> str | None

Add the section to a file

weighted_jaccard_similarity

weighted_jaccard_similarity(set_a: set[str], set_b: set[str], use_weights: bool = True) -> float

Jaccard Similarity method was suggested by ChatGPT. Currently only weighted variant is being used