Skip to content

Commit f576ce4

Browse files
committed
fix 404.html
1 parent 3066b6f commit f576ce4

File tree

2 files changed

+52
-62
lines changed

2 files changed

+52
-62
lines changed

docs/conf.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"sphinxcontrib.httpdomain",
3131
"sphinx_gallery.gen_gallery",
3232
"sphinx_design",
33-
"myst_nb"
33+
"myst_nb",
3434
]
3535

3636
print(
@@ -45,7 +45,7 @@
4545
"plot_gallery": True, # Generate plots for examples
4646
}
4747

48-
#pytorch_project = "tutorials"
48+
# pytorch_project = "tutorials"
4949
torch_version = str(torch.__version__)
5050
version = "main (" + torch_version + " )"
5151
# The full version, including alpha/beta/rc tags.
@@ -74,7 +74,7 @@
7474
]
7575

7676
html_additional_pages = {
77-
'404': '404.html',
77+
"404": "404.html",
7878
}
7979

8080
# The suffix of source filenames.
@@ -199,7 +199,8 @@
199199
# "json_url": "https://docs.pytorch.org/docs/pytorch-versions.json",
200200
# "version_match": "main",
201201
# },
202-
"canonical_url": "https://pytorch.org/docs/stable/",
202+
# "canonical_url": "https://pytorch.org/docs/stable/",
203+
"canonical_url": "http://localhost:8000",
203204
"pytorch_project": "tutorials",
204205
}
205206

@@ -240,9 +241,15 @@ def setup(app):
240241

241242
def hide_edit_button_for_pages(app, pagename, templatename, context, doctree):
242243
if pagename == "installing" or pagename.startswith("installing/"):
243-
context["theme_use_edit_page_button"] = False
244+
context["theme_edit_page_button"] = False
244245

245246

247+
# The base URL which points to the root of the HTML documentation. It is used
248+
# to indicate the location of document using The Canonical Link Relation.
249+
# Default: None.
250+
# Example for GitHub Pages: https://user.github.io/project/ (with trailing slash)
251+
html_baseurl = "http://localhost:8000/" # Set this for production deployment
252+
246253
# The name for this set of Sphinx documents. If None, it defaults to
247254
# "<project> v<release> documentation".
248255
# html_title = None
Lines changed: 40 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,31 @@
11
{% extends "!layout.html" %}
22

33
{% block extrahead %}
4-
{{ super() }}
5-
<script>
6-
// Fix static asset paths for 404 page on static hosting
7-
(function () {
8-
// Skip on localhost/development
9-
if (window.location.hostname === 'localhost' ||
10-
window.location.hostname === '127.0.0.1') {
11-
return;
12-
}
4+
<!DOCTYPE html>
5+
<html>
6+
<head>
7+
<meta charset="UTF-8">
8+
<meta name="viewport" content="width=device-width, initial-scale=1" />
9+
<title> 404 - Page Not Found </title>
10+
</head>
1311

14-
// Get the base path for _static assets
15-
let basePath = '/';
16-
17-
// On docs.pytorch.org, use first subdirectory (e.g. /tutorials, /docs) as base
18-
if (window.location.hostname === 'docs.pytorch.org') {
19-
const pathParts = window.location.pathname.split('/').filter(part => part);
20-
if (pathParts.length > 0) {
21-
basePath = '/' + pathParts[0] + '/';
22-
}
23-
}
12+
<base href="{{ theme_canonical_url }}">
13+
<script type="text/javascript" src="_static/js/theme.js"></script>
14+
<link rel="stylesheet" type="text/css" href="_static/styles/bootstrap.css" crossorigin="anonymous">
15+
<link rel="stylesheet" type="text/css" href="_static/styles/pydata-sphinx-theme.css" crossorigin="anonymous">
16+
<link rel="preconnect" href="https://fonts.googleapis.com">
17+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
18+
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400&display=swap" rel="stylesheet">
19+
<link rel="stylesheet" type="text/css" href="_static/css/theme.css" crossorigin="anonymous">
20+
<meta property="og:image" content="_static/img/pytorch_seo.png" />
21+
<link rel="stylesheet" href="_static/webfonts/all.min.css" crossorigin="anonymous">
22+
<meta http-equiv="Content-Security-Policy"
23+
content="default-src * 'unsafe-inline' 'unsafe-eval' data: blob:; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval' blob:;">
24+
<meta name="pytorch_project" content="{{ pytorch_project }}">
2425

25-
// Fix CSS links
26-
document.querySelectorAll('link[href*="_static"]').forEach(link => {
27-
if (!link.href.startsWith('http') && !link.href.startsWith('/')) {
28-
link.href = basePath + link.getAttribute('href');
29-
}
30-
});
3126

32-
// Fix script sources
33-
document.querySelectorAll('script[src*="_static"]').forEach(script => {
34-
if (!script.src.startsWith('http') && !script.src.startsWith('/')) {
35-
script.src = basePath + script.getAttribute('src');
36-
}
37-
});
38-
39-
// Fix image sources
40-
document.querySelectorAll('img[src*="_static"]').forEach(img => {
41-
if (!img.src.startsWith('http') && !img.src.startsWith('/')) {
42-
img.src = basePath + img.getAttribute('src');
43-
}
44-
});
45-
})();
46-
</script>
27+
<script async src="https://cse.google.com/cse.js?cx=e65585f8c3ea1440e"></script>
28+
{{ super() }}
4729
<!-- Conditional CSS for header and footer height adjustment -->
4830
{% if not theme_show_lf_header or not theme_show_lf_footer %}
4931
<style>
@@ -87,26 +69,27 @@
8769
{% endblock %}
8870

8971
{% block body %}
90-
<article class="bd-article" id="pytorch-article">
91-
<div class="container text-center error-404-container">
92-
<h1 class="error-404-title">404</h1>
93-
<h2 class="error-404-subtitle">Page Not Found</h2>
94-
<p class="error-404-text">The page you are looking for might have been removed, had its name changed, or is
95-
temporarily unavailable.</p>
96-
<div class="error-404-buttons">
97-
<a href="{{ pathto(master_doc) }}" class="btn btn-primary error-404-button">
98-
Back Home <i class="fa fa-arrow-right" aria-hidden="true"></i>
99-
</a>
100-
<a href="{{ theme_feedback_url|default('https://github.com/pytorch/pytorch') }}/issues/new?template=documentation.yml&labels=module:%20docs,broken-link"
101-
class="btn btn-secondary error-404-button error-404-issue-button">
102-
Found a broken link? File an issue <i class="fa-brands fa-github" aria-hidden="true"></i>
103-
</a>
104-
</div>
72+
{% include "components/searchbox.html" %}
73+
<div class="container text-center error-404-container">
74+
<h1 class="error-404-title">404</h1>
75+
<h2 class="error-404-subtitle">Page Not Found</h2>
76+
<p class="error-404-text">The page you are looking for might have been removed, had its name changed, or is
77+
temporarily unavailable.</p>
78+
<div class="error-404-buttons">
79+
<a href="http://localhost:8000/" class="btn btn-primary error-404-button">
80+
Back Home <i class="fa fa-arrow-right" aria-hidden="true"></i>
81+
</a>
82+
<a href="{{ theme_feedback_url|default('https://github.com/pytorch/pytorch') }}/issues/new?template=documentation.yml&labels=module:%20docs,broken-link"
83+
class="btn btn-secondary error-404-button error-404-issue-button">
84+
Found a broken link? File an issue <i class="fa-brands fa-github" aria-hidden="true"></i>
85+
</a>
10586
</div>
106-
</article>
107-
{% endblock body %}
87+
</div>
88+
{% endblock %}
10889

10990
{% block footer%}
11091
{% include "pytorch_footer.html" %}
11192
{{ super() }}
11293
{% endblock %}
94+
</body>
95+
</html>

0 commit comments

Comments
 (0)