From 3e9f46195482fbb539fcfb09d3e7e81a418718eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Krzy=C5=9Bk=C3=B3w?= Date: Wed, 25 Sep 2024 07:05:45 +0200 Subject: [PATCH] feat: add generate robots.txt tweak --- mkdocs_nype/plugins/nype_tweaks/plugin.py | 18 ++++++++++++++++++ pyproject.toml | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mkdocs_nype/plugins/nype_tweaks/plugin.py b/mkdocs_nype/plugins/nype_tweaks/plugin.py index 17f7682..9501815 100644 --- a/mkdocs_nype/plugins/nype_tweaks/plugin.py +++ b/mkdocs_nype/plugins/nype_tweaks/plugin.py @@ -26,6 +26,7 @@ """ import logging +import os import sys import material @@ -115,6 +116,23 @@ def _on_page_markdown_social_meta( on_page_markdown = CombinedEvent(_on_page_markdown_social_meta) + def on_post_build(self, *, config: MkDocsConfig) -> None: + + # Generate robots.txt tweak + sitemap_xml = config.site_url.rstrip("/") + "/sitemap.xml" + robots_txt = os.path.join(config.site_dir, "robots.txt") + with open(robots_txt, "w", encoding="utf-8") as file: + file.write( + "\n".join( + [ + "User-agent: *", + "Allow: /", + "", + f"Sitemap: {sitemap_xml}", + ] + ) + ) + def on_serve( self, server: LiveReloadServer, /, *, config: MkDocsConfig, builder ) -> LiveReloadServer | None: diff --git a/pyproject.toml b/pyproject.toml index dd249be..cb17ee9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ build-backend = "hatchling.build" [project] name = "mkdocs-nype" -version = "0.16.2" +version = "0.16.3" description = "MkDocs theme for Nype MkDocs projects, extends the Material for MkDocs theme" authors = [ { name = "Kamil Krzyśków", email = "kk@npe.cm" }