Skip to content

Commit 639cedc

Browse files
committed
Improve 404 perf and exp.
1 parent 9b22464 commit 639cedc

13 files changed

Lines changed: 141 additions & 53 deletions

File tree

converter/generator/DocIndexTransformer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace OriginLab.DocumentGeneration;
1+
using OriginLab.DocumentGeneration.Templates;
2+
3+
namespace OriginLab.DocumentGeneration;
24

35
internal class DocIndexTransformer : DocTransformer
46
{
@@ -25,5 +27,7 @@ public override async Task TransformFilesAsync(string language)
2527

2628
Transform(sourceFile, destinationFile);
2729
}
30+
31+
File.WriteAllText(Path.Combine(OutputFolder, language, "404.html"), await Template.Render404PageAsync(language));
2832
}
2933
}

converter/generator/DocTransformer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ internal async Task<string> InitializeLanguageLayoutAsync(string language)
160160
var scripts = await Template.RenderApplyLayoutScriptsAsync(new ApplyLayoutModel
161161
{
162162
LayoutPageUrl = '/'.TryPrefixEach(BookUrlName, language, $"layout.html?v={FileHash.FromString(html)}"),
163-
PlaceHolderId = "doc-content-placeholder",
164-
MainContentId = "main-content",
165163
});
166164

167165
Language = language;

converter/templates/ApplyLayoutModel.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,4 @@
33
public class ApplyLayoutModel
44
{
55
public required string LayoutPageUrl { get; init; }
6-
7-
public required string PlaceHolderId { get; init; }
8-
9-
public required string MainContentId { get; set; }
106
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<html>
2+
<head>
3+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
4+
<link rel="stylesheet" href="~/books/loading.css" asp-append-version="true" />
5+
<title>@ViewBag.Title</title>
6+
</head>
7+
<body>
8+
<div class="container">
9+
<div class="row">
10+
<div class="col-md-12">
11+
<div class="error-template">
12+
@RenderBody()
13+
</div>
14+
</div>
15+
</div>
16+
</div>
17+
<script>
18+
document.getElementById('url').innerText = decodeURIComponent(location.hash.substr(1));
19+
</script>
20+
</body>
21+
</html>
Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,2 @@
1-
<html>
2-
<head>
3-
<script src="~/books/loading.js" asp-append-version="true"></script>
4-
<script>tryRedirectFrom404()</script>
5-
6-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
7-
<link rel="stylesheet" href="~/books/loading.css" asp-append-version="true" />
8-
<title>An error occurred.</title>
9-
</head>
10-
<body>
11-
<div class="container">
12-
<div class="row">
13-
<div class="col-md-12">
14-
<div class="error-template">
15-
<h1>404</h1>
16-
<h2>Not Found</h2>
17-
<div class="error-details">
18-
The requested resource cannot be found.
19-
</div>
20-
<div class="error-actions">
21-
<a href="/" class="btn btn-primary">
22-
<span class="glyphicon glyphicon-home"></span>
23-
Return Home
24-
</a>
25-
<a href="mailto:webmaster@originlab.com" class="btn btn-default">
26-
<span class="glyphicon glyphicon-envelope"></span>
27-
Contact Support
28-
</a>
29-
</div>
30-
</div>
31-
</div>
32-
</div>
33-
</div>
34-
</body>
35-
</html>
1+
<script src="~/books/loading.js" asp-append-version="true"></script>
2+
<script>handle404()</script>

converter/templates/Partials/ApplyLayout.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
<script src="~/books/loading.js" asp-append-version="true"></script>
44
<link rel="stylesheet" href="~/books/loading.css" asp-append-version="true" />
55
<script>
6-
fetchApplyLayout('@(Model.LayoutPageUrl)', '@(Model.PlaceHolderId)', '@(Model.MainContentId)')
6+
applyLayout('@(Model.LayoutPageUrl)')
77
</script>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@{
2+
Layout = "/Layouts/404.cshtml";
3+
ViewBag.Title = "Ein Fehler ist aufgetreten";
4+
}
5+
6+
<h1>404</h1>
7+
<h2>Seite nicht gefunden</h2>
8+
<h3>
9+
Bitte überprüfen Sie, ob die URL korrekt ist.
10+
</h3>
11+
<p>👉<span id="url"></span></p>
12+
<div class="error-actions">
13+
<a href="/" class="btn btn-primary">
14+
<span class="glyphicon glyphicon-home"></span>
15+
Zur Startseite
16+
</a>
17+
<a href="https://www.originlab.com/index.aspx?go=COMPANY/ContactUS" class="btn btn-default">
18+
<span class="glyphicon glyphicon-envelope"></span>
19+
Kontakt
20+
</a>
21+
</div>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@{
2+
Layout = "/Layouts/404.cshtml";
3+
ViewBag.Title = "An error occurred";
4+
}
5+
6+
<h1>404</h1>
7+
<h2>Not Found</h2>
8+
<h3>
9+
Please make sure the URL is correct.
10+
</h3>
11+
<p>👉<span id="url"></span></p>
12+
<div class="error-actions">
13+
<a href="/" class="btn btn-primary">
14+
<span class="glyphicon glyphicon-home"></span>
15+
Return Home
16+
</a>
17+
<a href="https://www.originlab.com/index.aspx?go=COMPANY/ContactUS" class="btn btn-default">
18+
<span class="glyphicon glyphicon-envelope"></span>
19+
Contact Support
20+
</a>
21+
</div>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@{
2+
Layout = "/Layouts/404.cshtml";
3+
ViewBag.Title = "エラーが発生しました";
4+
}
5+
6+
<h1>404</h1>
7+
<h2>ページが見つかりません</h2>
8+
<h3>
9+
URLが正しいかご確認ください。
10+
</h3>
11+
<p>👉<span id="url"></span></p>
12+
<div class="error-actions">
13+
<a href="/" class="btn btn-primary">
14+
<span class="glyphicon glyphicon-home"></span>
15+
ホームに戻る
16+
</a>
17+
<a href="https://www.originlab.com/index.aspx?go=COMPANY/ContactUS" class="btn btn-default">
18+
<span class="glyphicon glyphicon-envelope"></span>
19+
お問い合わせ
20+
</a>
21+
</div>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@{
2+
Layout = "/Layouts/404.cshtml";
3+
ViewBag.Title = "出错啦";
4+
}
5+
6+
<h1>404</h1>
7+
<h2>找不到</h2>
8+
<h3>
9+
请确认地址正确。
10+
</h3>
11+
<p>👉<span id="url"></span></p>
12+
<div class="error-actions">
13+
<a href="/" class="btn btn-primary">
14+
<span class="glyphicon glyphicon-home"></span>
15+
返回主页
16+
</a>
17+
<a href="https://www.originlab.com/index.aspx?go=COMPANY/ContactUS" class="btn btn-default">
18+
<span class="glyphicon glyphicon-envelope"></span>
19+
联系我们
20+
</a>
21+
</div>

0 commit comments

Comments
 (0)