mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-29 05:02:52 +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);
|
||||
},
|
||||
};
|
||||
})();
|
||||
|
Reference in New Issue
Block a user