diff --git a/components/DataUpdateDisplay.js b/components/DataUpdateDisplay.js new file mode 100644 index 0000000..6bba201 --- /dev/null +++ b/components/DataUpdateDisplay.js @@ -0,0 +1,14 @@ +// components/DataUpdateDisplay.js +import React from 'react'; + +const DataUpdateDisplay = ({ lastFetched }) => { + const formattedDate = new Date(lastFetched).toLocaleString(); + + return ( +
+ 数据更新时间:{formattedDate} +
+ ); +}; + +export default DataUpdateDisplay; \ No newline at end of file diff --git a/components/Footer.js b/components/Footer.js index da1d6ab..d474aa9 100644 --- a/components/Footer.js +++ b/components/Footer.js @@ -1,10 +1,40 @@ +import { useEffect, useState } from 'react'; + // components/Footer.js const Footer = () => { + const [visitCount, setVisitCount] = useState(null); + + useEffect(() => { + // 调用 API 获取访问量 + const fetchVisitCount = async () => { + try { + const response = await fetch('/api/visit-count'); + const data = await response.json(); + setVisitCount(data.count); + } catch (error) { + console.error('获取访问量失败:', error); + } + }; + + fetchVisitCount(); + }, []); + return ( -

- Copyright © 2021 - NowScott -

- ) +
+ + 投稿网页 + + {visitCount !== null && ( +

访问量:{visitCount}

+ )} +

Copyright © 2021 - NowScott

+
+ ); }; export default Footer; \ No newline at end of file diff --git a/components/Titles.js b/components/Titles.js index 903ef16..d060754 100644 --- a/components/Titles.js +++ b/components/Titles.js @@ -11,16 +11,6 @@ const Titles = () => ( Individual Web Index. -
- - 如何部署 - -
); diff --git a/package.json b/package.json index 28a3695..64e8f73 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ind-web-index", - "version": "2.2.3", + "version": "2.2.4", "scripts": { "dev": "next dev", "build": "next build", diff --git a/pages/mainPage.js b/pages/mainPage.js index 170562a..a5074c8 100644 --- a/pages/mainPage.js +++ b/pages/mainPage.js @@ -6,6 +6,7 @@ import Tags from '../components/Tags'; import WebList from '../components/WebList'; import Footer from '../components/Footer'; import FontMenu from '../components/FontMenu'; +import DataUpdateDisplay from '../components/DataUpdateDisplay'; import { randomSort, unique, extractTags, filterPostsBySearch, toggleTagButton, updateResults } from '../lib/dataLoader'; const MainPage = ({ initialPosts, lastFetched }) => { @@ -16,27 +17,10 @@ const MainPage = ({ initialPosts, lastFetched }) => { const [tags, setTags] = useState([]); const [onList, setOnList] = useState([]); const [filteredPosts, setFilteredPosts] = useState(initialPosts || []); - const [visitCount, setVisitCount] = useState(null); useEffect(() => { - console.log(`数据更新时间: ${new Date(lastFetched).toLocaleString()}`); setPosts(initialPosts || []); - - fetch('/api/visit-count') - .then(response => response.json()) - .then(data => { - if (data.count) { - console.log(`本页面已被访问 ${data.count} 次`); - setVisitCount(data.count); - } else { - console.log('访问计数数据不可用:', data.message); - } - }) - .catch(error => { - console.error('Error fetching visit count:', error); - }); - - }, [initialPosts, lastFetched]); + }, [initialPosts]); useEffect(() => { const filteredNormalPosts = (initialPosts || []).filter(post => post.state !== '隐藏'); @@ -68,8 +52,15 @@ const MainPage = ({ initialPosts, lastFetched }) => { return (
+
+ + 数据更新时间:{new Date(lastFetched).toLocaleString()} + +
+ +
+
-