Skip to content

Commit 361d9ee

Browse files
Set dark/light theme for EthicalAds
1 parent 2925124 commit 361d9ee

File tree

5 files changed

+104
-47
lines changed

5 files changed

+104
-47
lines changed

src/extra/EthicalAds.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, {useState, useEffect} from 'react';
2+
import clsx from 'clsx';
3+
import { useColorMode } from '@docusaurus/theme-common';
4+
5+
export default function EthicalAds({id, type}) {
6+
const {colorMode} = useColorMode();
7+
const [isInitialized, setIsInitialized] = useState(false);
8+
const [isEthABlocked, setIsEthABlocked] = useState(false)
9+
useEffect(() => {
10+
if (isInitialized) {
11+
return;
12+
}
13+
setIsInitialized(true);
14+
try {
15+
setIsEthABlocked(typeof ethicalads === 'undefined')
16+
ethicalads.load_placements()
17+
} catch (error) {
18+
setIsEthABlocked(false)
19+
}
20+
});
21+
return (
22+
<div>
23+
<div
24+
data-ea-publisher="neutralino"
25+
data-ea-type={type}
26+
id={"neutralino-" + id}
27+
className={clsx(colorMode, isInitialized && "loaded")}>
28+
</div>
29+
</div>
30+
);
31+
}

src/pages/index.js

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
88
import styles from './styles.module.css';
99
import {Adsense} from '@ctrl/react-adsense';
1010
import logo from '../../static/logo.gif';
11+
import EthicalAds from '../extra/EthicalAds';
1112

1213
const youtubeLink = "https://www.youtube.com/c/CodeZri";
1314
const features = [
@@ -95,21 +96,7 @@ function Feature({imageUrl, title, description}) {
9596
export default function Home() {
9697
const context = useDocusaurusContext();
9798
const {siteConfig = {}} = context;
98-
const [isInitialized, setIsInitialized] = useState(false);
99-
const [isEthABlocked, setIsEthABlocked] = useState(false);
100-
useEffect(() => {
101-
if(isInitialized) {
102-
return;
103-
}
104-
setIsInitialized(true);
105-
try {
106-
setIsEthABlocked(typeof ethicalads === 'undefined');
107-
ethicalads.load_placements();
108-
}
109-
catch (error) {
110-
setIsEthABlocked(false);
111-
}
112-
});
99+
113100
return (
114101
<Layout
115102
title={`${siteConfig.tagline}`}
@@ -119,14 +106,7 @@ export default function Home() {
119106
<img src={logo + '?v=' + Math.floor(Math.random() * 10000) } alt="Neutralinojs logo animation" />
120107
<h1 className="hero__title">{siteConfig.title}</h1>
121108
<p className="hero__subtitle">{siteConfig.tagline}</p>
122-
<div>
123-
<div
124-
data-ea-publisher="neutralino"
125-
data-ea-type="image"
126-
id="neutralino-front"
127-
>
128-
</div>
129-
</div>
109+
<EthicalAds id="front" type="image"/>
130110
<div className={styles.buttons}>
131111
<Link
132112
className={clsx(

src/theme/DocItem/TOC/Desktop/index.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import React, {useState, useEffect} from 'react';
1+
import React from 'react';
22
import {useDoc} from '@docusaurus/theme-common/internal';
33
import clsx from 'clsx';
44
import styles from './styles.module.css';
5-
import { useTOCHighlight } from "@docusaurus/theme-common/internal"
5+
import { useTOCHighlight } from "@docusaurus/theme-common/internal";
6+
import EthicalAds from '../../../../extra/EthicalAds';
67

78
const LINK_CLASS_NAME = 'table-of-contents__link';
89
const ACTIVE_LINK_CLASS_NAME = 'table-of-contents__link--active';
@@ -45,30 +46,9 @@ function Headings({
4546

4647
function CustomTOC({ toc, frontMatter }) {
4748
useTOCHighlight({linkClassName: LINK_CLASS_NAME, linkActiveClassName: ACTIVE_LINK_CLASS_NAME, maxHeadingLevel: TOP_OFFSET, minHeadingLevel: 0});
48-
const [isInitialized, setIsInitialized] = useState(false);
49-
const [isEthABlocked, setIsEthABlocked] = useState(false)
50-
useEffect(() => {
51-
if (isInitialized) {
52-
return;
53-
}
54-
setIsInitialized(true);
55-
try {
56-
setIsEthABlocked(typeof ethicalads === 'undefined')
57-
ethicalads.load_placements()
58-
} catch (error) {
59-
setIsEthABlocked(false)
60-
}
61-
});
6249
return (
6350
<div className={clsx(styles.tableOfContents, 'thin-scrollbar')}>
64-
<div>
65-
<div
66-
data-ea-publisher="neutralino"
67-
data-ea-type="image"
68-
id="neutralino-docs"
69-
>
70-
</div>
71-
</div>
51+
<EthicalAds id="docs" type="image"/>
7252
<Headings toc={toc} frontMatter={frontMatter}/>
7353
</div>
7454
);

src/theme/EditMetaRow/index.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
import React, {type ReactNode} from 'react';
8+
import clsx from 'clsx';
9+
import EditThisPage from '@theme/EditThisPage';
10+
import type {Props} from '@theme/EditMetaRow';
11+
import {Adsense} from '@ctrl/react-adsense';
12+
13+
import LastUpdated from '@theme/LastUpdated';
14+
import styles from './styles.module.css';
15+
16+
export default function EditMetaRow({
17+
className,
18+
editUrl,
19+
lastUpdatedAt,
20+
lastUpdatedBy,
21+
}: Props): ReactNode {
22+
return (
23+
<>
24+
<div className={clsx('row', className)}>
25+
<div className="col padding--sm">
26+
<Adsense
27+
client='ca-pub-4805219819571962'
28+
slot='1174653824'
29+
style={{ display: 'block' }}
30+
layout='in-article'
31+
format='auto'
32+
/>
33+
</div>
34+
</div>
35+
<div className={clsx('row', className)}>
36+
<div className="col">{editUrl && <EditThisPage editUrl={editUrl} />}</div>
37+
<div className={clsx('col', styles.lastUpdated)}>
38+
{(lastUpdatedAt || lastUpdatedBy) && (
39+
<LastUpdated
40+
lastUpdatedAt={lastUpdatedAt}
41+
lastUpdatedBy={lastUpdatedBy}
42+
/>
43+
)}
44+
</div>
45+
</div>
46+
</>
47+
);
48+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
.lastUpdated {
9+
font-size: smaller;
10+
font-style: italic;
11+
margin-top: 0.2rem;
12+
}
13+
14+
@media (min-width: 997px) {
15+
.lastUpdated {
16+
text-align: right;
17+
}
18+
}

0 commit comments

Comments
 (0)