Skip to content

Commit

Permalink
Merge pull request #13043 from carkod/move-robots-wd-5011
Browse files Browse the repository at this point in the history
Generate sitemaps and fix robots.txt path for analytics
  • Loading branch information
carkod committed Jul 24, 2023
2 parents 38ed9ee + 8a9406e commit a3894cb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
1 change: 0 additions & 1 deletion redirects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,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 @@ -151,6 +151,7 @@
subscription_centre,
thank_you,
unlisted_engage_page,
build_engage_pages_sitemap,
)

DISCOURSE_API_KEY = os.getenv("DISCOURSE_API_KEY")
Expand Down Expand Up @@ -536,6 +537,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

0 comments on commit a3894cb

Please sign in to comment.