- 新增内容页外壳 base_content.html 与 reading.css / reading.js - 重写 post_detail.html:分类胶囊、阅读进度、首字下沉、代码块复制、 侧栏目录、上下篇、图片灯箱、明暗主题 - post_detail 视图补充上下篇、字数与阅读时长 - base.html 补 extra_css / extra_js block,修复脑图详情页样式不加载 - 加入 mindmaps、api、首页静态资源与模板 - 忽略 __pycache__ / *.pyc / *.back,并将已跟踪的 .pyc 移出版本库
148 lines
3.6 KiB
HTML
148 lines
3.6 KiB
HTML
{% extends "base.html" %}
|
|
|
|
{% block title %}{{ mindmap.title }}{% endblock %}
|
|
|
|
{% block extra_css %}
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/simple-mind-map@0.10.0/dist/style.css" />
|
|
<style>
|
|
#mindmap-wrapper {
|
|
position: relative;
|
|
margin-top: 1.5rem;
|
|
width: 100vw;
|
|
margin-left: calc(-50vw + 50%);
|
|
}
|
|
#mindmap-container {
|
|
width: 100% !important;
|
|
height: 90vh !important;
|
|
min-height: 700px !important;
|
|
border: 1px solid #e0e0e0;
|
|
border-radius: 6px;
|
|
display: block !important;
|
|
position: relative;
|
|
overflow: hidden;
|
|
background: #fff;
|
|
}
|
|
|
|
#mindmap-container svg {
|
|
width: 100% !important;
|
|
height: 100% !important;
|
|
}
|
|
|
|
#fullscreen-btn {
|
|
position: absolute;
|
|
top: 10px;
|
|
right: 10px;
|
|
z-index: 100;
|
|
padding: 6px 14px;
|
|
background: #333;
|
|
color: #fff;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 13px;
|
|
font-family: -apple-system, "Noto Sans SC", sans-serif;
|
|
}
|
|
|
|
#fullscreen-btn:hover {
|
|
background: #555;
|
|
}
|
|
|
|
#mindmap-container:fullscreen {
|
|
width: 100vw !important;
|
|
height: 100vh !important;
|
|
border-radius: 0;
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block wide_content %}
|
|
<h1>{{ mindmap.title }}</h1>
|
|
{% if mindmap.description %}
|
|
<p style="color: var(--text-light); margin-bottom: 1rem;">{{ mindmap.description }}</p>
|
|
{% endif %}
|
|
|
|
<div id="mindmap-wrapper">
|
|
<button id="fullscreen-btn">全屏</button>
|
|
<div id="mindmap-container"></div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/simple-mind-map@0.10.0/dist/simpleMindMap.umd.min.js"></script>
|
|
<script>
|
|
(function () {
|
|
function init() {
|
|
var el = document.getElementById('mindmap-container');
|
|
if (!el) return;
|
|
|
|
// ✅ 强制容器尺寸先生效
|
|
el.style.width = '100%';
|
|
el.style.height = '90vh';
|
|
el.style.display = 'block';
|
|
|
|
// ✅ 等一帧让浏览器 reflow
|
|
requestAnimationFrame(function () {
|
|
// 这时候 el.clientWidth 应该是 1400px 左右了
|
|
|
|
var raw = {{ mindmap.mindmap_data|safe }};
|
|
|
|
function adapt(node) {
|
|
if (!node) return null;
|
|
if (node.topic !== undefined) {
|
|
var result = { data: { text: node.topic } };
|
|
if (node.children && node.children.length) {
|
|
result.children = node.children.map(adapt).filter(Boolean);
|
|
}
|
|
return result;
|
|
}
|
|
if (node.data && node.data.text) {
|
|
var result2 = { data: { text: node.data.text } };
|
|
if (node.children && node.children.length) {
|
|
result2.children = node.children.map(adapt).filter(Boolean);
|
|
}
|
|
return result2;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
var mindData;
|
|
if (raw.data && raw.data.topic !== undefined) {
|
|
mindData = adapt(raw.data);
|
|
} else if (raw.data && raw.data.text) {
|
|
mindData = adapt(raw);
|
|
} else {
|
|
return;
|
|
}
|
|
|
|
var MindMap = window.simpleMindMap && window.simpleMindMap.default;
|
|
if (!MindMap) return;
|
|
|
|
new MindMap({
|
|
el: el,
|
|
data: mindData,
|
|
readonly: true,
|
|
layout: 'logicalStructure',
|
|
theme: 'default',
|
|
scale: 1.5,
|
|
maxScale: 3,
|
|
minScale: 0.3,
|
|
fit: false,
|
|
center: true
|
|
});
|
|
|
|
// ✅ 初始化完再强制改一次 SVG 尺寸
|
|
var svg = el.querySelector('svg');
|
|
if (svg) {
|
|
svg.style.width = el.clientWidth + 'px';
|
|
svg.style.height = el.clientHeight + 'px';
|
|
}
|
|
});
|
|
}
|
|
|
|
// DOM ready 后执行
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
} else {
|
|
setTimeout(init, 100);
|
|
}
|
|
})();
|
|
</script>
|
|
{% endblock %} |