Skip to content

Commit 2e6ccfe

Browse files
authored
Fix docs initial render (#3247)
1 parent 70ae43f commit 2e6ccfe

4 files changed

Lines changed: 46 additions & 39 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
> backend. Shared repro URLs encode them in the URL fragment (`#state=...`), which browsers do not send to the server;
1010
> the full URL can still be stored in your browser history or wherever you share it.
1111
12-
[![PyPI version](https://badge.fury.io/py/datamodel-code-generator.svg)](https://pypi.python.org/pypi/datamodel-code-generator)
12+
[![PyPI version](https://img.shields.io/pypi/v/datamodel-code-generator.svg)](https://pypi.python.org/pypi/datamodel-code-generator)
1313
[![Conda-forge](https://img.shields.io/conda/v/conda-forge/datamodel-code-generator)](https://anaconda.org/conda-forge/datamodel-code-generator)
1414
[![Downloads](https://api.pepy.tech/badge/datamodel-code-generator/month)](https://pepy.tech/projects/datamodel-code-generator)
1515
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/datamodel-code-generator)](https://pypi.python.org/pypi/datamodel-code-generator)

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
🚀 Generate Python data models from schema definitions in seconds.
44

5-
[![PyPI version](https://badge.fury.io/py/datamodel-code-generator.svg)](https://pypi.python.org/pypi/datamodel-code-generator)
5+
[![PyPI version](https://img.shields.io/pypi/v/datamodel-code-generator.svg)](https://pypi.python.org/pypi/datamodel-code-generator)
66
[![Conda-forge](https://img.shields.io/conda/v/conda-forge/datamodel-code-generator)](https://anaconda.org/conda-forge/datamodel-code-generator)
77
[![Downloads](https://api.pepy.tech/badge/datamodel-code-generator/month)](https://pepy.tech/projects/datamodel-code-generator)
88
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/datamodel-code-generator)](https://pypi.python.org/pypi/datamodel-code-generator)

docs/llms-full.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Source: https://datamodel-code-generator.koxudaxi.dev/
44

55
🚀 Generate Python data models from schema definitions in seconds.
66

7-
[![PyPI version](https://badge.fury.io/py/datamodel-code-generator.svg)](https://pypi.python.org/pypi/datamodel-code-generator)
7+
[![PyPI version](https://img.shields.io/pypi/v/datamodel-code-generator.svg)](https://pypi.python.org/pypi/datamodel-code-generator)
88
[![Conda-forge](https://img.shields.io/conda/v/conda-forge/datamodel-code-generator)](https://anaconda.org/conda-forge/datamodel-code-generator)
99
[![Downloads](https://api.pepy.tech/badge/datamodel-code-generator/month)](https://pepy.tech/projects/datamodel-code-generator)
1010
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/datamodel-code-generator)](https://pypi.python.org/pypi/datamodel-code-generator)

overrides/main.html

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
background: #0f172a;
88
}
99

10-
html.dcg-theme-loading body {
11-
visibility: hidden;
12-
}
13-
1410
.md-toggle {
1511
position: absolute;
1612
width: 0;
@@ -42,40 +38,51 @@
4238
}
4339
</style>
4440
<script>
45-
const isPlaygroundLink = link => {
46-
const url = new URL(link.href);
47-
return url.origin === window.location.origin && (
48-
url.pathname.endsWith("/playground/") ||
49-
url.pathname.endsWith("/assets/playground/index.html")
50-
);
51-
};
52-
53-
document.documentElement.classList.add("dcg-theme-loading");
54-
window.setTimeout(() => {
55-
document.documentElement.classList.remove("dcg-theme-loading");
56-
}, 3000);
57-
window.addEventListener("DOMContentLoaded", () => {
58-
for (const link of document.querySelectorAll("a[href]")) {
59-
if (isPlaygroundLink(link)) {
60-
link.target = "_self";
41+
(() => {
42+
const html = document.documentElement;
43+
const revealPage = () => html.classList.remove("dcg-theme-loading");
44+
const getPlaygroundUrl = link => {
45+
try {
46+
const url = new URL(link.getAttribute("href") || "", window.location.href);
47+
const isPlayground = url.origin === window.location.origin && (
48+
url.pathname.endsWith("/playground/") ||
49+
url.pathname.endsWith("/assets/playground/index.html")
50+
);
51+
return isPlayground ? url : null;
52+
} catch {
53+
return null;
6154
}
55+
};
56+
const initPage = () => {
57+
for (const link of document.querySelectorAll("a[href]")) {
58+
if (getPlaygroundUrl(link)) {
59+
link.setAttribute("target", "_self");
60+
}
61+
}
62+
window.requestAnimationFrame(revealPage);
63+
};
64+
65+
html.classList.add("dcg-theme-loading");
66+
window.setTimeout(revealPage, 3000);
67+
if (document.readyState === "loading") {
68+
window.addEventListener("DOMContentLoaded", initPage, { once: true });
69+
} else {
70+
initPage();
6271
}
63-
window.requestAnimationFrame(() => {
64-
document.documentElement.classList.remove("dcg-theme-loading");
65-
});
66-
});
67-
document.addEventListener("click", event => {
68-
if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
69-
return;
70-
}
71-
const target = event.target instanceof Element ? event.target : event.target.parentElement;
72-
const link = target ? target.closest("a[href]") : null;
73-
if (!link || !isPlaygroundLink(link)) {
74-
return;
75-
}
76-
event.preventDefault();
77-
window.location.assign(link.href);
78-
}, true);
72+
document.addEventListener("click", event => {
73+
if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
74+
return;
75+
}
76+
const target = event.target instanceof Element ? event.target : event.target.parentElement;
77+
const link = target ? target.closest("a[href]") : null;
78+
const url = link ? getPlaygroundUrl(link) : null;
79+
if (!url) {
80+
return;
81+
}
82+
event.preventDefault();
83+
window.location.assign(url.href);
84+
}, true);
85+
})();
7986
</script>
8087
{% endblock %}
8188

0 commit comments

Comments
 (0)