mirror of
https://github.com/donlon/cloudflare-error-page.git
synced 2025-12-19 14:59:28 +00:00
editor: support page icon
This commit is contained in:
@@ -7,6 +7,12 @@ SHARE_LINK_DIGITS = 7
|
||||
# Use short share url (without '/s' path)
|
||||
SHORT_SHARE_URL = false
|
||||
|
||||
# Icon URL for rendered pages
|
||||
PAGE_ICON_URL = ''
|
||||
|
||||
# MIME type of page icon
|
||||
PAGE_ICON_TYPE = 'image/png'
|
||||
|
||||
# Set to true if trust X-Forwarded-For/X-Forwarded-Proto header
|
||||
BEHIND_PROXY = true
|
||||
|
||||
|
||||
@@ -12,8 +12,9 @@ from flask import (
|
||||
)
|
||||
|
||||
from cloudflare_error_page import ErrorPageParams
|
||||
from cloudflare_error_page import render as render_cf_error_page
|
||||
from .utils import fill_cf_template_params
|
||||
from .utils import (
|
||||
render_extended_template,
|
||||
)
|
||||
|
||||
root_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../')
|
||||
examples_dir = os.path.join(root_dir, 'examples')
|
||||
@@ -50,7 +51,5 @@ def index(name: str):
|
||||
if params is None:
|
||||
abort(404)
|
||||
|
||||
fill_cf_template_params(params)
|
||||
|
||||
# Render the error page
|
||||
return render_cf_error_page(params)
|
||||
return render_extended_template(params=params)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import html
|
||||
import random
|
||||
import string
|
||||
|
||||
@@ -13,49 +12,20 @@ from flask import (
|
||||
redirect,
|
||||
url_for,
|
||||
)
|
||||
from jinja2 import Environment, select_autoescape
|
||||
|
||||
from cloudflare_error_page import (
|
||||
default_template as cf_template,
|
||||
render as render_cf_error_page,
|
||||
)
|
||||
|
||||
from . import (
|
||||
db,
|
||||
limiter,
|
||||
models
|
||||
models,
|
||||
)
|
||||
|
||||
from .utils import fill_cf_template_params, sanitize_page_param_links
|
||||
|
||||
# root_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../')
|
||||
# examples_dir = os.path.join(root_dir, 'examples')
|
||||
env = Environment(
|
||||
autoescape=select_autoescape(),
|
||||
trim_blocks=True,
|
||||
lstrip_blocks=True,
|
||||
from .utils import (
|
||||
render_extended_template,
|
||||
sanitize_page_param_links,
|
||||
)
|
||||
template = env.from_string('''
|
||||
{% extends base %}
|
||||
|
||||
{% block header %}
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:site_name" content="moe::virt" />
|
||||
<meta property="og:title" content="{{ html_title }}" />
|
||||
<meta property="og:url" content="{{ url }}" />
|
||||
<meta property="og:description" content="{{ description }}" />
|
||||
|
||||
<meta property="twitter:card" content="summary" />
|
||||
<meta property="twitter:site" content="moe::virt" />
|
||||
<meta property="twitter:title" content="{{ html_title }}" />
|
||||
<meta property="twitter:description" content="{{ description }}" />
|
||||
{% endblock %}
|
||||
''')
|
||||
|
||||
bp = Blueprint('share', __name__, url_prefix='/')
|
||||
bp_short = Blueprint('share_short', __name__, url_prefix='/')
|
||||
|
||||
|
||||
rand_charset = string.ascii_lowercase + string.digits
|
||||
|
||||
def get_rand_name(digits=8):
|
||||
@@ -131,15 +101,9 @@ def get(name: str):
|
||||
'text': 'CF Error Page Editor',
|
||||
'link': request.host_url[:-1] + url_for('editor.index') + f'#from={name}',
|
||||
}
|
||||
fill_cf_template_params(params)
|
||||
sanitize_page_param_links(params)
|
||||
|
||||
return render_cf_error_page(params=params,
|
||||
allow_html=False,
|
||||
template=template,
|
||||
base=cf_template,
|
||||
url=request.url,
|
||||
description='Cloudflare error page')
|
||||
return render_extended_template(params=params,
|
||||
allow_html=False)
|
||||
|
||||
|
||||
@bp.get('/<name>')
|
||||
|
||||
@@ -1,11 +1,47 @@
|
||||
import json
|
||||
import os
|
||||
from typing import Any
|
||||
|
||||
from cloudflare_error_page import ErrorPageParams
|
||||
from flask import request
|
||||
from cloudflare_error_page import (
|
||||
ErrorPageParams,
|
||||
default_template as base_template,
|
||||
render as render_cf_error_page,
|
||||
)
|
||||
from flask import current_app, request
|
||||
from jinja2 import Environment, select_autoescape
|
||||
|
||||
from . import root_dir
|
||||
|
||||
env = Environment(
|
||||
autoescape=select_autoescape(),
|
||||
trim_blocks=True,
|
||||
lstrip_blocks=True,
|
||||
)
|
||||
template = env.from_string('''
|
||||
{% extends base %}
|
||||
|
||||
{% block header %}
|
||||
{% if page_icon_url %}
|
||||
{% if page_icon_type %}
|
||||
<link rel="icon" href="{{ page_icon_url }}" type="{{ page_icon_type }}">
|
||||
{% else %}
|
||||
<link rel="icon" href="{{ page_icon_url }}">
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:site_name" content="moe::virt" />
|
||||
<meta property="og:title" content="{{ html_title }}" />
|
||||
<meta property="og:url" content="{{ url }}" />
|
||||
<meta property="og:description" content="{{ description }}" />
|
||||
|
||||
<meta property="twitter:card" content="summary" />
|
||||
<meta property="twitter:site" content="moe::virt" />
|
||||
<meta property="twitter:title" content="{{ html_title }}" />
|
||||
<meta property="twitter:description" content="{{ description }}" />
|
||||
{% endblock %}
|
||||
''')
|
||||
|
||||
|
||||
loc_data: dict = None
|
||||
|
||||
@@ -74,3 +110,18 @@ def sanitize_page_param_links(param: ErrorPageParams):
|
||||
link = perf_sec_by.get('link')
|
||||
if link:
|
||||
perf_sec_by['link'] = sanitize_user_link(link)
|
||||
|
||||
|
||||
def render_extended_template(params: ErrorPageParams,
|
||||
*args: Any,
|
||||
**kwargs: Any) -> str:
|
||||
fill_cf_template_params(params)
|
||||
return render_cf_error_page(params=params,
|
||||
template=template,
|
||||
base=base_template,
|
||||
page_icon_url=current_app.config.get('PAGE_ICON_URL'),
|
||||
page_icon_type=current_app.config.get('PAGE_ICON_TYPE'),
|
||||
url=request.url,
|
||||
description='Cloudflare error page',
|
||||
*args,
|
||||
**kwargs)
|
||||
|
||||
Reference in New Issue
Block a user