Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add horizontal ads to bottom of articles #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions components/HorizontalAdvertisement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Image from "next/image";
import Link from "next/link";
import horizontalAdvertisements from "../horizontalAdvertisements";
import styles from "../styles/Advertisement.module.css";

const HorizontalAdvertisement = (props: { index: number , section_id: number}) => {
let index = props.index % horizontalAdvertisements.length;
let section_id = props.section_id;

if (section_id != 0 && section_id != 2) {
return (
<Link href={horizontalAdvertisements[index].url}>
<div id={styles.parent_div}>
<Image
id={styles.image}
src={horizontalAdvertisements[index].image_src}
fill
alt={horizontalAdvertisements[index].name + " ad"}
/>
</div>
</Link>
);
}
};

export default HorizontalAdvertisement;
8 changes: 8 additions & 0 deletions horizontalAdvertisements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const horizontalAdvertisements = [
{
name: "placeholder",
image_src: "/images/ads/horizontal_ad_placeholder.jpg",
url: "..",
},
];
export default horizontalAdvertisements;
8 changes: 7 additions & 1 deletion pages/article/[article_slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ShareButton from "../../components/ShareButton";
import Link from "next/link";
import generate_contributors_jsx from "../../components/GenerateContributorsJSX";
import { generateMetaTags } from "../../utils/generateMetaTags";
import HorizontalAdvertisement from "../../components/HorizontalAdvertisement";

interface Props {
article: ReceivedArticle;
Expand Down Expand Up @@ -160,7 +161,12 @@ function Article(props: Props) {

{/* <RecommendedArticles /> */}
</article>
<div id={styles.advertisements}></div>
<div id={styles.advertisements}>
<HorizontalAdvertisement
index={0}
section_id={section_id}
/>
</div>
</main>
</div>
);
Expand Down
Binary file added public/images/ads/horizontal_ad_placeholder.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.