+
+
+
+
-
{removeTailingHash(heading.text)}
-
- )}
-
-}
+
+
+
+
+
+
\ No newline at end of file
+ if (!customElements.get("table-of-contents")) {
+ customElements.define("table-of-contents", TableOfContents);
+ }
+
diff --git a/src/i18n/i18nKey.ts b/src/i18n/i18nKey.ts
index 0f2da7f..a5d21a2 100644
--- a/src/i18n/i18nKey.ts
+++ b/src/i18n/i18nKey.ts
@@ -37,6 +37,7 @@ enum I18nKey {
notFoundDesc = "notFoundDesc",
backToHome = "backToHome",
pinned = "pinned",
+ toc = "toc",
}
export default I18nKey;
diff --git a/src/i18n/languages/en.ts b/src/i18n/languages/en.ts
index 4953f50..ef4b1a6 100644
--- a/src/i18n/languages/en.ts
+++ b/src/i18n/languages/en.ts
@@ -40,4 +40,5 @@ export const en: Translation = {
[Key.notFoundDesc]: "The link is broken, the page has gone missing",
[Key.backToHome]: "Back to Home",
[Key.pinned]: "Pinned",
+ [Key.toc]: "Toc",
};
diff --git a/src/i18n/languages/zh_CN.ts b/src/i18n/languages/zh_CN.ts
index 391efd6..9a5c6a3 100644
--- a/src/i18n/languages/zh_CN.ts
+++ b/src/i18n/languages/zh_CN.ts
@@ -40,4 +40,5 @@ export const zh_CN: Translation = {
[Key.notFoundDesc]: "你访问的链接已断开,页面走丢了",
[Key.backToHome]: "返回首页",
[Key.pinned]: "置顶",
+ [Key.toc]: "目录",
};
diff --git a/src/i18n/languages/zh_TW.ts b/src/i18n/languages/zh_TW.ts
index b24ee7f..d881362 100644
--- a/src/i18n/languages/zh_TW.ts
+++ b/src/i18n/languages/zh_TW.ts
@@ -40,4 +40,5 @@ export const zh_TW: Translation = {
[Key.notFoundDesc]: "你訪問的連結已斷開,頁面走丟了",
[Key.backToHome]: "返回首頁",
[Key.pinned]: "置頂",
+ [Key.toc]: "目錄",
};
diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro
index c180522..9f3ee7b 100644
--- a/src/layouts/Layout.astro
+++ b/src/layouts/Layout.astro
@@ -405,7 +405,19 @@ const setup = () => {
}
})
window.swup.hooks.on('content:replace', initCustomScrollbar)
- window.swup.hooks.on('visit:start', (visit: {to: {url: string}}) => {
+ window.swup.hooks.on('visit:start', (visit: {to: {url: string};from: { url: string };containers: string[]}) => {
+
+ const postUrlPattern = "/posts/";
+ const isToPost = visit.to.url.includes(postUrlPattern);
+ const isFromPost = visit.from.url.includes(postUrlPattern);
+
+ if (isToPost || isFromPost) {
+ visit.containers = ["main", "#sidebar"]; // 刷新两者
+ } else {
+ // 否则(例如,从首页导航到关于页面),
+ // 仅刷新主内容区域。
+ visit.containers = ["main"];
+ }
// change banner height immediately when a link is clicked
const bodyElement = document.querySelector('body')
if (pathsEqual(visit.to.url, url('/'))) {
@@ -419,12 +431,6 @@ const setup = () => {
if (heightExtend) {
heightExtend.classList.remove('hidden')
}
-
- // Hide the TOC while scrolling back to top
- let toc = document.getElementById('toc-wrapper');
- if (toc) {
- toc.classList.add('toc-not-ready')
- }
});
window.swup.hooks.on('page:view', () => {
// hide the temp high element when the transition is done
@@ -439,12 +445,6 @@ const setup = () => {
if (heightExtend) {
heightExtend.classList.add('hidden')
}
-
- // Just make the transition looks better
- const toc = document.getElementById('toc-wrapper');
- if (toc) {
- toc.classList.remove('toc-not-ready')
- }
}, 200)
});
}
@@ -455,7 +455,6 @@ if (window?.swup?.hooks) {
}
let backToTopBtn = document.getElementById('back-to-top-btn');
-let toc = document.getElementById('toc-wrapper');
let navbar = document.getElementById('navbar-wrapper')
function scrollFunction() {
let bannerHeight = window.innerHeight * (BANNER_HEIGHT / 100)
@@ -468,14 +467,6 @@ function scrollFunction() {
}
}
- if (bannerEnabled && toc) {
- if (document.body.scrollTop > bannerHeight || document.documentElement.scrollTop > bannerHeight) {
- toc.classList.remove('toc-hide')
- } else {
- toc.classList.add('toc-hide')
- }
- }
-
if (!bannerEnabled) return
if (navbar) {
const NAVBAR_HEIGHT = 72
diff --git a/src/layouts/MainGridLayout.astro b/src/layouts/MainGridLayout.astro
index e1f8e5c..3ddcb2d 100644
--- a/src/layouts/MainGridLayout.astro
+++ b/src/layouts/MainGridLayout.astro
@@ -6,7 +6,6 @@ import SideBar from "@components/widget/SideBar.astro";
import type { MarkdownHeading } from "astro";
import { Icon } from "astro-icon/components";
import ImageWrapper from "../components/misc/ImageWrapper.astro";
-import TOC from "../components/widget/TOC.astro";
import { siteConfig } from "../config";
import {
BANNER_HEIGHT,
@@ -102,24 +101,4 @@ const mainPanelTop = siteConfig.banner.enable
-
-