mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-30 13:43:59 +08:00
website: remove hacky component injection code
This commit is contained in:
@ -4,10 +4,7 @@ import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
||||
|
||||
import styles from './styles.module.css';
|
||||
|
||||
const AD_ELEMENT_ID = 'ad-element-id';
|
||||
const CONTAINER_SELECTOR = '[class^="tableOfContents"]';
|
||||
|
||||
function SidebarAd() {
|
||||
export default function SidebarAd() {
|
||||
return (
|
||||
<a
|
||||
className={styles.container}
|
||||
@ -24,45 +21,3 @@ function SidebarAd() {
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
function initAd() {
|
||||
const $adEl = (() => {
|
||||
const $el = document.getElementById(AD_ELEMENT_ID);
|
||||
if ($el) {
|
||||
return $el;
|
||||
}
|
||||
|
||||
const $tocEl = document.querySelector(CONTAINER_SELECTOR);
|
||||
if ($tocEl == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const $newEl = document.createElement('div');
|
||||
$newEl.id = AD_ELEMENT_ID;
|
||||
$tocEl.prepend($newEl);
|
||||
|
||||
return $newEl;
|
||||
})();
|
||||
|
||||
if ($adEl == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ReactDOM.render(<SidebarAd />, $adEl);
|
||||
}
|
||||
|
||||
if (ExecutionEnvironment.canUseDOM) {
|
||||
window.onload = initAd;
|
||||
}
|
||||
|
||||
export default (function (context, options) {
|
||||
return {
|
||||
name: 'sidebar-ad',
|
||||
onRouteUpdate() {
|
||||
// Render only after the page renders.
|
||||
setTimeout(() => {
|
||||
initAd();
|
||||
}, 0);
|
||||
},
|
||||
};
|
||||
})();
|
||||
|
@ -1,11 +1,10 @@
|
||||
.container {
|
||||
background-color: var(--ifm-color-primary);
|
||||
background: linear-gradient(138deg, rgb(69, 104, 220), rgb(176, 106, 179));
|
||||
background-repeat: no-repeat;
|
||||
background-size: contain;
|
||||
border-radius: var(--ifm-global-radius);
|
||||
color: #fff;
|
||||
display: block;
|
||||
margin: 1rem;
|
||||
padding: 1rem;
|
||||
transition: background-color var(--ifm-transition-fast)
|
||||
var(--ifm-transition-timing-default);
|
||||
|
Reference in New Issue
Block a user