]> khamidou — GitHub mirrors - rfcspot.git/commitdiff
(test) adding sitemap support
authorKarim Hamidou <khamidou@gmail.com>
Sun, 27 Mar 2016 05:09:07 +0000 (22:09 -0700)
committerKarim Hamidou <khamidou@gmail.com>
Sun, 27 Mar 2016 05:09:07 +0000 (22:09 -0700)
app.py
templates/sitemap.html [new file with mode: 0644]

diff --git a/app.py b/app.py
index 2e5826cfbe09c6d12dc1f995ceb46e3b7d2f31f9..315023cb4b904683d7977bf8e5cb8e1ae6b03646 100644 (file)
--- a/app.py
+++ b/app.py
@@ -1,7 +1,8 @@
 import os
 import json
 import datetime
-from flask import Flask, render_template, request, redirect, url_for
+from flask import (Flask, render_template, request, redirect,
+                   url_for, make_response)
 from src.render_rfc import render_html_rfc
 
 
@@ -52,6 +53,17 @@ def list_rfc():
                            untitled_rfc=sorted_untitled_list)
 
 
+@app.route('/sitemap.xml')
+def sitemap_view():
+    """Render website's sitemap."""
+    sitemap = render_template('sitemap.html', rfcs=metadata.values())
+
+    # We need to set the content-type header correctly.
+    response = make_response(sitemap)
+    response.headers['Content-Type'] = 'application/xml'
+    return response
+
+
 @app.after_request
 def add_header(response):
     """
diff --git a/templates/sitemap.html b/templates/sitemap.html
new file mode 100644 (file)
index 0000000..42c707f
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
+        <url>
+            <loc>http://www.rfcspot.com/</loc>
+            <changefreq>weekly</changefreq>
+            <priority>0.8</priority>
+        </url>
+        {% for rfc in rfcs %}
+            {% if 'rfc' in rfc %}
+                <url>
+                    <loc>http://www.rfcspot.com/{{ rfc['rfc'] }}</loc>
+                    <changefreq>weekly</changefreq>
+                    <priority>0.8</priority>
+                </url>
+            {% endif %}
+        {% endfor %}
+    </urlset>
+</xml>