Merge pull request #130 from DanielGrams/issue/129-robots

Missing robots.txt causes internal server error #129
This commit is contained in:
Daniel Grams 2021-02-24 16:01:12 +01:00 committed by GitHub
commit 48cbc4e8cd
3 changed files with 9 additions and 14 deletions

View File

@ -56,8 +56,10 @@ cache_path = (
) )
dump_path = os.path.join(cache_path, "dump") dump_path = os.path.join(cache_path, "dump")
img_path = os.path.join(cache_path, "img") img_path = os.path.join(cache_path, "img")
sitemap_path = os.path.join(cache_path, "sitemap.xml") sitemap_file = "sitemap.xml"
robots_txt_path = os.path.join(cache_path, "robots.txt") robots_txt_file = "robots.txt"
sitemap_path = os.path.join(cache_path, sitemap_file)
robots_txt_path = os.path.join(cache_path, robots_txt_file)
# i18n # i18n
app.config["BABEL_DEFAULT_LOCALE"] = "de" app.config["BABEL_DEFAULT_LOCALE"] = "de"

View File

@ -233,7 +233,7 @@
{% if link %} {% if link %}
<div> <div>
<i class="fa fa-fw fa-link" data-toggle="tooltip" title="{{ _('Link') }}"></i> <i class="fa fa-fw fa-link" data-toggle="tooltip" title="{{ _('Link') }}"></i>
<a href="{{ link }}" target="_blank" rel="noopener noreferrer">{{ link }}</a> <a href="{{ link }}" target="_blank" rel="noopener noreferrer" style="word-break: break-all;">{{ link }}</a>
</div> </div>
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}

View File

@ -1,18 +1,11 @@
import json import json
import os.path import os.path
from flask import ( from flask import redirect, render_template, request, send_from_directory, url_for
redirect,
render_template,
request,
send_file,
send_from_directory,
url_for,
)
from flask_babelex import gettext from flask_babelex import gettext
from markupsafe import Markup from markupsafe import Markup
from project import app, dump_path, robots_txt_path, sitemap_path from project import app, cache_path, dump_path, robots_txt_file, sitemap_file
from project.services.admin import upsert_settings from project.services.admin import upsert_settings
from project.views.utils import track_analytics from project.views.utils import track_analytics
@ -97,9 +90,9 @@ def static_from_root():
@app.route("/robots.txt") @app.route("/robots.txt")
def robots_txt(): def robots_txt():
return send_file(robots_txt_path) return send_from_directory(cache_path, robots_txt_file)
@app.route("/sitemap.xml") @app.route("/sitemap.xml")
def sitemap_xml(): def sitemap_xml():
return send_file(sitemap_path) return send_from_directory(cache_path, sitemap_file)