// 关于页面JavaScript功能 - 现代动态版本 $(document).ready(function() { // 初始化所有功能 initGitHubStats(); initBlogArticles(); initVisitorStats(); initArtalkComments(); initPageAnimations(); initTechCloud(); initScrollEffects(); }); // GitHub 统计信息 function initGitHubStats() { const username = 'listener-He'; // 替换为实际的GitHub用户名 // 获取用户基本信息 fetch(`https://api.github.com/users/${username}`) .then(response => response.json()) .then(data => { const profileHtml = `
${data.name}

${data.name || data.login}

${data.bio || '暂无简介'}

${data.public_repos} 仓库
${data.followers} 关注者
${data.following} 关注
`; $('#github-profile').html(profileHtml); }) .catch(error => { console.error('获取GitHub用户信息失败:', error); $('#github-profile').html('
加载GitHub信息失败
'); }); // 获取提交统计(使用GitHub API的限制,这里模拟数据) const commitsHtml = `

提交统计

本周
24
本月
156
今年
1,247
`; $('#github-commits').html(commitsHtml); } // 优质项目展示 function initProjects() { const username = 'listener-He'; fetch(`https://api.github.com/users/${username}/repos?sort=stars&per_page=6`) .then(response => response.json()) .then(repos => { const projectsHtml = repos.map(repo => { const languages = repo.language ? [repo.language] : []; return `

${repo.name}

${repo.description || '暂无描述'}

${repo.stargazers_count} ${repo.forks_count}
${languages.map(lang => `${lang}`).join('')}
更新于 ${new Date(repo.updated_at).toLocaleDateString('zh-CN')}
`; }).join(''); $('#projects-container').html(projectsHtml); }) .catch(error => { console.error('获取GitHub项目失败:', error); $('#projects-container').html('
加载项目信息失败
'); }); } // 博客文章RSS解析 function initBlogArticles() { const rssUrl = 'https://blog.hehouhui.cn/rss/feed.xml'; const cacheKey = 'blog_articles_cache'; const cacheTimeKey = 'blog_articles_cache_time'; // 检查缓存 const cachedData = localStorage.getItem(cacheKey); const cacheTime = localStorage.getItem(cacheTimeKey); const today = new Date().toDateString(); if (cachedData && cacheTime === today) { // 使用缓存数据 displayBlogArticles(JSON.parse(cachedData)); return; } // 清除过期缓存并重新获取 localStorage.removeItem(cacheKey); localStorage.removeItem(cacheTimeKey); // 使用代理服务获取RSS数据 const proxyUrl = `https://api.allorigins.win/get?url=${encodeURIComponent(rssUrl)}`; fetch(proxyUrl) .then(response => response.json()) .then(data => { const parser = new DOMParser(); const xmlDoc = parser.parseFromString(data.contents, 'text/xml'); const items = xmlDoc.querySelectorAll('item'); const articles = Array.from(items).slice(0, 6).map(item => { const title = item.querySelector('title')?.textContent || ''; const link = item.querySelector('link')?.textContent || ''; const description = item.querySelector('description')?.textContent || ''; const pubDate = item.querySelector('pubDate')?.textContent || ''; const category = item.querySelector('category')?.textContent || '技术分享'; // 提取摘要(去除HTML标签) const excerpt = description.replace(/<[^>]*>/g, '').substring(0, 150) + '...'; return { title, excerpt, link, pubDate: new Date(pubDate).toLocaleDateString('zh-CN'), category }; }); // 缓存数据 localStorage.setItem(cacheKey, JSON.stringify(articles)); localStorage.setItem(cacheTimeKey, today); displayBlogArticles(articles); }) .catch(error => { console.error('获取RSS数据失败:', error); // 降级到模拟数据 const fallbackArticles = [ { title: "向量数据库全攻略:从算法公式到选型指南,一篇吃透高维数据存储术", excerpt: "深入探讨向量数据库的核心算法、应用场景和选型策略,帮助开发者掌握高维数据存储的关键技术...", link: "https://blog.hehouhui.cn/posts/vector-database-guide", pubDate: "2025-01-02", category: "技术分享" }, { title: "CompletableFuture 从源码到实战:让异步编程像喝奶茶一样丝滑", excerpt: "全面解析CompletableFuture的源码实现和实战应用,让Java异步编程变得简单优雅...", link: "https://blog.hehouhui.cn/posts/completablefuture-guide", pubDate: "2025-01-02", category: "Java开发" }, { title: "从规范到架构:一篇读懂 Java 工程建模、分层、命名与演进之路", excerpt: "深入讲解Java工程的规范化建设,包括项目结构、分层架构、命名规范等最佳实践...", link: "https://blog.hehouhui.cn/posts/java-project-architecture", pubDate: "2025-01-01", category: "架构设计" } ]; displayBlogArticles(fallbackArticles); }); } function displayBlogArticles(articles) { const articlesHtml = articles.map(article => `

${article.title}

${article.excerpt}

`).join(''); $('#blog-container').html(articlesHtml); } // 访问统计(百度统计集成) function initVisitorStats() { // 这里需要集成百度统计API // 由于百度统计API需要认证,这里使用模拟数据 const mockStats = { totalVisitors: 12580, totalVisits: 25640, todayVisitors: 156, todayVisits: 234 }; // 动画显示数字 animateNumber('#total-visitors', mockStats.totalVisitors); animateNumber('#total-visits', mockStats.totalVisits); animateNumber('#today-visitors', mockStats.todayVisitors); animateNumber('#today-visits', mockStats.todayVisits); } // 数字动画效果 function animateNumber(selector, targetNumber) { const element = $(selector); const duration = 2000; const steps = 60; const increment = targetNumber / steps; let current = 0; const timer = setInterval(() => { current += increment; if (current >= targetNumber) { current = targetNumber; clearInterval(timer); } element.text(Math.floor(current).toLocaleString()); }, duration / steps); } // 评论系统初始化 function initArtalkComments() { // 初始化 Artalk 评论系统 if (typeof Artalk !== 'undefined') { const artalk = Artalk.init({ el: '#artalk-container', pageKey: window.location.pathname, pageTitle: document.title, server: 'https://your-artalk-server.com', // 替换为实际的Artalk服务器地址 site: 'Honesty的主页', placeholder: '来说点什么吧...', noComment: '暂无评论', sendBtn: '发送', darkMode: false, gravatar: { mirror: 'https://cravatar.cn/avatar/' }, pagination: { pageSize: 20, readMore: true, autoLoad: true }, heightLimit: { content: 300, children: 400 }, imgUpload: false, preview: true, versionCheck: true }); // 自定义样式 setTimeout(() => { const atkMain = document.querySelector('.atk-main'); if (atkMain) { atkMain.style.borderRadius = '15px'; atkMain.style.overflow = 'hidden'; } }, 1000); } } // 技术云图初始化 function initTechCloud() { const techItems = [ // 内层轨道 - 核心技能 { name: 'JavaScript', level: 'primary', orbit: 1 }, { name: 'Python', level: 'primary', orbit: 1 }, { name: 'React', level: 'primary', orbit: 1 }, // 中层轨道 - 熟练技能 { name: 'Node.js', level: 'secondary', orbit: 2 }, { name: 'Vue.js', level: 'secondary', orbit: 2 }, { name: 'TypeScript', level: 'secondary', orbit: 2 }, { name: 'MySQL', level: 'secondary', orbit: 2 }, // 外层轨道 - 工具技能 { name: 'Docker', level: 'tertiary', orbit: 3 }, { name: 'Git', level: 'tertiary', orbit: 3 }, { name: 'Linux', level: 'tertiary', orbit: 3 }, { name: 'AWS', level: 'tertiary', orbit: 3 }, { name: 'MongoDB', level: 'tertiary', orbit: 3 }, { name: 'Redis', level: 'tertiary', orbit: 3 } ]; // 动态生成技术项目 techItems.forEach((tech, index) => { const orbit = $(`.orbit-${tech.orbit}`); const techElement = $(`
${tech.name}
`); orbit.append(techElement); }); } // 滚动效果 function initScrollEffects() { // 导航栏滚动效果 let lastScrollTop = 0; $(window).scroll(function() { const scrollTop = $(this).scrollTop(); const navbar = $('.navbar'); // 添加滚动样式 if (scrollTop > 50) { navbar.addClass('scrolled'); } else { navbar.removeClass('scrolled'); } // 隐藏/显示导航栏 if (scrollTop > lastScrollTop && scrollTop > 100) { navbar.css('transform', 'translateY(-100%)'); } else { navbar.css('transform', 'translateY(0)'); } lastScrollTop = scrollTop; }); } // 页面动画效果 function initPageAnimations() { // 滚动显示动画 const observerOptions = { threshold: 0.1, rootMargin: '0px 0px -50px 0px' }; const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.style.opacity = '1'; entry.target.style.transform = 'translateY(0)'; entry.target.classList.add('animate-in'); } }); }, observerOptions); // 观察所有区域 document.querySelectorAll('.hero-section, .tech-cloud-section, .personality-timeline-section, .github-showcase-section, .blog-waterfall-section, .contact-floating-section, .comments-section').forEach(section => { section.style.opacity = '0'; section.style.transform = 'translateY(50px)'; section.style.transition = 'opacity 0.8s ease, transform 0.8s ease'; observer.observe(section); }); // 数字动画 function animateNumbers() { $('.stat-number').each(function() { const $this = $(this); const target = parseInt($this.text().replace(/[^0-9]/g, '')); const duration = 2000; const step = target / (duration / 16); let current = 0; const timer = setInterval(() => { current += step; if (current >= target) { current = target; clearInterval(timer); } $this.text(Math.floor(current).toLocaleString()); }, 16); }); } // 当英雄区域进入视野时开始数字动画 const heroObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { animateNumbers(); heroObserver.unobserve(entry.target); } }); }); const heroSection = document.querySelector('.hero-section'); if (heroSection) { heroObserver.observe(heroSection); } } // 添加GitHub统计的CSS样式 const githubStyles = ` `; // 添加样式到页面 $('head').append(githubStyles); // 错误处理 window.addEventListener('error', function(e) { console.error('页面错误:', e.error); }); // 页面加载完成提示 $(window).on('load', function() { console.log('关于我页面加载完成'); });