Skip to content

Commit

Permalink
feat: add generate robots.txt tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkrzyskow committed Sep 25, 2024
1 parent 3afe522 commit 3e9f461
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions mkdocs_nype/plugins/nype_tweaks/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"""

import logging
import os
import sys

import material
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]" }
Expand Down

0 comments on commit 3e9f461

Please sign in to comment.