Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace custom sitemap with datasette-sitemap #116

Open
simonw opened this issue Aug 29, 2022 · 1 comment
Open

Replace custom sitemap with datasette-sitemap #116

simonw opened this issue Aug 29, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Aug 29, 2022

New plugin: https://github.com/simonw/datasette-sitemap

Can replace this:

async def urls(datasette):
paths = ["/", "/for", "/examples", "/plugins", "/tools", "/news"]
db = datasette.get_database("content")
for row in await db.execute("select _path from uses"):
paths.append("/" + row["_path"].split(".")[0])
for row in await db.execute("select name from plugins"):
paths.append("/plugins/" + row["name"])
for row in await db.execute("select name from tools"):
paths.append("/tools/" + row["name"])
return ("https://datasette.io{}".format(path) for path in paths)
async def sitemap_xml(datasette):
content = [
'<?xml version="1.0" encoding="UTF-8"?>',
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
]
for url in await urls(datasette):
content.append("<url><loc>{}</loc></url>".format(url))
content.append("</urlset>")
return Response("\n".join(content), 200, content_type="application/xml")

@simonw simonw added the enhancement New feature or request label Aug 29, 2022
@simonw
Copy link
Owner Author

simonw commented Aug 29, 2022

Maybe use this as an excuse to solve the thing where datasette-block-robots and datasette-sitemap can intefere with each other since they both try to register /robots.txt.

Could do that by teaching datasette-block-robots to detect if datasette-sitemap is installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant