chore: optimize SEO and fix golangci-lint issues
- Implement dynamic SEO meta tags and sitemap.xml for toolbox.pengzhan.dev - Fix SPA title/meta refresh issue in layout.html - Address golangci-lint findings: - Refactor switch-case for tool path and SVG token parsing - Replace math.Pow with direct multiplication for performance - Fix unhandled error returns and unused imports - Omit redundant type declarations
This commit is contained in:
@@ -4,6 +4,24 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{.Title}} | Own-Tools</title>
|
||||
<meta name="description" content="{{.Description}}">
|
||||
<meta name="keywords" content="{{.Keywords}}">
|
||||
<link rel="canonical" href="{{.CanonicalURL}}">
|
||||
|
||||
<!-- Open Graph / Facebook -->
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:url" content="{{.CanonicalURL}}">
|
||||
<meta property="og:title" content="{{.Title}} | Own-Tools">
|
||||
<meta property="og:description" content="{{.Description}}">
|
||||
<meta property="og:image" content="/static/og-image.png">
|
||||
|
||||
<!-- Twitter -->
|
||||
<meta property="twitter:card" content="summary_large_image">
|
||||
<meta property="twitter:url" content="{{.CanonicalURL}}">
|
||||
<meta property="twitter:title" content="{{.Title}} | Own-Tools">
|
||||
<meta property="twitter:description" content="{{.Description}}">
|
||||
<meta property="twitter:image" content="/static/og-image.png">
|
||||
|
||||
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🖋️</text></svg>">
|
||||
|
||||
{{if .GA_ID}}
|
||||
@@ -126,10 +144,41 @@
|
||||
renderCurrentPath();
|
||||
}
|
||||
|
||||
const metaConfig = {
|
||||
'welcome': {
|
||||
title: '探索工具箱',
|
||||
desc: '基于 Go 语言构建的模块化个人工具箱,提供汉字字帖生成、数字学习等多种实用生产力工具。',
|
||||
keywords: '个人工具箱, 汉字字帖生成, 书法练习, 数字学习, Own-Tools'
|
||||
},
|
||||
'zitie': {
|
||||
title: '汉字字帖生成器 - 教学方格与步进式分解',
|
||||
desc: '在线生成 2x3 教学方格字帖和 9 列步进式笔顺分解字帖,支持多种书法字体和古风排版。',
|
||||
keywords: '字帖生成, 笔顺分解, 汉字教学, 书法字帖, 练字'
|
||||
},
|
||||
'learn-number': {
|
||||
title: '趣味数字学习工具',
|
||||
desc: '为儿童设计的数字学习与计数练习工具,生动活泼,寓教于乐。',
|
||||
keywords: '数字学习, 儿童计数, 幼小衔接'
|
||||
}
|
||||
};
|
||||
|
||||
function renderCurrentPath() {
|
||||
const path = window.location.pathname.replace('/', '') || 'welcome';
|
||||
|
||||
// 隐藏所有面板
|
||||
// 1. 更新标题与元数据
|
||||
const meta = metaConfig[path] || metaConfig['welcome'];
|
||||
document.title = `${meta.title} | Own-Tools`;
|
||||
document.querySelector('meta[name="description"]').setAttribute('content', meta.desc);
|
||||
document.querySelector('meta[name="keywords"]').setAttribute('content', meta.keywords);
|
||||
|
||||
// 更新 Open Graph 标签 (可选,社交分享主要看服务端渲染)
|
||||
const canonical = `https://toolbox.pengzhan.dev/${path === 'welcome' ? '' : path}`;
|
||||
document.querySelector('link[rel="canonical"]').setAttribute('href', canonical);
|
||||
document.querySelector('meta[property="og:title"]').setAttribute('content', `${meta.title} | Own-Tools`);
|
||||
document.querySelector('meta[property="og:description"]').setAttribute('content', meta.desc);
|
||||
document.querySelector('meta[property="og:url"]').setAttribute('content', canonical);
|
||||
|
||||
// 2. 隐藏所有面板
|
||||
document.querySelectorAll('.tool-panel').forEach(p => p.classList.remove('active'));
|
||||
|
||||
// 显示目标面板
|
||||
|
||||
Reference in New Issue
Block a user