diff --git a/src/components/PageViews.tsx b/src/components/PageViews.tsx index 8310217..edb777f 100644 --- a/src/components/PageViews.tsx +++ b/src/components/PageViews.tsx @@ -1,40 +1,36 @@ 'use client' -import { useEffect, useState } from 'react'; +import { useEffect, useState } from 'react' interface PageViewsProps { - slug: string; + slug: string } export default function PageViews({ slug }: PageViewsProps) { - const [views, setViews] = useState(null); + const [views, setViews] = useState(null) - useEffect(() => { - console.log('PageViews component mounted with slug:', slug); - async function updatePageView() { - try { - // First increment the view count - const postResponse = await fetch(`/api/pageview/${slug}`, { - method: 'POST', - }); - if (!postResponse.ok) throw new Error('Failed to increment view count'); - - // Then get the updated count - const { views } = await postResponse.json(); - console.log('Updated views:', views); - setViews(views); - } catch (error) { - console.error('Error updating page views:', error); - setViews(null); - } - } + useEffect(() => { + console.log('PageViews component mounted with slug:', slug) + async function updatePageView() { + try { + // First increment the view count + const postResponse = await fetch(`/api/pageview/${slug}`, { + method: 'POST' + }) + if (!postResponse.ok) throw new Error('Failed to increment view count') - updatePageView(); - }, [slug]); + // Then get the updated count + const { views } = await postResponse.json() + console.log('Updated views:', views) + setViews(views) + } catch (error) { + console.error('Error updating page views:', error) + setViews(null) + } + } - return ( - - Views: {views === null ? '-' : views} - - ); + updatePageView() + }, [slug]) + + return Views: {views === null ? '-' : views} } diff --git a/src/components/layout/Footer.astro b/src/components/layout/Footer.astro index 66d27ff..e2c21bd 100644 --- a/src/components/layout/Footer.astro +++ b/src/components/layout/Footer.astro @@ -3,9 +3,7 @@ import { Icon } from 'astro-icon/components' import PageViews from '../PageViews' const pathname = new URL(Astro.request.url).pathname -const isBlogPost = pathname.startsWith('/blog/') && pathname !== '/blog' const slug = pathname === '/' ? 'home' : pathname.replace(/^\/|\/$/g, '') -console.log('Slug:', slug) ---