-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: supports exception page template for theme-side (#2925)
#### What type of PR is this? /kind feature /area core #### What this PR does / why we need it: 主题端支持异常模板页面 异常模板必须放在主题目录的 `templates/error` 目录下: - 支持按照 response status 名称模板页面,例如 404.html ,当发生 404 错误时会使用 404.html - 支持 4xx.html、5xx.html,例如当发生 403 错误时,如果存在 403.html 则使用此页面,否则使用 4xx.html error 模板中具有 model 示例: ```json { "error": { "type": "about:blank", "title": "Not Found", "status": 404, "detail": "Extension run.halo.app.core.extension.Plugin with name amet ut magn not found", "instance": "/apis/plugin.halo.run/v1alpha1/plugins/amet%20ut%20magn" } } ``` #### Which issue(s) this PR fixes: Fixes #2690 #### Special notes for your reviewer: /cc @halo-dev/sig-halo #### Does this PR introduce a user-facing change? ```release-note 主题端支持异常模板页面 ```
- Loading branch information
Showing
3 changed files
with
249 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<!DOCTYPE html> | ||
<html lang="zh" xmlns:th="https://www.thymeleaf.org"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1"> | ||
<title th:text="${error.status} + ' | ' + ${#strings.defaultString(error.title, 'Internal server error')}"></title> | ||
<style> | ||
body { | ||
padding: 30px 20px; | ||
font-family: -apple-system, BlinkMacSystemFont, | ||
"Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", | ||
"Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; | ||
color: #727272; | ||
line-height: 1.6; | ||
} | ||
|
||
.container { | ||
max-width: 500px; | ||
margin: 0 auto; | ||
} | ||
|
||
h1 { | ||
margin: 0; | ||
font-size: 60px; | ||
line-height: 1; | ||
color: #252427; | ||
font-weight: 700; | ||
display: inline-block; | ||
} | ||
|
||
h2 { | ||
margin: 100px 0 0; | ||
font-weight: 600; | ||
letter-spacing: 0.1em; | ||
color: #A299AC; | ||
text-transform: uppercase; | ||
} | ||
|
||
p { | ||
font-size: 16px; | ||
margin: 1em 0; | ||
} | ||
|
||
@media screen and (min-width: 768px) { | ||
body { | ||
padding: 50px; | ||
} | ||
} | ||
|
||
@media screen and (max-width: 480px) { | ||
h1 { | ||
font-size: 48px; | ||
} | ||
} | ||
|
||
.title { | ||
position: relative; | ||
} | ||
|
||
.title::before { | ||
content: ''; | ||
position: absolute; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
height: 2px; | ||
background-color: #000; | ||
transform-origin: bottom right; | ||
transform: scaleX(0); | ||
transition: transform 0.5s ease; | ||
} | ||
|
||
.title:hover::before { | ||
transform-origin: bottom left; | ||
transform: scaleX(1); | ||
} | ||
|
||
.back-home button { | ||
z-index: 1; | ||
position: relative; | ||
font-size: inherit; | ||
font-family: inherit; | ||
color: white; | ||
padding: 0.5em 1em; | ||
outline: none; | ||
border: none; | ||
background-color: hsl(0, 0%, 0%); | ||
overflow: hidden; | ||
transition: color 0.4s ease-in-out; | ||
} | ||
|
||
.back-home button::before { | ||
content: ''; | ||
z-index: -1; | ||
position: absolute; | ||
top: 100%; | ||
left: 100%; | ||
width: 1em; | ||
height: 1em; | ||
border-radius: 50%; | ||
background-color: #fff; | ||
transform-origin: center; | ||
transform: translate3d(-50%, -50%, 0) scale3d(0, 0, 0); | ||
transition: transform 0.45s ease-in-out; | ||
} | ||
|
||
.back-home button:hover { | ||
cursor: pointer; | ||
color: #000; | ||
} | ||
|
||
.back-home button:hover::before { | ||
transform: translate3d(-50%, -50%, 0) scale3d(15, 15, 15); | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<div class="container"> | ||
<h2 th:text="${error.status}"></h2> | ||
<h1 class="title" th:text="${#strings.defaultString(error.title, 'Internal server error')}"></h1> | ||
<p th:text="${#strings.defaultString(error.detail, '未知错误!可能存在的原因:未正确设置主题或主题文件缺失。')}"></p> | ||
<div class="back-home"> | ||
<button th:onclick="window.location.href='[(${site.url})]'" | ||
th:text="首页"> | ||
</button> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |