feat: Enhance BaseHead and Note page metadata with Google Analytics and improved description

This commit is contained in:
KazooTTT
2025-02-08 17:14:24 +08:00
parent b0d1a1049a
commit d94384bc40
2 changed files with 15 additions and 12 deletions

View File

@ -89,6 +89,18 @@ const socialImageURL = new URL(ogImage ? ogImage : "/social-card.png", Astro.url
<meta name="baidu-site-verification" content="codeva-ZWUil8ENc0" /> <meta name="baidu-site-verification" content="codeva-ZWUil8ENc0" />
<meta name="google-adsense-account" content="ca-pub-6184816340945344" /> <meta name="google-adsense-account" content="ca-pub-6184816340945344" />
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-F4KLD4XCDB"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "G-F4KLD4XCDB");
</script>
<script <script
async async
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6184816340945344" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6184816340945344"
@ -108,17 +120,6 @@ const socialImageURL = new URL(ogImage ? ogImage : "/social-card.png", Astro.url
y.parentNode.insertBefore(t, y); y.parentNode.insertBefore(t, y);
})(window, document, "clarity", "script", "kvbyuhu6d2"); })(window, document, "clarity", "script", "kvbyuhu6d2");
</script> </script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-F4KLD4XCDB"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "G-F4KLD4XCDB");
</script>
<meta content={Astro.generator} name="generator" /> <meta content={Astro.generator} name="generator" />

View File

@ -4,6 +4,7 @@ import { getCollection } from "astro:content";
import Note from "@/components/note/Note.astro"; import Note from "@/components/note/Note.astro";
import PageLayout from "@/layouts/Base.astro"; import PageLayout from "@/layouts/Base.astro";
import type { GetStaticPaths, InferGetStaticPropsType } from "astro"; import type { GetStaticPaths, InferGetStaticPropsType } from "astro";
import { siteConfig } from "@/site.config";
// if you're using an adaptor in SSR mode, getStaticPaths wont work -> https://docs.astro.build/en/guides/routing/#modifying-the-slug-example-for-ssr // if you're using an adaptor in SSR mode, getStaticPaths wont work -> https://docs.astro.build/en/guides/routing/#modifying-the-slug-example-for-ssr
export const getStaticPaths = (async () => { export const getStaticPaths = (async () => {
@ -20,7 +21,8 @@ const { note } = Astro.props;
const meta = { const meta = {
description: description:
note.data.description || `Read about my note posted on: ${note.data.date.toLocaleDateString()}`, note.data.description ||
`Read about my note posted on ${siteConfig.title} (${siteConfig.description}) at ${note.data.date.toLocaleDateString()} by ${siteConfig.author}`,
title: note.data.title, title: note.data.title,
tags: note.data.tags.join(", "), tags: note.data.tags.join(", "),
}; };