首次提交:初始化项目代码

This commit is contained in:
sunct
2026-07-31 14:44:48 +08:00
commit a4fe393571
119 changed files with 29105 additions and 0 deletions
+847
View File
@@ -0,0 +1,847 @@
{{ define "web/portfolio" }}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>项目作品集 - {{.Resume.BasicInfo.Name}}</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@11.8.0/styles/github.min.css">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
background: #f5f7fa;
min-height: 100vh;
line-height: 1.65;
}
.nav-bar {
background: white;
border-bottom: 0.06rem solid #e8ecef;
padding: 0.88rem 1.25rem;
position: sticky;
top: 0;
z-index: 1000;
box-shadow: 0 0.06rem 0.19rem rgba(0,0,0,0.04);
}
.nav-bar .nav-content {
max-width: 75rem;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: space-between;
}
.nav-bar .back-link {
color: #3498db;
text-decoration: none;
font-size: 0.95em;
display: flex;
align-items: center;
gap: 0.38rem;
transition: all 0.3s ease;
}
.nav-bar .back-link:hover {
color: #2980b9;
gap: 0.62rem;
}
.nav-bar .nav-title {
font-size: 1.15em;
font-weight: 600;
color: #2c3e50;
display: flex;
align-items: center;
gap: 0.50rem;
}
.nav-bar .nav-title i {
color: #3498db;
}
.search-bar {
background: white;
border-bottom: 0.06rem solid #e8ecef;
padding: 0.75rem 1.25rem;
position: sticky;
top: 3.75rem;
z-index: 999;
box-shadow: 0 0.06rem 0.19rem rgba(0,0,0,0.04);
}
.search-bar .search-content {
max-width: 75rem;
margin: 0 auto;
display: flex;
gap: 0.94rem;
align-items: center;
flex-wrap: wrap;
}
.search-input-wrapper {
flex: 1;
min-width: 15.62rem;
max-width: 25rem;
position: relative;
display: flex;
align-items: center;
}
.search-input-wrapper i {
position: absolute;
left: 0.75rem;
color: #999;
font-size: 0.9em;
}
.search-input-wrapper input {
width: 100%;
padding: 0.62rem 2.50rem 0.62rem 2.19rem;
border: 0.06rem solid #e8ecef;
border-radius: 0.38rem;
font-size: 0.95em;
transition: all 0.2s;
font-family: inherit;
}
.search-input-wrapper input:focus {
outline: none;
border-color: #3498db;
box-shadow: 0 0 0 0.19rem rgba(52,152,219,0.1);
}
.clear-btn {
position: absolute;
right: 0.75rem;
background: none;
border: none;
color: #999;
cursor: pointer;
padding: 0.25rem;
transition: color 0.2s;
}
.clear-btn:hover {
color: #333;
}
.filter-tags {
display: flex;
flex-wrap: wrap;
gap: 0.50rem;
}
.filter-tag {
padding: 0.38rem 0.75rem;
background: #f0f4f8;
color: #555;
border-radius: 0.25rem;
font-size: 0.85em;
cursor: pointer;
transition: all 0.2s;
border: 0.06rem solid #e8ecef;
display: flex;
align-items: center;
gap: 0.38rem;
}
.filter-tag:hover {
background: #e8f4fd;
color: #3498db;
border-color: #d5eaf9;
}
.filter-tag.active {
background: #3498db;
color: white;
border-color: #3498db;
}
.portfolio-container {
max-width: 75rem;
margin: 0 auto;
display: flex;
min-height: calc(100vh - 3.75rem);
}
.project-sidebar {
width: 17.50rem;
background: white;
border-right: 0.06rem solid #e8ecef;
padding: 1.50rem 0;
position: sticky;
top: 3.75rem;
height: calc(100vh - 3.75rem);
overflow-y: auto;
}
.project-sidebar .sidebar-header {
padding: 0 1.25rem 1rem;
border-bottom: 0.06rem solid #f0f2f5;
margin-bottom: 0.75rem;
}
.project-sidebar .sidebar-header h3 {
font-size: 0.88em;
font-weight: 600;
color: #888;
text-transform: uppercase;
letter-spacing: 0.03rem;
}
.project-sidebar .project-list {
list-style: none;
padding: 0;
}
.project-sidebar .project-list li {
margin-bottom: 0.25rem;
}
.project-sidebar .project-list li a {
display: flex;
align-items: center;
padding: 0.75rem 1.25rem;
color: #444;
text-decoration: none;
transition: all 0.25s ease;
border-left: 0.19rem solid transparent;
gap: 0.62rem;
}
.project-sidebar .project-list li a:hover {
background: #f8fbfe;
color: #3498db;
}
.project-sidebar .project-list li a.active {
background: #e8f4fd;
color: #3498db;
border-left-color: #3498db;
}
.project-sidebar .project-list li a i {
font-size: 0.85em;
flex-shrink: 0;
}
.project-sidebar .project-list li a .project-name {
font-size: 0.92em;
font-weight: 500;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.project-sidebar .project-list li a .project-date {
font-size: 0.78em;
color: #999;
margin-top: 0.12rem;
}
.project-main {
flex: 1;
background: white;
padding: 2rem;
overflow-y: auto;
}
.project-main .project-header {
margin-bottom: 2rem;
padding-bottom: 1.25rem;
border-bottom: 0.12rem solid #3498db;
}
.project-main .project-header h1 {
font-size: 1.7em;
font-weight: 700;
color: #2c3e50;
margin-bottom: 0.50rem;
}
.project-main .project-header .project-meta {
display: flex;
flex-wrap: wrap;
gap: 1rem;
font-size: 0.92em;
color: #666;
}
.project-main .project-header .project-meta span {
display: flex;
align-items: center;
gap: 0.38rem;
}
.project-main .project-header .project-meta i {
color: #3498db;
font-size: 0.85em;
}
.project-main .project-header .tech-stack {
display: flex;
flex-wrap: wrap;
gap: 0.38rem;
margin-top: 0.75rem;
}
.project-main .project-header .tech-tag {
padding: 0.25rem 0.62rem;
background: #e8f4fd;
color: #3498db;
border-radius: 0.19rem;
font-size: 0.82em;
border: 0.06rem solid #d5eaf9;
}
.project-main .doc-content {
color: #333;
font-size: 0.98em;
}
.doc-content h2 {
font-size: 1.4em;
font-weight: 600;
color: #2c3e50;
margin: 1.75rem 0 1rem;
padding-bottom: 0.62rem;
border-bottom: 0.06rem solid #e8ecef;
}
.doc-content h3 {
font-size: 1.2em;
font-weight: 600;
color: #34495e;
margin: 1.38rem 0 0.75rem;
}
.doc-content h4 {
font-size: 1.05em;
font-weight: 600;
color: #4a5568;
margin: 1.12rem 0 0.62rem;
}
.doc-content p {
margin-bottom: 0.88rem;
line-height: 1.75;
color: #444;
}
.doc-content ul, .doc-content ol {
margin-bottom: 0.88rem;
padding-left: 1.50rem;
}
.doc-content li {
margin-bottom: 0.38rem;
color: #444;
}
.doc-content blockquote {
border-left: 0.19rem solid #3498db;
padding: 0.88rem 1.25rem;
margin: 1.12rem 0;
background: #f8fbfe;
color: #555;
border-radius: 0 0.25rem 0.25rem 0;
font-style: italic;
}
.doc-content pre {
background: #2d2d2d;
color: #ccc;
padding: 1.12rem 1.38rem;
border-radius: 0.38rem;
overflow-x: auto;
margin: 1.12rem 0;
font-size: 0.88em;
line-height: 1.6;
}
.doc-content pre code {
background: none;
padding: 0;
color: inherit;
}
.doc-content code {
background: #f4f6f8;
padding: 0.12rem 0.38rem;
border-radius: 0.19rem;
font-size: 0.9em;
color: #e74c3c;
font-family: 'Fira Code', 'Monaco', monospace;
}
.doc-content table {
width: 100%;
border-collapse: collapse;
margin: 1.12rem 0;
font-size: 0.92em;
}
.doc-content th, .doc-content td {
border: 0.06rem solid #e8ecef;
padding: 0.75rem 1rem;
text-align: left;
}
.doc-content th {
background: #f8fafc;
font-weight: 600;
color: #2c3e50;
}
.doc-content tr:nth-child(even) {
background: #fafbfc;
}
.doc-content img {
max-width: 100%;
border-radius: 0.38rem;
margin: 0.88rem 0;
box-shadow: 0 0.12rem 0.62rem rgba(0,0,0,0.08);
}
.doc-content a {
color: #3498db;
text-decoration: none;
position: relative;
}
.doc-content a::after {
content: '';
position: absolute;
width: 0;
height: 0.06rem;
bottom: -0.06rem;
left: 0;
background: #3498db;
transition: width 0.3s ease;
}
.doc-content a:hover::after {
width: 100%;
}
.doc-content hr {
border: none;
border-top: 0.06rem solid #e8ecef;
margin: 1.75rem 0;
}
.mermaid {
margin: 1.12rem 0;
text-align: center;
}
.mermaid svg {
max-width: 100%;
height: auto;
}
.no-doc {
text-align: center;
padding: 5rem 1.25rem;
color: #888;
}
.no-doc i {
font-size: 4em;
margin-bottom: 1.25rem;
opacity: 0.4;
color: #3498db;
}
.no-doc h3 {
font-size: 1.2em;
font-weight: 500;
margin-bottom: 0.50rem;
color: #555;
}
.no-doc p {
font-size: 0.95em;
color: #999;
}
@media (max-width: 56.25rem) {
.portfolio-container {
flex-direction: column;
}
.project-sidebar {
width: 100%;
border-right: none;
border-bottom: 0.06rem solid #e8ecef;
position: relative;
top: auto;
height: auto;
max-height: 18.75rem;
}
.project-main {
padding: 1.50rem 1.25rem;
}
}
@media (max-width: 48rem) {
.nav-bar {
padding: 0.75rem 0.94rem;
}
.nav-bar .nav-title {
font-size: 1em;
}
.project-sidebar {
padding: 1.12rem 0;
}
.project-sidebar .sidebar-header {
padding: 0 0.94rem 0.75rem;
}
.project-sidebar .project-list li a {
padding: 0.62rem 0.94rem;
}
.project-main {
padding: 1.25rem 0.94rem;
}
.project-main .project-header h1 {
font-size: 1.4em;
}
.project-main .project-header .project-meta {
gap: 0.62rem;
font-size: 0.88em;
}
.doc-content h2 {
font-size: 1.2em;
}
.doc-content h3 {
font-size: 1.05em;
}
.doc-content pre {
padding: 0.75rem;
font-size: 0.8em;
}
}
@media print {
body { background: white; }
.nav-bar { display: none; }
.portfolio-container {
flex-direction: column;
margin: 0;
}
.project-sidebar {
display: none;
}
.project-main {
padding: 0;
box-shadow: none;
}
a { color: #3498db; text-decoration: underline; }
@page { margin: 15mm; }
}
</style>
</head>
<body>
<nav class="nav-bar">
<div class="nav-content">
<a href="/" class="back-link">
<i class="fas fa-arrow-left"></i> 返回简历
</a>
<span class="nav-title">
<i class="fas fa-folder-open"></i> 项目作品集
</span>
</div>
</nav>
<div class="search-bar">
<div class="search-content">
<div class="search-input-wrapper">
<i class="fas fa-search"></i>
<input type="text" id="searchInput" placeholder="搜索项目名称、描述或技术栈..." oninput="handleSearch()">
<button class="clear-btn" id="clearSearch" onclick="clearSearch()" style="display:none;">
<i class="fas fa-times"></i>
</button>
</div>
<div class="filter-tags" id="filterTags">
</div>
</div>
</div>
<div class="portfolio-container">
<aside class="project-sidebar">
<div class="sidebar-header">
<h3>项目列表</h3>
</div>
<ul class="project-list" id="projectList">
</ul>
</aside>
<main class="project-main" id="projectContent">
</main>
</div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/highlight.js@11.8.0/lib/highlight.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dompurify@3/dist/purify.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
<script>
mermaid.initialize({
startOnLoad: false,
theme: 'default',
flowchart: { htmlLabels: false },
graph: { htmlLabels: false }
});
let allProjects = [];
let currentFilter = '';
let currentSearch = '';
function handleSearch() {
const input = document.getElementById('searchInput');
const clearBtn = document.getElementById('clearSearch');
currentSearch = input.value.toLowerCase().trim();
if (currentSearch) {
clearBtn.style.display = 'block';
} else {
clearBtn.style.display = 'none';
}
filterProjects();
}
function clearSearch() {
const input = document.getElementById('searchInput');
input.value = '';
currentSearch = '';
document.getElementById('clearSearch').style.display = 'none';
filterProjects();
}
function toggleFilter(tag) {
const filterTags = document.querySelectorAll('.filter-tag');
filterTags.forEach(el => {
if (el.dataset.tag === tag) {
el.classList.toggle('active');
if (el.classList.contains('active')) {
currentFilter = tag;
} else {
currentFilter = '';
}
} else {
el.classList.remove('active');
}
});
filterProjects();
}
function filterProjects() {
if (allProjects.length === 0) return;
let filtered = allProjects;
if (currentSearch) {
filtered = filtered.filter(p => {
const name = (p.name || '').toLowerCase();
const desc = (p.description || '').toLowerCase();
const tech = (p.tech_stack || []).join(' ').toLowerCase();
return name.includes(currentSearch) || desc.includes(currentSearch) || tech.includes(currentSearch);
});
}
if (currentFilter) {
filtered = filtered.filter(p => {
const tech = (p.tech_stack || []);
return tech.includes(currentFilter);
});
}
renderProjectList(filtered);
if (filtered.length > 0) {
renderProject(filtered[0], 0);
} else {
document.getElementById('projectContent').innerHTML = '<div class="no-doc"><i class="fas fa-search"></i><h3>未找到匹配的项目</h3><p>尝试调整搜索关键词或筛选条件</p></div>';
}
}
function renderFilterTags() {
const tagContainer = document.getElementById('filterTags');
if (!tagContainer) return;
const techSet = new Set();
allProjects.forEach(p => {
(p.tech_stack || []).forEach(t => techSet.add(t));
});
const tags = Array.from(techSet).slice(0, 6);
if (tags.length === 0) {
tagContainer.innerHTML = '';
return;
}
tagContainer.innerHTML = tags.map(tag =>
`<span class="filter-tag" data-tag="${tag}" onclick="toggleFilter('${tag}')">
<i class="fas fa-tag"></i> ${tag}
</span>`
).join('');
}
async function renderMarkdown(markdown) {
const mermaidBlocks = [];
const processed = markdown.replace(/```mermaid\s*([\s\S]*?)```/g, function(match, content) {
const id = 'mermaid-' + Date.now() + '-' + mermaidBlocks.length;
mermaidBlocks.push({ id: id, content: content.trim() });
return '<div id="' + id + '" class="mermaid"></div>';
});
const html = DOMPurify.sanitize(marked.parse(processed), {
ADD_TAGS: ['iframe'],
ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling']
});
const container = document.createElement('div');
container.innerHTML = html;
if (typeof hljs !== 'undefined') {
container.querySelectorAll('pre code').forEach(function(block) {
hljs.highlightElement(block);
});
}
await Promise.all(mermaidBlocks.map(async function(block) {
const el = container.querySelector('#' + block.id);
if (el) {
try {
const result = await mermaid.render(block.id, block.content);
el.innerHTML = result.svg;
} catch (e) {
el.innerHTML = '<div style="color: #e74c3c; padding: 0.62rem; background: #fef5f5; border-radius: 0.25rem;">' + e.message + '</div>';
}
}
}));
return container.innerHTML;
}
async function loadProjects() {
const response = await fetch('/api/portfolio');
const projects = await response.json();
allProjects = projects;
renderFilterTags();
renderProjectList(projects);
if (projects.length > 0) {
renderProject(projects[0], 0);
} else {
document.getElementById('projectContent').innerHTML = '<div class="no-doc"><i class="fas fa-folder-open"></i><h3>暂无项目</h3><p>还没有添加任何作品集项目</p></div>';
}
}
function renderProjectList(projects) {
const list = document.getElementById('projectList');
list.innerHTML = '';
projects.forEach(function(project, index) {
const li = document.createElement('li');
const a = document.createElement('a');
a.href = '#';
a.onclick = function(e) {
e.preventDefault();
selectProject(index);
};
const icon = document.createElement('i');
icon.className = 'fas fa-file-code';
const info = document.createElement('div');
info.innerHTML = '<div class="project-name">' + (project.name || '未命名项目') + '</div>' + (project.start_date ? '<div class="project-date">' + project.start_date + ' - ' + (project.end_date || '至今') + '</div>' : '');
a.appendChild(icon);
a.appendChild(info);
li.appendChild(a);
list.appendChild(li);
});
}
function selectProject(index) {
const links = document.querySelectorAll('.project-list li a');
links.forEach(function(link, i) {
if (i === index) {
link.classList.add('active');
} else {
link.classList.remove('active');
}
});
let projects = allProjects;
if (currentSearch || currentFilter) {
projects = projects.filter(p => {
const matchSearch = !currentSearch ||
(p.name || '').toLowerCase().includes(currentSearch) ||
(p.description || '').toLowerCase().includes(currentSearch) ||
(p.tech_stack || []).join(' ').toLowerCase().includes(currentSearch);
const matchFilter = !currentFilter || (p.tech_stack || []).includes(currentFilter);
return matchSearch && matchFilter;
});
}
if (projects[index]) {
renderProject(projects[index], index);
}
}
async function renderProject(project, index) {
const content = document.getElementById('projectContent');
content.innerHTML = '<div style="text-align:center;padding:2.50rem;"><i class="fas fa-spinner fa-spin fa-2x"></i></div>';
const header = '<div class="project-header">' +
'<h1>' + (project.name || '未命名项目') + '</h1>' +
'<div class="project-meta">' +
(project.start_date ? '<span><i class="fas fa-calendar"></i> ' + project.start_date + ' - ' + (project.end_date || '至今') + '</span>' : '') +
(project.url ? '<span><i class="fas fa-external-link-alt"></i> <a href="' + project.url + '" target="_blank">项目链接</a></span>' : '') +
'</div>' +
(project.tech_stack && project.tech_stack.length ? '<div class="tech-stack">' + project.tech_stack.map(function(t) { return '<span class="tech-tag">' + t + '</span>'; }).join('') + '</div>' : '') +
'</div>';
var docHtml = '';
if (project.doc && project.doc.trim()) {
docHtml = '<div class="doc-content" id="doc-' + index + '"></div>';
} else {
docHtml = '<div class="no-doc"><i class="fas fa-file"></i><h3>该项目暂无详细文档</h3><p>点击左侧项目切换,或在后台添加项目文档</p></div>';
}
content.innerHTML = header + docHtml;
if (project.doc && project.doc.trim()) {
const docDiv = document.getElementById('doc-' + index);
if (docDiv) {
docDiv.innerHTML = await renderMarkdown(project.doc);
}
}
}
document.addEventListener('DOMContentLoaded', loadProjects);
</script>
</body>
</html>
{{ end }}