Skip to content

Commit

Permalink
Add goatcounter
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-ping committed Jan 2, 2024
1 parent b4292fa commit 8562250
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/layout.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import GoatCounter from '@/components/goatCounter';
import Navbar from '@/components/navbar';
import Footer from '@/components/footer';
import ThemeProvider from '@/components/themeProvider';
Expand Down Expand Up @@ -50,6 +51,7 @@ export default function RootLayout({ children }) {
<main className="flex flex-col flex-grow gap-y-14">{children}</main>
<Footer navbarButtons={NavbarButtons} />
</ThemeProvider>
<GoatCounter />
</body>
</html>
);
Expand Down
26 changes: 26 additions & 0 deletions components/goatCounter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use client';

import { useEffect } from 'react';

import Script from 'next/script';
import { usePathname } from 'next/navigation';

const GoatCounter = () => {
let path = usePathname();

useEffect(() => {
if (window.goatcounter === undefined) return;

window.goatcounter.count({ path });
}, [path]);

return (
<Script
data-goatcounter="https://stats.samuelp.ing/count"
async={true}
src="//gc.zgo.at/count.js"
/>
);
};

export default GoatCounter;
2 changes: 1 addition & 1 deletion components/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Popover, Transition } from '@headlessui/react';
import HamburgerMenuIcon from '@/components/hamburgerMenuIcon';
import Logo from '@/components/logo';
import NavbarButton from '@/components/navbarButton';
import { ThemeToggle } from './themeToggle';
import { ThemeToggle } from '@/components/themeToggle';

export default function Navbar({ navbarButtons }) {
const pathname = usePathname();
Expand Down
3 changes: 2 additions & 1 deletion components/themeToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { useState, useEffect } from 'react';
import { useTheme } from 'next-themes';
import { MoonIcon, SunIcon } from './icons';

import { MoonIcon, SunIcon } from '@/components/icons';

export const ThemeToggle = () => {
const [mounted, setMounted] = useState(false);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "samuelp.ing",
"version": "4.0.0",
"version": "4",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down

0 comments on commit 8562250

Please sign in to comment.