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

View File

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

View File

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

View File

@ -25,45 +25,45 @@ const {
<meta name="author" content={author} />
<meta name="description" content={description} />
<link rel="sitemap" href="/sitemap-index.xml" />
<meta name="google-adsense-account" content="ca-pub-2655673927481085" />
<title>{title}</title>
</head>
<body
class="flex flex-col place-items-center bg-ctp-base ctp-latte text-ctp-text dark:ctp-mocha"
>
<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>
</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>