Skip to content

Commit 603a409

Browse files
committed
fix disqus recommendation width (possibly due to the removed ads) via js
1 parent 0dc998a commit 603a409

File tree

4 files changed

+79
-33
lines changed

4 files changed

+79
-33
lines changed

docs/10-Boosting-and-Additive-Trees/10.9-Boosting-Trees.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $$
1616
因此,一棵树可以正式地表达成
1717

1818
$$
19-
T(x;\Theta)=\sum\limits_{j=1}^J\gamma_jI(x\in R_j)\tag{10.25}
19+
T(x;\Theta)=\sum\limits_{j=1}^J\gamma_jI(x\in R_j)\tag{10.25}\label{10.25}
2020
$$
2121

2222
其中参数为 $\Theta=\\{R_j,\gamma_j\\}_1^J$.$J$ 通常看成是元参数.通过最小化 **经验风险 (empirical risk)** 来确定

docs/css/misc.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,20 @@ label.md-nav__title {
9090
.md-typeset table:not([class]) {
9191
max-width: none !important;
9292
table-layout: auto !important;
93+
}
94+
95+
/* 强制推荐模块宽度为100% */
96+
#disqus_recommendations iframe {
97+
width: 100% !important;
98+
max-width: 100% !important;
99+
margin: 0 !important;
100+
left: 0 !important;
101+
transform: none !important;
102+
}
103+
104+
/* 确保父容器不受限制 */
105+
#disqus_recommendations {
106+
width: 100% !important;
107+
max-width: none !important;
108+
overflow: visible !important;
93109
}

material/base.html

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,28 @@
6767
{% block libs %}
6868
<script src="{{ base_url }}/assets/javascripts/modernizr.js"></script>
6969
{% endblock %}
70+
{% block disqus_ads %}
71+
<!--rm disqus ad refer to https://www.javaer101.com/article/25891160.html-->
72+
<script src="{{ base_url }}/assets/javascripts/jquery-latest.min.js"></script>
73+
<script>
74+
(function($){
75+
setInterval(() => {
76+
$.each($('iframe'), (arr,x) => {
77+
let src = $(x).attr('src');
78+
if (src && src.match(/(ads-iframe)|(disqusads)/gi)) {
79+
$(x).remove();
80+
}
81+
let title = $(x).attr('title');
82+
if (!src && title == "Disqus") {
83+
$(x).remove();
84+
}
85+
});
86+
}, 300);
87+
})(jQuery);
88+
</script>
89+
{% endblock %}
7090
{% block disqus_js %}
7191
{% if config.extra.disqus and not page.is_homepage %}
72-
<!--rm disqus ad refer to https://www.javaer101.com/article/25891160.html-->
73-
<script src="{{ base_url }}/assets/javascripts/jquery-latest.min.js"></script>
74-
<script>
75-
(function($){
76-
setInterval(() => {
77-
$.each($('iframe'), (arr,x) => {
78-
let src = $(x).attr('src');
79-
if (src && src.match(/(ads-iframe)|(disqusads)/gi)) {
80-
$(x).remove();
81-
}
82-
let title = $(x).attr('title');
83-
if (!src && title == "Disqus") {
84-
$(x).remove();
85-
}
86-
});
87-
}, 300);
88-
})(jQuery);
89-
</script>
9092
{% endif %}
9193
{% endblock %}
9294
{% block fonts %}
@@ -217,16 +219,6 @@ <h2 id="__source">{{ lang.t("meta.source") }}</h2>
217219
{% endblock %}
218220
{% block disqus_free %}
219221
{% if config.extra.disqus and not page.is_homepage %}
220-
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
221-
<ins class="adsbygoogle"
222-
style="display:block; text-align:center;"
223-
data-ad-layout="in-article"
224-
data-ad-format="fluid"
225-
data-ad-client="ca-pub-3680148472128768"
226-
data-ad-slot="6465742678"></ins>
227-
<script>
228-
(adsbygoogle = window.adsbygoogle || []).push({});
229-
</script>
230222
<h2 id="__comments">{{ lang.t("meta.comments") }}</h2>
231223
{% include "partials/integrations/disqus.html" %}
232224
{% endif %}
@@ -280,5 +272,43 @@ <h2 id="__comments">{{ lang.t("meta.comments") }}</h2>
280272
{% include "partials/integrations/analytics.html" %}
281273
{% endif %}
282274
{% endblock %}
275+
<!--adjust disqus recommendation width (possibly occupied by ads)-->
276+
<script>
277+
// 确保在 DOM 完全加载后执行
278+
document.addEventListener('DOMContentLoaded', function() {
279+
// 定义修复宽度的函数
280+
function fixDisqusWidth() {
281+
const iframe = document.querySelector('#disqus_recommendations iframe');
282+
if (iframe) {
283+
iframe.style.cssText += 'width: 100% !important; max-width: 100% !important;';
284+
}
285+
}
286+
287+
// 初次尝试修复
288+
fixDisqusWidth();
289+
290+
// 监听 Disqus 容器的动态加载
291+
const observer = new MutationObserver(function(mutations) {
292+
fixDisqusWidth();
293+
});
294+
295+
// 获取 Disqus 容器
296+
const targetNode = document.getElementById('disqus_recommendations');
297+
if (targetNode) {
298+
// 如果容器已存在,直接监听
299+
observer.observe(targetNode, { childList: true, subtree: true });
300+
} else {
301+
// 如果容器未加载,监听整个文档直到其出现
302+
const docObserver = new MutationObserver(function(mutations) {
303+
const lateTarget = document.getElementById('disqus_recommendations');
304+
if (lateTarget) {
305+
observer.observe(lateTarget, { childList: true, subtree: true });
306+
docObserver.disconnect();
307+
}
308+
});
309+
docObserver.observe(document.body, { childList: true, subtree: true });
310+
}
311+
});
312+
</script>
283313
</body>
284314
</html>

material/partials/integrations/disqus.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<div id="disqus_thread"></div>
1919
<script>
20-
if (window.location.hostname !== "localhost" && window.location.hostname !== "127.0.0.1") {
20+
// if (window.location.hostname !== "localhost" && window.location.hostname !== "127.0.0.1") {
2121
var disqus_config = function () {
2222
this.page.url = "{{ page.canonical_url }}";
2323
this.page.identifier =
@@ -29,9 +29,9 @@
2929
s.setAttribute("data-timestamp", +new Date());
3030
(d.head || d.body).appendChild(s);
3131
})();
32-
} else {
33-
console.log("Disqus is disabled on localhost.");
34-
}
32+
// } else {
33+
// console.log("Disqus is disabled on localhost.");
34+
// }
3535
</script>
3636

3737

0 commit comments

Comments
 (0)