Skip to content

Commit db16c7f

Browse files
authored
Build custom 404 page at root (#1742)
* Build custom 404 page at root * Fix up orphan checks * Split test package docs into dev and stable versions * Make stable and dev trees separate for Dart compare_output_test * Search box refactor but still needs setting adjustment * Fix up search style * update test package docs
1 parent 8342fe0 commit db16c7f

File tree

12 files changed

+273
-30
lines changed

12 files changed

+273
-30
lines changed

lib/dartdoc.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,17 @@ class Dartdoc extends PackageBuilder {
247247
continue;
248248
}
249249
if (visited.contains(fullPath)) continue;
250-
if (!writtenFiles.contains(fullPath)) {
250+
String relativeFullPath = pathLib.relative(fullPath, from: normalOrigin);
251+
if (!writtenFiles.contains(relativeFullPath)) {
251252
// This isn't a file we wrote (this time); don't claim we did.
252253
_warn(packageGraph, PackageWarning.unknownFile, fullPath, normalOrigin);
253254
} else {
254-
_warn(
255-
packageGraph, PackageWarning.orphanedFile, fullPath, normalOrigin);
255+
// Error messages are orphaned by design and do not appear in the search
256+
// index.
257+
if (relativeFullPath != '__404error.html') {
258+
_warn(packageGraph, PackageWarning.orphanedFile, fullPath,
259+
normalOrigin);
260+
}
256261
}
257262
_onCheckProgress.add(fullPath);
258263
}

lib/resources/script.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function initSideNav() {
2727
}
2828
}
2929

30-
function initSearch() {
30+
function initSearch(name) {
3131
var searchIndex; // the JSON data
3232

3333
var weights = {
@@ -120,16 +120,16 @@ function initSearch() {
120120
}
121121
}
122122

123-
$('#search-box').prop('disabled', false);
124-
$('#search-box').prop('placeholder', 'Search');
123+
$('#' + name).prop('disabled', false);
124+
$('#' + name).prop('placeholder', 'Search');
125125
$(document).keypress(function(event) {
126126
if (event.which == 47 /* / */) {
127127
event.preventDefault();
128-
$('#search-box').focus();
128+
$('#' + name).focus();
129129
}
130130
});
131131

132-
$('#search-box.typeahead').typeahead({
132+
$('#' + name + '.typeahead').typeahead({
133133
hint: true,
134134
highlight: true,
135135
minLength: 1
@@ -156,7 +156,7 @@ function initSearch() {
156156
}
157157
});
158158

159-
var typeaheadElement = $('#search-box.typeahead');
159+
var typeaheadElement = $('#' + name + '.typeahead');
160160
var typeaheadElementParent = typeaheadElement.parent();
161161
var selectedSuggestion;
162162

@@ -187,13 +187,14 @@ function initSearch() {
187187
initTypeahead();
188188
});
189189
jsonReq.addEventListener('error', function() {
190-
$('#search-box').prop('placeholder', 'Error loading search index');
190+
$('#' + name).prop('placeholder', 'Error loading search index');
191191
});
192192
jsonReq.send();
193193
}
194194

195195
document.addEventListener("DOMContentLoaded", function() {
196196
hljs.initHighlightingOnLoad();
197197
initSideNav();
198-
initSearch();
198+
initSearch("search-box");
199+
initSearch("search-body");
199200
});

lib/resources/styles.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,15 @@ button {
776776
color: #999
777777
}
778778

779-
.tt-menu {
779+
.navbar-right .tt-menu {
780780
right:0;
781781
left: inherit !important;
782782
width: 422px;
783783
max-height: 250px;
784784
overflow-y: auto;
785+
}
786+
787+
.tt-menu {
785788
font-size: 14px;
786789
margin: 0;
787790
padding: 8px 0;
@@ -830,6 +833,12 @@ button {
830833
background-color: #ffffff;
831834
}
832835

836+
.search-body {
837+
border: 1px solid #7f7f7f;
838+
max-width: 400px;
839+
box-shadow: 3px 3px 5px rgba(0,0,0,0.1);
840+
}
841+
833842
section#setter {
834843
border-top: 1px solid #ddd;
835844
padding-top: 36px;

lib/src/html/html_generator_instance.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class HtmlGeneratorInstance {
170170
logInfo('documenting ${package.name}');
171171

172172
_build('index.html', _templates.indexTemplate, data);
173+
_build('__404error.html', _templates.errorTemplate, data);
173174
}
174175

175176
void generateLibrary(PackageGraph packageGraph, Library lib) {

lib/src/html/templates.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class Templates {
8383
final TemplateRenderer enumTemplate;
8484
final TemplateRenderer constantTemplate;
8585
final TemplateRenderer constructorTemplate;
86+
final TemplateRenderer errorTemplate;
8687
final TemplateRenderer functionTemplate;
8788
final TemplateRenderer indexTemplate;
8889
final TemplateRenderer libraryTemplate;
@@ -119,6 +120,7 @@ class Templates {
119120
var functionTemplate = await _loadTemplate('function.html');
120121
var methodTemplate = await _loadTemplate('method.html');
121122
var constructorTemplate = await _loadTemplate('constructor.html');
123+
var errorTemplate = await _loadTemplate('404error.html');
122124
var propertyTemplate = await _loadTemplate('property.html');
123125
var constantTemplate = await _loadTemplate('constant.html');
124126
var topLevelConstantTemplate =
@@ -135,6 +137,7 @@ class Templates {
135137
functionTemplate,
136138
methodTemplate,
137139
constructorTemplate,
140+
errorTemplate,
138141
propertyTemplate,
139142
constantTemplate,
140143
topLevelConstantTemplate,
@@ -150,6 +153,7 @@ class Templates {
150153
this.functionTemplate,
151154
this.methodTemplate,
152155
this.constructorTemplate,
156+
this.errorTemplate,
153157
this.propertyTemplate,
154158
this.constantTemplate,
155159
this.topLevelConstantTemplate,

lib/templates/404error.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{{>head}}
2+
3+
<div class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left">
4+
<h5><span class="package-name">{{self.name}}</span> <span class="package-kind">{{self.kind}}</span></h5>
5+
{{>packages}}
6+
</div>
7+
8+
<div class="col-xs-12 col-sm-9 col-md-8 main-content">
9+
<h1>404: Something's gone wrong :-(</h1>
10+
11+
<section class="desc">
12+
<p>You've tried to visit a page that doesn't exist. Luckily this site
13+
has other <a href="index.html">pages</a>.</p>
14+
<p>If you were looking for something specific, try searching:
15+
<form class="search-body" role="search">
16+
<input type="text" id="search-body" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
17+
</form>
18+
</p>
19+
20+
</section>
21+
</div> <!-- /.main-content -->
22+
23+
{{>footer}}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<meta name="generator" content="made with love by dartdoc 0.20.3">
8+
<meta name="description" content="test_package API docs, for the Dart programming language.">
9+
<title>test_package - Dart API docs</title>
10+
11+
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500,400i,400,300|Source+Sans+Pro:400,300,700" rel="stylesheet">
12+
<link rel="stylesheet" href="static-assets/github.css">
13+
<link rel="stylesheet" href="static-assets/styles.css">
14+
<link rel="icon" href="static-assets/favicon.png">
15+
16+
</head>
17+
18+
<body>
19+
20+
<div id="overlay-under-drawer"></div>
21+
22+
<header id="title">
23+
<ol class="breadcrumbs gt-separated dark hidden-xs">
24+
<li><a href="http://github.com/dart-lang">test_package package</a></li>
25+
</ol>
26+
<div class="self-name">test_package</div>
27+
<form class="search navbar-right" role="search">
28+
<input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
29+
</form>
30+
</header>
31+
32+
<main>
33+
34+
<div class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left">
35+
<h5><span class="package-name">test_package</span> <span class="package-kind">package</span></h5>
36+
<ol>
37+
<li class="section-title">Libraries</li>
38+
<li><a href="anonymous_library/anonymous_library-library.html">anonymous_library</a></li>
39+
<li><a href="another_anonymous_lib/another_anonymous_lib-library.html">another_anonymous_lib</a></li>
40+
<li><a href="code_in_comments/code_in_comments-library.html">code_in_comments</a></li>
41+
<li><a class="deprecated" href="is_deprecated/is_deprecated-library.html">is_deprecated</a></li>
42+
<li class="section-subtitle">Real Libraries</li>
43+
<li class="section-subitem"><a href="ex/ex-library.html">ex</a></li>
44+
<li class="section-subitem"><a href="fake/fake-library.html">fake</a></li>
45+
<li class="section-subtitle">Unreal</li>
46+
<li class="section-subitem"><a href="reexport_one/reexport_one-library.html">reexport_one</a></li>
47+
<li class="section-subitem"><a href="reexport_two/reexport_two-library.html">reexport_two</a></li>
48+
<li class="section-subtitle">Misc</li>
49+
<li class="section-subitem"><a href="two_exports/two_exports-library.html">two_exports</a></li>
50+
<li class="section-subtitle">Other</li>
51+
<li class="section-subitem"><a href="css/css-library.html">css</a></li>
52+
<li class="section-title">test_package_imported</li>
53+
<li><a href="test_package_imported.main/test_package_imported.main-library.html">test_package_imported.main</a></li>
54+
</ol>
55+
</div>
56+
57+
<div class="col-xs-12 col-sm-9 col-md-8 main-content">
58+
<h1>404: Something's gone wrong :-(</h1>
59+
60+
<section class="desc">
61+
<p>You've tried to visit a page that doesn't exist. Luckily this site
62+
has other <a href="index.html">pages</a>.</p>
63+
<p>If you were looking for something specific, try searching:
64+
<form class="search-body" role="search">
65+
<input type="text" id="search-body" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
66+
</form>
67+
</p>
68+
69+
</section>
70+
</div> <!-- /.main-content -->
71+
72+
</main>
73+
74+
<footer>
75+
<span class="no-break">
76+
test_package 0.0.1
77+
</span>
78+
79+
</footer>
80+
81+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
82+
<script src="static-assets/typeahead.bundle.min.js"></script>
83+
<script src="static-assets/highlight.pack.js"></script>
84+
<script src="static-assets/URI.js"></script>
85+
<script src="static-assets/script.js"></script>
86+
87+
88+
</body>
89+
90+
</html>

testing/test_package_docs/static-assets/script.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function initSideNav() {
2727
}
2828
}
2929

30-
function initSearch() {
30+
function initSearch(name) {
3131
var searchIndex; // the JSON data
3232

3333
var weights = {
@@ -120,16 +120,16 @@ function initSearch() {
120120
}
121121
}
122122

123-
$('#search-box').prop('disabled', false);
124-
$('#search-box').prop('placeholder', 'Search');
123+
$('#' + name).prop('disabled', false);
124+
$('#' + name).prop('placeholder', 'Search');
125125
$(document).keypress(function(event) {
126126
if (event.which == 47 /* / */) {
127127
event.preventDefault();
128-
$('#search-box').focus();
128+
$('#' + name).focus();
129129
}
130130
});
131131

132-
$('#search-box.typeahead').typeahead({
132+
$('#' + name + '.typeahead').typeahead({
133133
hint: true,
134134
highlight: true,
135135
minLength: 1
@@ -156,7 +156,7 @@ function initSearch() {
156156
}
157157
});
158158

159-
var typeaheadElement = $('#search-box.typeahead');
159+
var typeaheadElement = $('#' + name + '.typeahead');
160160
var typeaheadElementParent = typeaheadElement.parent();
161161
var selectedSuggestion;
162162

@@ -187,13 +187,14 @@ function initSearch() {
187187
initTypeahead();
188188
});
189189
jsonReq.addEventListener('error', function() {
190-
$('#search-box').prop('placeholder', 'Error loading search index');
190+
$('#' + name).prop('placeholder', 'Error loading search index');
191191
});
192192
jsonReq.send();
193193
}
194194

195195
document.addEventListener("DOMContentLoaded", function() {
196196
hljs.initHighlightingOnLoad();
197197
initSideNav();
198-
initSearch();
198+
initSearch("search-box");
199+
initSearch("search-body");
199200
});

testing/test_package_docs/static-assets/styles.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,15 @@ button {
776776
color: #999
777777
}
778778

779-
.tt-menu {
779+
.navbar-right .tt-menu {
780780
right:0;
781781
left: inherit !important;
782782
width: 422px;
783783
max-height: 250px;
784784
overflow-y: auto;
785+
}
786+
787+
.tt-menu {
785788
font-size: 14px;
786789
margin: 0;
787790
padding: 8px 0;
@@ -830,6 +833,12 @@ button {
830833
background-color: #ffffff;
831834
}
832835

836+
.search-body {
837+
border: 1px solid #7f7f7f;
838+
max-width: 400px;
839+
box-shadow: 3px 3px 5px rgba(0,0,0,0.1);
840+
}
841+
833842
section#setter {
834843
border-top: 1px solid #ddd;
835844
padding-top: 36px;

0 commit comments

Comments
 (0)