From d0b408a664cfbdd788bc6c3ea636b46516b9c632 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sun, 17 Feb 2019 10:28:43 +0100 Subject: [PATCH] Fix sitemap --- netlify.toml | 3 +++ sitemap.py | 34 +++++++++++++--------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/netlify.toml b/netlify.toml index 0a882c40c..b4ba3adef 100644 --- a/netlify.toml +++ b/netlify.toml @@ -6,6 +6,9 @@ [context.beta] environment = { BASE_URL = "https://beta.esphome.io" } +[context.next] + environment = { BASE_URL = "https://next.esphome.io" } + # A basic redirect rule [[redirects]] from = "/esphomeyaml/*" diff --git a/sitemap.py b/sitemap.py index e84c553e5..b5114323e 100644 --- a/sitemap.py +++ b/sitemap.py @@ -1,18 +1,5 @@ -# Copyright (c) 2013 Michael Dowling -# Copyright (c) 2017 Jared Dillard -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. - +import os import xml.etree.ElementTree as ET -from sphinx.writers.html import HTMLTranslator def setup(app): @@ -31,22 +18,27 @@ def create_sitemap(app, exception): """Generates the sitemap.xml from the collected HTML page links""" root = ET.Element("urlset") root.set("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9") - root.set("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance") - root.set("xsi:schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9 \ - http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd") for link in app.sitemap_links: url = ET.SubElement(root, "url") - ET.SubElement(url, "loc").text = app.builder.config.html_baseurl + '/' + link priority = 0.5 - if link.endswith('index.html'): - priority += 0.25 if link == 'index.html': priority = 1.0 + link = '' + elif link.endswith('index.html'): + priority += 0.25 + link = link[:-len('index.html')] + if link.endswith('.html'): + link = link[:-len('.html')] + ET.SubElement(url, "loc").text = app.builder.config.html_baseurl + '/' + link ET.SubElement(url, "priority").text = str(priority) - filename = app.outdir + "/sitemap.xml" + filename = os.path.join(app.outdir, "sitemap.xml") ET.ElementTree(root).write(filename, xml_declaration=True, encoding='utf-8', method="xml") + + if app.builder.config.html_baseurl != 'https://esphome.io': + with open(os.path.join(app.builder.outdir, 'robots.txt'), 'wt') as f: + f.write('User-agent: *\nDisallow: /\n')