mirror of
https://github.com/ai-robots-txt/ai.robots.txt.git
synced 2025-05-19 16:53:11 +00:00
Added a Caddyfile converter
This commit is contained in:
parent
bbec639c14
commit
e519f9f94c
3 changed files with 68 additions and 1 deletions
|
@ -178,6 +178,12 @@ def json_to_nginx(robot_json):
|
|||
config = f"if ($http_user_agent ~* \"{list_to_pcre(robot_json.keys())}\") {{\n return 403;\n}}"
|
||||
return config
|
||||
|
||||
def json_to_caddy(robot_json):
|
||||
caddyfile = "@aibots {\n "
|
||||
caddyfile += "\n ".join(f'header User-Agent "*{k}*"' for k in robot_json.keys())
|
||||
caddyfile += "\n}"
|
||||
return caddyfile
|
||||
|
||||
|
||||
def update_file_if_changed(file_name, converter):
|
||||
"""Update files if newer content is available and log the (in)actions."""
|
||||
|
@ -208,6 +214,10 @@ def conversions():
|
|||
file_name="./nginx-block-ai-bots.conf",
|
||||
converter=json_to_nginx,
|
||||
)
|
||||
update_file_if_changed(
|
||||
file_name="./Caddyfile",
|
||||
converter=json_to_caddy
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue