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

Generate sitemaps and fix robots.txt path for analytics #13043

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion redirects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,6 @@ release-notes/precise-pangolin/?: "https://wiki.ubuntu.com/PrecisePangolin/Relea
releases/?: "https://releases.ubuntu.com"
releaseendoflife/?: "/about/release-cycle"
risc-v/?: "https://wiki.ubuntu.com/RISC-V"
robots.txt?: "/static/files/robots.txt"
robotics/esm/?: "/robotics/ros-esm"
rss\.xml/?: "/blog/feed"
rss\.xmlsubscribe=feed/?: "/blog/feed"
Expand Down
4 changes: 4 additions & 0 deletions robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
User-Agent: *
Disallow: /search
Disallow: /search*
Sitemap: https://ubuntu.com/sitemap.xml
4 changes: 0 additions & 4 deletions static/files/robots.txt

This file was deleted.

8 changes: 8 additions & 0 deletions webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
subscription_centre,
thank_you,
unlisted_engage_page,
build_engage_pages_sitemap,
)

DISCOURSE_API_KEY = os.getenv("DISCOURSE_API_KEY")
Expand Down Expand Up @@ -537,6 +538,13 @@
exclude_topics=[17229, 18033, 17250],
)


app.add_url_rule(
"/engage/sitemap.xml",
view_func=build_engage_pages_sitemap(engage_pages),
)


app.add_url_rule(
"/openstack/resources", view_func=openstack_engage(engage_pages)
)
Expand Down
30 changes: 30 additions & 0 deletions webapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,36 @@ def unlisted_engage_page(slug):
return flask.abort(404)


def build_engage_pages_sitemap(engage_pages):
"""
Create sitemaps for each engage page
"""

def ep_sitemap():
links = []
metadata = engage_pages.get_index()
if len(metadata) == 0:
flask.abort(404)

for page in metadata:
links.append(
{
"url": f'https://ubuntu.com/{page["path"]}',
"last_updated": page["updated"].strftime("%-d %B %Y"),
}
)

xml_sitemap = flask.render_template("sitemap.xml", links=links)

response = flask.make_response(xml_sitemap)
response.headers["Content-Type"] = "application/xml"
response.headers["Cache-Control"] = "public, max-age=43200"

return response

return ep_sitemap


def openstack_install():
"""
OpenStack install docs
Expand Down
Loading