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:
@@ -20,6 +20,7 @@ env = Environment(
|
|||||||
lstrip_blocks=True,
|
lstrip_blocks=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# TODO: rename to base_template
|
||||||
default_template: Template = env.get_template("error.html")
|
default_template: Template = env.get_template("error.html")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,12 @@ SHARE_LINK_DIGITS = 7
|
|||||||
# Use short share url (without '/s' path)
|
# Use short share url (without '/s' path)
|
||||||
SHORT_SHARE_URL = false
|
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
|
# Set to true if trust X-Forwarded-For/X-Forwarded-Proto header
|
||||||
BEHIND_PROXY = true
|
BEHIND_PROXY = true
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,9 @@ from flask import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from cloudflare_error_page import ErrorPageParams
|
from cloudflare_error_page import ErrorPageParams
|
||||||
from cloudflare_error_page import render as render_cf_error_page
|
from .utils import (
|
||||||
from .utils import fill_cf_template_params
|
render_extended_template,
|
||||||
|
)
|
||||||
|
|
||||||
root_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../')
|
root_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../')
|
||||||
examples_dir = os.path.join(root_dir, 'examples')
|
examples_dir = os.path.join(root_dir, 'examples')
|
||||||
@@ -50,7 +51,5 @@ def index(name: str):
|
|||||||
if params is None:
|
if params is None:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
fill_cf_template_params(params)
|
|
||||||
|
|
||||||
# Render the error page
|
# Render the error page
|
||||||
return render_cf_error_page(params)
|
return render_extended_template(params=params)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import html
|
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
|
||||||
@@ -13,49 +12,20 @@ from flask import (
|
|||||||
redirect,
|
redirect,
|
||||||
url_for,
|
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 (
|
from . import (
|
||||||
db,
|
db,
|
||||||
limiter,
|
limiter,
|
||||||
models
|
models,
|
||||||
)
|
)
|
||||||
|
from .utils import (
|
||||||
from .utils import fill_cf_template_params, sanitize_page_param_links
|
render_extended_template,
|
||||||
|
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,
|
|
||||||
)
|
)
|
||||||
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 = Blueprint('share', __name__, url_prefix='/')
|
||||||
bp_short = Blueprint('share_short', __name__, url_prefix='/')
|
bp_short = Blueprint('share_short', __name__, url_prefix='/')
|
||||||
|
|
||||||
|
|
||||||
rand_charset = string.ascii_lowercase + string.digits
|
rand_charset = string.ascii_lowercase + string.digits
|
||||||
|
|
||||||
def get_rand_name(digits=8):
|
def get_rand_name(digits=8):
|
||||||
@@ -131,15 +101,9 @@ def get(name: str):
|
|||||||
'text': 'CF Error Page Editor',
|
'text': 'CF Error Page Editor',
|
||||||
'link': request.host_url[:-1] + url_for('editor.index') + f'#from={name}',
|
'link': request.host_url[:-1] + url_for('editor.index') + f'#from={name}',
|
||||||
}
|
}
|
||||||
fill_cf_template_params(params)
|
|
||||||
sanitize_page_param_links(params)
|
sanitize_page_param_links(params)
|
||||||
|
return render_extended_template(params=params,
|
||||||
return render_cf_error_page(params=params,
|
allow_html=False)
|
||||||
allow_html=False,
|
|
||||||
template=template,
|
|
||||||
base=cf_template,
|
|
||||||
url=request.url,
|
|
||||||
description='Cloudflare error page')
|
|
||||||
|
|
||||||
|
|
||||||
@bp.get('/<name>')
|
@bp.get('/<name>')
|
||||||
|
|||||||
@@ -1,11 +1,47 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from cloudflare_error_page import ErrorPageParams
|
from cloudflare_error_page import (
|
||||||
from flask import request
|
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
|
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
|
loc_data: dict = None
|
||||||
|
|
||||||
@@ -74,3 +110,18 @@ def sanitize_page_param_links(param: ErrorPageParams):
|
|||||||
link = perf_sec_by.get('link')
|
link = perf_sec_by.get('link')
|
||||||
if link:
|
if link:
|
||||||
perf_sec_by['link'] = sanitize_user_link(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)
|
||||||
|
|||||||
BIN
editor/web/icon.png
Normal file
BIN
editor/web/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 708 B |
@@ -14,6 +14,7 @@
|
|||||||
<meta name="description" content="Online editor to create customized Cloudflare-style error pages.">
|
<meta name="description" content="Online editor to create customized Cloudflare-style error pages.">
|
||||||
<meta name="keywords" content="cloudflare,error,page,editor">
|
<meta name="keywords" content="cloudflare,error,page,editor">
|
||||||
<link rel="canonical" href="https://virt.moe/cferr/editor/" />
|
<link rel="canonical" href="https://virt.moe/cferr/editor/" />
|
||||||
|
<link rel="icon" type="image/png" href="icon.png">
|
||||||
|
|
||||||
<meta property="og:type" content="website" />
|
<meta property="og:type" content="website" />
|
||||||
<meta property="og:site_name" content="moe::virt" />
|
<meta property="og:site_name" content="moe::virt" />
|
||||||
|
|||||||
Reference in New Issue
Block a user