Skip to content

Commit 374c519

Browse files
AFOJbabblebey
andauthored
fix: invalid hook call and analytic measurement_id error (#114)
### Description This PR will: - Fix the `MEASUREMENT_ID` variable not being recognised in the base layout (It was logging an error in the browser). - Fix the "Invalid hook call" issue that occurred when starting the dev server. ### Related Issue Fixes #23 ### Screenshots/Screencasts N/A ### Notes to Reviewer - There's a slight formatting change to the affected file due to to my eslint config (I tried my best to configure it to match the source). - Slightly unrelated to this PR, but I feel it would be better to have the recent word in a row(not sure what to call it exactly) layout (Very rough sketch below). ![IMG_1997](https://github.com/user-attachments/assets/b75cf945-1ac4-4e3f-82b8-4c94b3c401df) --------- Co-authored-by: babblebey <babblebey@gmail.com>
1 parent 57d5bd8 commit 374c519

2 files changed

Lines changed: 34 additions & 30 deletions

File tree

src/components/islands/recent-searches.jsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { $recentSearches } from "../../lib/stores/search.js";
44

55
/**
66
* Recent Searches Component - An Island that displays a user's last 5 searches
7-
*
8-
* @todo implement a default list instead of `null` when no `$recentSearch` is found
7+
*
8+
* @todo implement a default list instead of `null` when no `$recentSearch` is found
99
* @todo implement loading component to avoid flickering UI
1010
*/
1111
export default function RecentSearches() {
@@ -17,16 +17,18 @@ export default function RecentSearches() {
1717

1818
return Object.values(recentSearches).length ? (
1919
<div className="space-y-3 ml-2 mt-4 md:mt-6">
20-
<h2 className="text-2xl md:text-4xl font-black">Recent</h2>
21-
<ol className="space-y-1.5 underline">
20+
<h2 className="text-2xl md:text-4xl font-black">Recent</h2>
21+
<ol className="space-y-1.5 underline">
2222
{Object.values(recentSearches).slice(0, 5).map((item, i) => (
2323
<li key={i}>
2424
<a href={item.url}>
2525
{ item.word }
2626
</a>
2727
</li>
2828
))}
29-
</ol>
30-
</div>
31-
) : null;
29+
</ol>
30+
</div>
31+
) : (
32+
<></>
33+
);
3234
}

src/layouts/base.astro

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import { SITE_META_KEYWORDS, SITE_META_DESCRIPTION } from "../../constants.js";
77
const MEASUREMENT_ID = import.meta.env.PUBLIC_GOOGLE_ANALYTICS_MEASUREMENT_ID;
88
99
const { props, url } = Astro;
10-
const {
11-
pageTitle,
12-
class:list,
13-
ogImageUrl = `${url.origin}/og.png`,
10+
const {
11+
pageTitle,
12+
class:list,
13+
ogImageUrl = `${url.origin}/og.png`,
1414
description = SITE_META_DESCRIPTION,
15-
subtitle = "Developer Jargons"
15+
subtitle = "Developer Jargons",
1616
} = props;
1717
---
1818

@@ -25,32 +25,34 @@ const {
2525
<meta name="description" content={description} />
2626
<meta name="keyword" content={SITE_META_KEYWORDS.join(",")} />
2727

28-
<meta property="og:url" content={url.href}>
29-
<meta property="og:type" content="website">
30-
<meta property="og:title" content={`${ pageTitle } - ${subtitle}`}>
31-
<meta property="og:description" content={description}>
32-
<meta property="og:image" content={ogImageUrl}>
28+
<meta property="og:url" content={url.href} />
29+
<meta property="og:type" content="website" />
30+
<meta property="og:title" content={`${pageTitle} - ${subtitle}`} />
31+
<meta property="og:description" content={description} />
32+
<meta property="og:image" content={ogImageUrl} />
3333

34-
<meta name="twitter:card" content="summary_large_image">
35-
<meta property="twitter:domain" content={url.host}>
36-
<meta property="twitter:url" content={url.href}>
37-
<meta name="twitter:title" content={`${ pageTitle } - ${subtitle}`}>
38-
<meta name="twitter:description" content={description}>
39-
<meta name="twitter:image" content={ogImageUrl}>
34+
<meta name="twitter:card" content="summary_large_image" />
35+
<meta property="twitter:domain" content={url.host} />
36+
<meta property="twitter:url" content={url.href} />
37+
<meta name="twitter:title" content={`${pageTitle} - ${subtitle}`} />
38+
<meta name="twitter:description" content={description} />
39+
<meta name="twitter:image" content={ogImageUrl} />
4040

4141
<!-- Google tag (gtag.js) -->
4242
<script async src=`https://www.googletagmanager.com/gtag/js?id=${MEASUREMENT_ID}`></script>
43-
<script>
43+
<script define:vars={{ MEASUREMENT_ID }}>
4444
window.dataLayer = window.dataLayer || [];
45-
function gtag(){dataLayer.push(arguments);}
46-
gtag('js', new Date());
45+
function gtag() {
46+
dataLayer.push(arguments);
47+
}
48+
gtag("js", new Date());
4749

48-
gtag('config', MEASUREMENT_ID);
50+
gtag("config", MEASUREMENT_ID);
4951
</script>
5052

51-
<title>{ pageTitle } - {subtitle}</title>
53+
<title>{pageTitle} - {subtitle}</title>
5254
</head>
5355
<body class={list}>
54-
<slot />
56+
<slot />
5557
</body>
56-
</html>
58+
</html>

0 commit comments

Comments
 (0)