From 2eec7c4884146add6e0c8142e463cfad34fb7637 Mon Sep 17 00:00:00 2001 From: Koy Zhuang Date: Sun, 11 Aug 2024 10:56:55 +0800 Subject: [PATCH] fix: sync the page title regarding the title config (#2478) Co-authored-by: Luffy <52o@qq52o.cn> --- 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..ef8a39b4c 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 + ? `${currentSection} - ${name}` + : 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}