mirror of
https://github.com/donlon/cloudflare-error-page.git
synced 2025-12-19 14:59:28 +00:00
editor/server: set meta description from page
This commit is contained in:
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
from typing import cast
|
||||||
|
|
||||||
|
|
||||||
|
from cloudflare_error_page import ErrorPageParams
|
||||||
from flask import (
|
from flask import (
|
||||||
Blueprint,
|
Blueprint,
|
||||||
current_app,
|
current_app,
|
||||||
@@ -85,7 +88,7 @@ def get(name: str):
|
|||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
return abort(404)
|
return abort(404)
|
||||||
params: dict = item.params
|
params = cast(ErrorPageParams, item.params)
|
||||||
params.pop('time', None)
|
params.pop('time', None)
|
||||||
params.pop('ray_id', None)
|
params.pop('ray_id', None)
|
||||||
params.pop('client_ip', None)
|
params.pop('client_ip', None)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from cloudflare_error_page import (
|
from cloudflare_error_page import (
|
||||||
@@ -17,8 +18,7 @@ env = Environment(
|
|||||||
trim_blocks=True,
|
trim_blocks=True,
|
||||||
lstrip_blocks=True,
|
lstrip_blocks=True,
|
||||||
)
|
)
|
||||||
template = env.from_string('''
|
template = env.from_string('''{% extends base %}
|
||||||
{% extends base %}
|
|
||||||
|
|
||||||
{% block header %}
|
{% block header %}
|
||||||
{% if page_icon_url %}
|
{% if page_icon_url %}
|
||||||
@@ -32,8 +32,8 @@ template = env.from_string('''
|
|||||||
<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" />
|
||||||
<meta property="og:title" content="{{ html_title }}" />
|
<meta property="og:title" content="{{ html_title }}" />
|
||||||
<meta property="og:url" content="{{ url }}" />
|
<meta property="og:url" content="{{ page_url }}" />
|
||||||
<meta property="og:description" content="{{ description }}" />
|
<meta property="og:description" content="{{ page_description }}" />
|
||||||
{% if page_image_url %}
|
{% if page_image_url %}
|
||||||
<meta property="og:image" content="{{ page_image_url }}" />
|
<meta property="og:image" content="{{ page_image_url }}" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -41,7 +41,7 @@ template = env.from_string('''
|
|||||||
<meta property="twitter:card" content="summary" />
|
<meta property="twitter:card" content="summary" />
|
||||||
<meta property="twitter:site" content="moe::virt" />
|
<meta property="twitter:site" content="moe::virt" />
|
||||||
<meta property="twitter:title" content="{{ html_title }}" />
|
<meta property="twitter:title" content="{{ html_title }}" />
|
||||||
<meta property="twitter:description" content="{{ description }}" />
|
<meta property="twitter:description" content="{{ page_description }}" />
|
||||||
{% if page_image_url %}
|
{% if page_image_url %}
|
||||||
<meta property="twitter:image" content="{{ page_image_url }}" />
|
<meta property="twitter:image" content="{{ page_image_url }}" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -122,6 +122,9 @@ def render_extended_template(params: ErrorPageParams,
|
|||||||
*args: Any,
|
*args: Any,
|
||||||
**kwargs: Any) -> str:
|
**kwargs: Any) -> str:
|
||||||
fill_cf_template_params(params)
|
fill_cf_template_params(params)
|
||||||
|
description = params.get('what_happened') or 'Cloudflare error page'
|
||||||
|
description = re.sub(r'</?.*?>', '', description).strip()
|
||||||
|
|
||||||
page_image_id = 'ok'
|
page_image_id = 'ok'
|
||||||
cf_status_obj = params.get('cloudflare_status')
|
cf_status_obj = params.get('cloudflare_status')
|
||||||
if cf_status_obj:
|
if cf_status_obj:
|
||||||
@@ -134,8 +137,8 @@ def render_extended_template(params: ErrorPageParams,
|
|||||||
base=base_template,
|
base=base_template,
|
||||||
page_icon_url=current_app.config.get('PAGE_ICON_URL'),
|
page_icon_url=current_app.config.get('PAGE_ICON_URL'),
|
||||||
page_icon_type=current_app.config.get('PAGE_ICON_TYPE'),
|
page_icon_type=current_app.config.get('PAGE_ICON_TYPE'),
|
||||||
url=request.url,
|
page_url=request.url,
|
||||||
description='Cloudflare error page',
|
page_description=description,
|
||||||
page_image_url=page_image_url,
|
page_image_url=page_image_url,
|
||||||
*args,
|
*args,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user