Skip to content

Commit 5051a1a

Browse files
committed
Revert "测试继续优化"
This reverts commit d419393.
1 parent 90ba5fd commit 5051a1a

3 files changed

Lines changed: 27 additions & 191 deletions

File tree

docs/javascripts/altium-loader.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

docs/javascripts/mathjax.js

Lines changed: 20 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,25 @@
1-
(function () {
2-
const MATHJAX_SRC = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js';
3-
const PANGU_SRC = (typeof document !== 'undefined') ? new URL('javascripts/pangu.min.js', document.baseURI).href : '/javascripts/pangu.min.js';
4-
const pendingScripts = new Map();
5-
let mathjaxReady;
6-
7-
window.MathJax = {
8-
tex: {
9-
inlineMath: [["\(", "\)"]],
10-
displayMath: [["\[", "\]"]],
11-
processEscapes: true,
12-
processEnvironments: true
13-
},
14-
options: {
15-
ignoreHtmlClass: ".*|",
16-
processHtmlClass: "arithmatex"
17-
},
18-
chtml: {
19-
fontURL: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/output/chtml/fonts/woff-v2'
20-
}
21-
};
22-
23-
function loadScript(id, src, attrs) {
24-
if (pendingScripts.has(id)) {
25-
return pendingScripts.get(id);
26-
}
27-
28-
if (document.getElementById(id)) {
29-
return Promise.resolve();
30-
}
31-
32-
const promise = new Promise((resolve, reject) => {
33-
const script = document.createElement('script');
34-
script.id = id;
35-
script.src = src;
36-
script.async = true;
37-
38-
if (attrs) {
39-
Object.keys(attrs).forEach((key) => {
40-
if (key === 'defer' || key === 'async') {
41-
script[key] = Boolean(attrs[key]);
42-
} else {
43-
script.setAttribute(key, attrs[key]);
44-
}
45-
});
46-
}
47-
48-
script.onload = () => resolve();
49-
script.onerror = () => reject(new Error('Failed to load script: ' + src));
50-
document.head.appendChild(script);
51-
});
52-
53-
pendingScripts.set(id, promise);
54-
return promise;
55-
}
56-
57-
function ensureMathJax(root) {
58-
if (!root.querySelector('.arithmatex')) {
59-
return;
60-
}
61-
62-
if (window.MathJax && typeof window.MathJax.typesetPromise === 'function') {
63-
window.MathJax.typesetPromise();
64-
return;
65-
}
66-
67-
if (!mathjaxReady) {
68-
mathjaxReady = loadScript('mathjax-cdn-script', MATHJAX_SRC, { defer: true, crossorigin: 'anonymous' })
69-
.then(() => {
70-
if (window.MathJax && window.MathJax.startup && window.MathJax.startup.promise) {
71-
return window.MathJax.startup.promise;
72-
}
73-
return undefined;
74-
})
75-
.catch((error) => {
76-
console.error('[MathJax] Unable to load:', error);
77-
});
78-
}
79-
80-
mathjaxReady?.then(() => {
81-
if (window.MathJax && typeof window.MathJax.typesetPromise === 'function') {
82-
window.MathJax.typesetPromise();
83-
}
84-
});
1+
window.MathJax = {
2+
tex: {
3+
inlineMath: [["\\(", "\\)"]],
4+
displayMath: [["\\[", "\\]"]],
5+
processEscapes: true,
6+
processEnvironments: true
7+
},
8+
options: {
9+
ignoreHtmlClass: ".*|",
10+
processHtmlClass: "arithmatex"
11+
},
12+
chtml: {
13+
fontURL: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/output/chtml/fonts/woff-v2'
8514
}
15+
};
8616

87-
function applyPangu(root) {
88-
const target = root.querySelector('.md-content');
89-
if (!target || !window.pangu) {
90-
return;
91-
}
92-
93-
if (typeof window.pangu.spacingElement === 'function') {
94-
window.pangu.spacingElement(target);
95-
} else if (typeof window.pangu.spacingPageBody === 'function') {
96-
window.pangu.spacingPageBody();
97-
}
98-
}
99-
100-
let panguLoading;
101-
102-
function ensurePangu(root) {
103-
if (document.documentElement && document.documentElement.lang && document.documentElement.lang.indexOf('zh') !== 0) {
104-
return;
105-
}
106-
107-
if (!root.querySelector('.md-content')) {
108-
return;
109-
}
110-
111-
if (window.pangu) {
112-
applyPangu(root);
113-
return;
114-
}
115-
116-
if (!panguLoading) {
117-
panguLoading = loadScript('pangu-script', PANGU_SRC, { defer: true })
118-
.catch((error) => {
119-
console.error('[Pangu] Unable to load:', error);
120-
});
121-
}
122-
123-
panguLoading?.then(() => applyPangu(root));
124-
}
125-
126-
function handlePage() {
127-
const root = document;
128-
ensureMathJax(root);
129-
ensurePangu(root);
17+
document$.subscribe(() => {
18+
if (window.MathJax && typeof window.MathJax.typesetPromise === 'function') {
19+
window.MathJax.typesetPromise();
13020
}
131-
132-
if (typeof document !== 'undefined') {
133-
document.addEventListener('DOMContentLoaded', handlePage);
21+
if (window.pangu && typeof window.pangu.spacingPageBody === 'function') {
22+
window.pangu.spacingPageBody();
13423
}
24+
});
13525

136-
if (typeof document$ !== 'undefined') {
137-
document$.subscribe(handlePage);
138-
}
139-
})();

mkdocs.yml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -273,17 +273,11 @@ markdown_extensions:
273273
format: !!python/name:pymdownx.superfences.fence_code_format
274274

275275
extra_javascript:
276-
- javascripts/mathjax.js
277-
- javascripts/altium-loader.js
278-
- javascripts/adsense.js # AdSense script
279-
# - javascripts/test-adsense.js # AdSense test script (development only)
280-
281-
#---
282-
# - https://cdnjs.cloudflare.com/ajax/libs/pangu/4.0.7/pangu.min.js
283-
# - javascripts/mathjax.js #https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/latest.min.js
284-
# - https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=es6 #https://polyfill.io/v3/polyfill.min.js?features=es6
285-
# - https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js
286-
# - https://viewer.altium.com/client/static/js/embed.js # javascripts/embed.js
287-
# - javascripts/adsense.js # AdSense广告脚本
288-
# - javascripts/test-adsense.js # AdSense测试脚本(开发时使用)
276+
- https://cdnjs.cloudflare.com/ajax/libs/pangu/4.0.7/pangu.min.js
277+
- javascripts/mathjax.js #https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/latest.min.js
278+
- https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=es6 #https://polyfill.io/v3/polyfill.min.js?features=es6
279+
- https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js
280+
- https://viewer.altium.com/client/static/js/embed.js # javascripts/embed.js
281+
- javascripts/adsense.js # AdSense广告脚本
282+
- javascripts/test-adsense.js # AdSense测试脚本(开发时使用)
289283

0 commit comments

Comments
 (0)