From ddaadff8db0d660fe9e925352e04fa4dc0fda543 Mon Sep 17 00:00:00 2001 From: koy Date: Wed, 31 Jul 2024 19:20:44 +0800 Subject: [PATCH 1/2] fix: sync the page title regarding the title config --- src/core/event/index.js | 13 ++++++++++--- src/plugins/search/component.js | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/core/event/index.js b/src/core/event/index.js index f1f488113..e9b475bb9 100644 --- a/src/core/event/index.js +++ b/src/core/event/index.js @@ -299,10 +299,17 @@ export function Events(Base) { * @void */ onRender() { + const { name } = this.config; const currentPath = this.router.toURL(this.router.getCurrentPath()); - const currentTitle = dom.find( - `.sidebar a[href='${currentPath}']`, - )?.innerText; + const currentSection = dom + .find(`.sidebar a[href='${currentPath}']`) + ?.getAttribute('title'); + + const currentTitle = name + ? currentSection + ? `${name} - ${currentSection}` + : name + : currentSection; // Update page title dom.$.title = currentTitle || this.#title; diff --git a/src/plugins/search/component.js b/src/plugins/search/component.js index 1fb4f36f2..dc0ac2e37 100644 --- a/src/plugins/search/component.js +++ b/src/plugins/search/component.js @@ -49,9 +49,10 @@ function doSearch(value) { let html = ''; matches.forEach((post, i) => { + const title = (post.title || '').replace(/<[^>]+>/g, ''); html += /* html */ `
- +

${post.title}

${post.content}

From 87218d6eeea5b1698e83b498007ddd2b457cccda Mon Sep 17 00:00:00 2001 From: Luffy <52o@qq52o.cn> Date: Sun, 11 Aug 2024 10:54:50 +0800 Subject: [PATCH 2/2] Update src/core/event/index.js --- src/core/event/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/event/index.js b/src/core/event/index.js index e9b475bb9..ef8a39b4c 100644 --- a/src/core/event/index.js +++ b/src/core/event/index.js @@ -307,7 +307,7 @@ export function Events(Base) { const currentTitle = name ? currentSection - ? `${name} - ${currentSection}` + ? `${currentSection} - ${name}` : name : currentSection;