google adsense

This commit is contained in:
Sammy Shear 2024-07-26 11:43:33 -04:00
parent a729386a92
commit 2b2745d669
Signed by: sammyshear
GPG Key ID: 69B1EDA35F4F4C09
4 changed files with 81 additions and 79 deletions

View File

@ -1,23 +1,25 @@
--- ---
type Props = { measurementId: string } type Props = { measurementId: string };
const props = Astro.props as Props const props = Astro.props as Props;
const measurementId = props.measurementId const measurementId = props.measurementId;
--- ---
<script <script
type='text/partytown' type="text/partytown"
src={`https://www.googletagmanager.com/gtag/js?id=${measurementId}`}></script> src={`https://www.googletagmanager.com/gtag/js?id=${measurementId}`}
></script>
<script <script
type='text/partytown' type="text/partytown"
data-ga-measurement-id={measurementId} data-ga-measurement-id={measurementId}
id='ga-init' id="ga-init"
> >
const measurementId = document const measurementId = document
.getElementById('ga-init') .getElementById("ga-init")
.getAttribute('data-ga-measurement-id') .getAttribute("data-ga-measurement-id");
window.dataLayer = window.dataLayer || [] window.dataLayer = window.dataLayer || [];
function gtag() { function gtag() {
dataLayer.push(arguments) // eslint-disable-line dataLayer.push(arguments); // eslint-disable-line
} }
gtag('js', new Date()) gtag("js", new Date());
gtag('config', measurementId) gtag("config", measurementId);
</script> </script>

View File

@ -1,29 +1,29 @@
import type { CollectionEntry } from "astro:content"; import type { CollectionEntry } from "astro:content";
type Props = { type Props = {
posts: CollectionEntry<"blog">[]; posts: CollectionEntry<"blog">[];
}; };
export default function Posts({ posts }: Props) { export default function Posts({ posts }: Props) {
return ( return (
<div className="flex flex-col space-y-10 mt-5"> <div className="flex flex-col space-y-10 mt-5">
{posts.map((post: CollectionEntry<"blog">) => { {posts.map((post: CollectionEntry<"blog">) => {
return ( return (
<a <a
className="flex flex-col bg-ctp-surface1 p-4 rounded-md" className="flex flex-col bg-ctp-surface1 p-4 rounded-md"
key={post.id} key={post.id}
href={`/posts/${post.slug}`} href={`/posts/${post.slug}`}
> >
<span className="text-2xl">{post.data.title}</span> <span className="text-2xl">{post.data.title}</span>
<span className="text-sm text-ctp-subtext0"> <span className="text-sm text-ctp-subtext0">
{post.data.author} {post.data.author}
</span> </span>
<span className="text-sm text-ctp-subtext0"> <span className="text-sm text-ctp-subtext0">
{post.data.publishedTime.toLocaleDateString()} {post.data.publishedTime.toLocaleDateString()}
</span> </span>
</a> </a>
); );
})} })}
</div> </div>
); );
} }

View File

@ -2,12 +2,12 @@ import { SITE } from "../config";
import { defineCollection, z } from "astro:content"; import { defineCollection, z } from "astro:content";
const blog = defineCollection({ const blog = defineCollection({
type: "content", type: "content",
schema: z.object({ schema: z.object({
author: z.string().default(SITE.author), author: z.string().default(SITE.author),
title: z.string(), title: z.string(),
publishedTime: z.date() publishedTime: z.date()
}) })
}); });
export const collections = { blog }; export const collections = { blog };

View File

@ -25,45 +25,45 @@ const {
<meta name="author" content={author} /> <meta name="author" content={author} />
<meta name="description" content={description} /> <meta name="description" content={description} />
<link rel="sitemap" href="/sitemap-index.xml" /> <link rel="sitemap" href="/sitemap-index.xml" />
<meta name="google-adsense-account" content="ca-pub-2655673927481085" />
<title>{title}</title> <title>{title}</title>
</head> </head>
<body <body
class="flex flex-col place-items-center bg-ctp-base ctp-latte text-ctp-text dark:ctp-mocha" class="flex flex-col place-items-center bg-ctp-base ctp-latte text-ctp-text dark:ctp-mocha"
> >
<slot /> <slot />
<style is:global>
html.dark .astro-code,
html.dark .astro-code span {
color: var(--shiki-dark) !important;
background-color: var(--shiki-dark-bg) !important;
/* Optional, if you also want font styles */
font-style: var(--shiki-dark-font-style) !important;
font-weight: var(--shiki-dark-font-weight) !important;
text-decoration: var(--shiki-dark-text-decoration) !important;
}
</style>
<script is:inline>
const theme = (() => {
if (
typeof localStorage !== "undefined" &&
localStorage.getItem("theme")
) {
return localStorage.getItem("theme");
}
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
return "dark";
}
return "light";
})();
if (theme === "light") {
document.documentElement.classList.remove("dark");
} else {
document.documentElement.classList.add("dark");
}
window.localStorage.setItem("theme", theme);
</script>
</body> </body>
</html> </html>
<style is:global>
html.dark .astro-code,
html.dark .astro-code span {
color: var(--shiki-dark) !important;
background-color: var(--shiki-dark-bg) !important;
/* Optional, if you also want font styles */
font-style: var(--shiki-dark-font-style) !important;
font-weight: var(--shiki-dark-font-weight) !important;
text-decoration: var(--shiki-dark-text-decoration) !important;
}
</style>
<script is:inline>
const theme = (() => {
if (
typeof localStorage !== "undefined" &&
localStorage.getItem("theme")
) {
return localStorage.getItem("theme");
}
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
return "dark";
}
return "light";
})();
if (theme === "light") {
document.documentElement.classList.remove("dark");
} else {
document.documentElement.classList.add("dark");
}
window.localStorage.setItem("theme", theme);
</script>