fix: sync the page title regarding the title config (#2478)

Co-authored-by: Luffy <52o@qq52o.cn>
This commit is contained in:
Koy Zhuang 2024-08-11 10:56:55 +08:00 committed by GitHub
parent 676f5f8842
commit 2eec7c4884
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View File

@ -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;

View File

@ -49,9 +49,10 @@ function doSearch(value) {
let html = '';
matches.forEach((post, i) => {
const title = (post.title || '').replace(/<[^>]+>/g, '');
html += /* html */ `
<div class="matching-post" aria-label="search result ${i + 1}">
<a href="${post.url}">
<a href="${post.url}" title="${title}">
<p class="title clamp-1">${post.title}</p>
<p class="content clamp-2">${post.content}</p>
</a>