mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-28 04:33:42 +08:00
website: make placement code not error on homepage
This commit is contained in:
@ -5,6 +5,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() {
|
||||
return (
|
||||
@ -28,14 +29,22 @@ function initAd() {
|
||||
return $el;
|
||||
}
|
||||
|
||||
const $tocEl = document.querySelector('[class^="tableOfContents"]');
|
||||
const $tocEl = document.querySelector(CONTAINER_SELECTOR);
|
||||
if ($tocEl == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const $newEl = document.createElement('div');
|
||||
$newEl.id = AD_ELEMENT_ID;
|
||||
$tocEl.appendChild($newEl);
|
||||
$tocEl.append($newEl);
|
||||
|
||||
return $newEl;
|
||||
})();
|
||||
|
||||
if ($adEl == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ReactDOM.render(<SidebarAd />, $adEl);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user