mirror of
https://github.com/donlon/cloudflare-error-page.git
synced 2025-12-19 14:59:28 +00:00
editor/server: add meta information in user-created pages
This commit is contained in:
@@ -3,7 +3,7 @@ import os
|
||||
import secrets
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from jinja2 import Environment, PackageLoader, select_autoescape
|
||||
from jinja2 import Environment, PackageLoader, Template, select_autoescape
|
||||
|
||||
env = Environment(
|
||||
loader=PackageLoader("cloudflare_error_page"),
|
||||
@@ -12,6 +12,7 @@ env = Environment(
|
||||
lstrip_blocks=True,
|
||||
)
|
||||
|
||||
default_template = env.get_template("error.html")
|
||||
|
||||
def get_resources_folder() -> str:
|
||||
"""
|
||||
@@ -21,19 +22,22 @@ def get_resources_folder() -> str:
|
||||
return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'resources')
|
||||
|
||||
|
||||
def render(params: dict, allow_html: bool=True, use_cdn: bool=True) -> str:
|
||||
"""
|
||||
Render a customized Cloudflare error page.
|
||||
"""
|
||||
params = {**params}
|
||||
def fill_params(params: dict):
|
||||
if not params.get('time'):
|
||||
utc_now = datetime.now(timezone.utc)
|
||||
params['time'] = utc_now.strftime("%Y-%m-%d %H:%M:%S UTC")
|
||||
if not params.get('ray_id'):
|
||||
params['ray_id'] = secrets.token_hex(8)
|
||||
|
||||
|
||||
def render(params: dict, allow_html: bool=True, use_cdn: bool=True) -> str:
|
||||
"""
|
||||
Render a customized Cloudflare error page.
|
||||
"""
|
||||
params = {**params}
|
||||
fill_params(params)
|
||||
if not allow_html:
|
||||
params['what_happened'] = html.escape(params.get('what_happened', ''))
|
||||
params['what_can_i_do'] = html.escape(params.get('what_can_i_do', ''))
|
||||
|
||||
template = env.get_template("error.html")
|
||||
return template.render(params=params, resources_use_cdn=use_cdn)
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
<head>
|
||||
{% set error_code = params.error_code or 500 %}
|
||||
{% set title = params.title or 'Internal server error' %}
|
||||
<title>{{ params.html_title or ((error_code | string) + ': ' + title) }}</title>
|
||||
{% set html_title = params.html_title or ((error_code | string) + ': ' + title) %}
|
||||
<title>{{ html_title }}</title>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
|
||||
<meta name="robots" content="noindex, nofollow" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
{% block header %}{% endblock %}
|
||||
<link rel="stylesheet" id="cf_styles-css" href="{{resources_cdn}}/cdn-cgi/styles/main.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Reference in New Issue
Block a user