Skip to content

Commit

Permalink
文章详情页增加目录索引
Browse files Browse the repository at this point in the history
  • Loading branch information
CYRUS-STUDIO committed Sep 16, 2024
1 parent 337a435 commit dc5c8af
Show file tree
Hide file tree
Showing 34 changed files with 527 additions and 44 deletions.
Empty file added assets/css/custom.css
Empty file.
3 changes: 3 additions & 0 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ theme = "m10c"

[params.style]
primaryColor = "#87CEFA"

[params]
customCSS = ["css/custom.css"]
2 changes: 1 addition & 1 deletion public/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="John Doe" />
<meta name="description" content="" />
<link rel="stylesheet" href="/blog/css/main.min.1130dbc316c46ebce5c0974972593128dc11ce9c223a91c1f73ca557000541bc.css" />
<link rel="stylesheet" href="/blog/css/main.min.08e876a0f4aeb92fb7ca4e4c12d7d6ea16684353b267ad3f4385e180cc91a06b.css" />



Expand Down
18 changes: 16 additions & 2 deletions public/about/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="John Doe" />
<meta name="description" content="" />
<link rel="stylesheet" href="/blog/css/main.min.1130dbc316c46ebce5c0974972593128dc11ce9c223a91c1f73ca557000541bc.css" />
<link rel="stylesheet" href="/blog/css/main.min.08e876a0f4aeb92fb7ca4e4c12d7d6ea16684353b267ad3f4385e180cc91a06b.css" />



Expand Down Expand Up @@ -65,9 +65,23 @@ <h1 class ="post-title">About</h1>
</div>
<div class="post-footer">

</div>
</div>
</article>



<div id="toc" class="toc-container hidden"></div>


<button id="toc-toggle" class="toc-toggle" aria-label="Ŀ¼">
&#9776;
</button>


<script src="/blog/js/toc.js"></script>



</main>
</body>
</html>
2 changes: 1 addition & 1 deletion public/categories/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="John Doe" />
<meta name="description" content="" />
<link rel="stylesheet" href="/blog/css/main.min.1130dbc316c46ebce5c0974972593128dc11ce9c223a91c1f73ca557000541bc.css" />
<link rel="stylesheet" href="/blog/css/main.min.08e876a0f4aeb92fb7ca4e4c12d7d6ea16684353b267ad3f4385e180cc91a06b.css" />
<link rel="alternate" type="application/rss+xml" href="https://cyrus-studio.github.io/blog/categories/index.xml" title="CYRUS STUDIO">


Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="John Doe" />
<meta name="description" content="Android &amp; Python Developer" />
<link rel="stylesheet" href="/blog/css/main.min.1130dbc316c46ebce5c0974972593128dc11ce9c223a91c1f73ca557000541bc.css" />
<link rel="stylesheet" href="/blog/css/main.min.08e876a0f4aeb92fb7ca4e4c12d7d6ea16684353b267ad3f4385e180cc91a06b.css" />
<link rel="alternate" type="application/rss+xml" href="https://cyrus-studio.github.io/blog/index.xml" title="CYRUS STUDIO">


Expand Down
72 changes: 72 additions & 0 deletions public/js/toc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 等待 DOM 加载完成
document.addEventListener('DOMContentLoaded', function () {
const tocToggle = document.getElementById('toc-toggle');
const tocContainer = document.getElementById('toc');
const contentArea = document.querySelector('.post-content'); // 根据你的内容区域的类名调整

// 生成目录函数
function generateTOC() {
const headings = contentArea.querySelectorAll('h1, h2, h3');
console.log("Headings found:", headings); // 输出找到的标题元素
if (headings.length === 0) {
// 如果没有找到标题,隐藏浮动按钮
tocToggle.style.display = 'none';
return;
}

const tocList = document.createElement('ul');

headings.forEach(function (heading) {
if (!heading.id) {
// 如果标题没有 id,生成一个
heading.id = heading.textContent.trim().toLowerCase().replace(/\s+/g, '-').replace(/[^\w\-]/g, '');
}

const tocItem = document.createElement('li');
tocItem.classList.add('toc-item', heading.tagName.toLowerCase());

const tocLink = document.createElement('a');
tocLink.href = `#${heading.id}`;
tocLink.textContent = heading.textContent;

tocItem.appendChild(tocLink);
tocList.appendChild(tocItem);
});

tocContainer.appendChild(tocList);
}

// 页面加载时生成目录
generateTOC();

// 切换目录的显示与隐藏
tocToggle.addEventListener('click', function () {
console.log("TOC toggle clicked"); // 点击按钮时输出到控制台
// 先检查当前是否是隐藏状态
if (tocContainer.classList.contains("hidden")) {
tocContainer.classList.remove("hidden");
tocContainer.classList.add("visible");
} else {
tocContainer.classList.remove("visible");
tocContainer.classList.add("hidden");
}
});

// 点击目录项时平滑滚动到对应位置
tocContainer.addEventListener('click', function (event) {
if (event.target.tagName.toLowerCase() === 'a') {
event.preventDefault();
const targetId = event.target.getAttribute('href').substring(1);
const targetHeading = document.getElementById(targetId);
if (targetHeading) {
window.scrollTo({
top: targetHeading.offsetTop - 20, // 根据需要调整偏移量
behavior: 'smooth'
});
// 点击后隐藏目录
tocContainer.classList.remove("visible");
tocContainer.classList.add("hidden");
}
}
});
});
2 changes: 1 addition & 1 deletion public/page/2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="John Doe" />
<meta name="description" content="Android &amp; Python Developer" />
<link rel="stylesheet" href="/blog/css/main.min.1130dbc316c46ebce5c0974972593128dc11ce9c223a91c1f73ca557000541bc.css" />
<link rel="stylesheet" href="/blog/css/main.min.08e876a0f4aeb92fb7ca4e4c12d7d6ea16684353b267ad3f4385e180cc91a06b.css" />
<link rel="alternate" type="application/rss+xml" href="https://cyrus-studio.github.io/blog/index.xml" title="CYRUS STUDIO">


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="John Doe" />
<meta name="description" content="" />
<link rel="stylesheet" href="/blog/css/main.min.1130dbc316c46ebce5c0974972593128dc11ce9c223a91c1f73ca557000541bc.css" />
<link rel="stylesheet" href="/blog/css/main.min.08e876a0f4aeb92fb7ca4e4c12d7d6ea16684353b267ad3f4385e180cc91a06b.css" />



Expand Down Expand Up @@ -268,9 +268,23 @@ <h1 class ="post-title">0成本通过Hugo和GitHub Pages搭建博客</h1>
</div>
<div class="post-footer">

</div>
</div>
</article>



<div id="toc" class="toc-container hidden"></div>


<button id="toc-toggle" class="toc-toggle" aria-label="Ŀ¼">
&#9776;
</button>


<script src="/blog/js/toc.js"></script>



</main>
</body>
</html>
18 changes: 16 additions & 2 deletions public/posts/android源码导入android-studio/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="John Doe" />
<meta name="description" content="" />
<link rel="stylesheet" href="/blog/css/main.min.1130dbc316c46ebce5c0974972593128dc11ce9c223a91c1f73ca557000541bc.css" />
<link rel="stylesheet" href="/blog/css/main.min.08e876a0f4aeb92fb7ca4e4c12d7d6ea16684353b267ad3f4385e180cc91a06b.css" />



Expand Down Expand Up @@ -154,9 +154,23 @@ <h1 id="__导入android-studio__"><strong>导入android studio</strong></h1>
</div>
<div class="post-footer">

</div>
</div>
</article>



<div id="toc" class="toc-container hidden"></div>


<button id="toc-toggle" class="toc-toggle" aria-label="Ŀ¼">
&#9776;
</button>


<script src="/blog/js/toc.js"></script>



</main>
</body>
</html>
Expand Down
2 changes: 1 addition & 1 deletion public/posts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="John Doe" />
<meta name="description" content="" />
<link rel="stylesheet" href="/blog/css/main.min.1130dbc316c46ebce5c0974972593128dc11ce9c223a91c1f73ca557000541bc.css" />
<link rel="stylesheet" href="/blog/css/main.min.08e876a0f4aeb92fb7ca4e4c12d7d6ea16684353b267ad3f4385e180cc91a06b.css" />
<link rel="alternate" type="application/rss+xml" href="https://cyrus-studio.github.io/blog/posts/index.xml" title="CYRUS STUDIO">


Expand Down
18 changes: 16 additions & 2 deletions public/posts/lineageos刷机教程/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="John Doe" />
<meta name="description" content="" />
<link rel="stylesheet" href="/blog/css/main.min.1130dbc316c46ebce5c0974972593128dc11ce9c223a91c1f73ca557000541bc.css" />
<link rel="stylesheet" href="/blog/css/main.min.08e876a0f4aeb92fb7ca4e4c12d7d6ea16684353b267ad3f4385e180cc91a06b.css" />



Expand Down Expand Up @@ -207,9 +207,23 @@ <h1 id="__使用lineageos-recovery刷机__"><strong>使用LineageOS Recovery刷
</div>
<div class="post-footer">

</div>
</div>
</article>



<div id="toc" class="toc-container hidden"></div>


<button id="toc-toggle" class="toc-toggle" aria-label="Ŀ¼">
&#9776;
</button>


<script src="/blog/js/toc.js"></script>



</main>
</body>
</html>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="John Doe" />
<meta name="description" content="" />
<link rel="stylesheet" href="/blog/css/main.min.1130dbc316c46ebce5c0974972593128dc11ce9c223a91c1f73ca557000541bc.css" />
<link rel="stylesheet" href="/blog/css/main.min.08e876a0f4aeb92fb7ca4e4c12d7d6ea16684353b267ad3f4385e180cc91a06b.css" />



Expand Down Expand Up @@ -512,9 +512,23 @@ <h1 id="__刷机__"><strong>刷机</strong></h1>
</div>
<div class="post-footer">

</div>
</div>
</article>



<div id="toc" class="toc-container hidden"></div>


<button id="toc-toggle" class="toc-toggle" aria-label="Ŀ¼">
&#9776;
</button>


<script src="/blog/js/toc.js"></script>



</main>
</body>
</html>
Expand Down
18 changes: 16 additions & 2 deletions public/posts/linux下代理设置/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="John Doe" />
<meta name="description" content="" />
<link rel="stylesheet" href="/blog/css/main.min.1130dbc316c46ebce5c0974972593128dc11ce9c223a91c1f73ca557000541bc.css" />
<link rel="stylesheet" href="/blog/css/main.min.08e876a0f4aeb92fb7ca4e4c12d7d6ea16684353b267ad3f4385e180cc91a06b.css" />



Expand Down Expand Up @@ -182,9 +182,23 @@ <h1 id="__4-配置环境变量__"><strong>4. 配置环境变量</strong></h1>
</div>
<div class="post-footer">

</div>
</div>
</article>



<div id="toc" class="toc-container hidden"></div>


<button id="toc-toggle" class="toc-toggle" aria-label="Ŀ¼">
&#9776;
</button>


<script src="/blog/js/toc.js"></script>



</main>
</body>
</html>
Expand Down
18 changes: 16 additions & 2 deletions public/posts/magiskboot编译解包打包boot.img/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="John Doe" />
<meta name="description" content="" />
<link rel="stylesheet" href="/blog/css/main.min.1130dbc316c46ebce5c0974972593128dc11ce9c223a91c1f73ca557000541bc.css" />
<link rel="stylesheet" href="/blog/css/main.min.08e876a0f4aeb92fb7ca4e4c12d7d6ea16684353b267ad3f4385e180cc91a06b.css" />



Expand Down Expand Up @@ -203,9 +203,23 @@ <h1 id="__使用-magiskboot-解包打包内核__"><strong>使用 magiskboot 解
</div>
<div class="post-footer">

</div>
</div>
</article>



<div id="toc" class="toc-container hidden"></div>


<button id="toc-toggle" class="toc-toggle" aria-label="Ŀ¼">
&#9776;
</button>


<script src="/blog/js/toc.js"></script>



</main>
</body>
</html>
Expand Down
2 changes: 1 addition & 1 deletion public/posts/page/2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="John Doe" />
<meta name="description" content="" />
<link rel="stylesheet" href="/blog/css/main.min.1130dbc316c46ebce5c0974972593128dc11ce9c223a91c1f73ca557000541bc.css" />
<link rel="stylesheet" href="/blog/css/main.min.08e876a0f4aeb92fb7ca4e4c12d7d6ea16684353b267ad3f4385e180cc91a06b.css" />
<link rel="alternate" type="application/rss+xml" href="https://cyrus-studio.github.io/blog/posts/index.xml" title="CYRUS STUDIO">


Expand Down
Loading

0 comments on commit dc5c8af

Please sign in to comment.