beerds/server/infra/web/seo.py

80 lines
2.3 KiB
Python

import asyncio
from pathlib import Path
import os
import inject
import markdown
from litestar import (
Controller,
get,
post,
MediaType,
Litestar,
)
from litestar.enums import RequestEncodingType
from litestar.datastructures import UploadFile
from litestar.params import Body
from litestar.exceptions import HTTPException
from litestar.contrib.jinja import JinjaTemplateEngine
from litestar.template.config import TemplateConfig
from litestar.response import Template
from litestar.static_files import create_static_files_router
from server.infra import logger
from server.config import get_app_config
from server.infra.cache import LocalCacheRepository
from server.infra.db import AsyncDB
from server.modules.descriptions import CharactersService, Breed, CharactersRepository
from server.modules.recognizer import RecognizerService, RecognizerRepository
class SeoController(Controller):
@get("/sitemap.xml", media_type=MediaType.XML)
async def sitemaps(self) -> bytes:
breeds: list[Breed] = await characters_service.get_characters()
lastmod = "2025-10-04T19:01:03+00:00"
beers_url = ""
for b in breeds:
beers_url += f"""
<url>
<loc>https://xn-----6kcp3cadbabfh8a0a.xn--p1ai/dogs-characteristics/{b.alias}</loc>
<lastmod>{lastmod}</lastmod>
</url>
"""
return f"""<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<!-- created with Free Online Sitemap Generator www.xml-sitemaps.com -->
<url>
<loc>https://xn-----6kcp3cadbabfh8a0a.xn--p1ai/</loc>
<lastmod>{lastmod}</lastmod>
</url>
<url>
<loc>https://xn-----6kcp3cadbabfh8a0a.xn--p1ai/cats</loc>
<lastmod>{lastmod}</lastmod>
</url>
<url>
<loc>https://xn-----6kcp3cadbabfh8a0a.xn--p1ai/donate</loc>
<lastmod>{lastmod}</lastmod>
</url>
<url>
<loc>https://xn-----6kcp3cadbabfh8a0a.xn--p1ai/dogs-characteristics</loc>
<lastmod>{lastmod}</lastmod>
</url>
{beers_url}
</urlset>
""".encode()
@get("/robots.txt", media_type=MediaType.TEXT)
async def robots(self) -> str:
return """
User-agent: *
Allow: /
Sitemap: https://xn-----6kcp3cadbabfh8a0a.xn--p1ai/sitemap.xml
"""