Skip to content

Commit af44f81

Browse files
committed
fix: sync the page title regarding the title config
1 parent 33f1d9a commit af44f81

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/core/event/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,20 @@ export function Events(Base) {
296296
// =========================================================================
297297
/**
298298
* Handle rendering UI element updates and new content
299+
* @param {string} name the site name
299300
* @void
300301
*/
301-
onRender() {
302+
onRender(name) {
302303
const currentPath = this.router.toURL(this.router.getCurrentPath());
303-
const currentTitle = dom.find(
304-
`.sidebar a[href='${currentPath}']`,
305-
)?.innerText;
304+
const currentSection = dom
305+
.find(`.sidebar a[href='${currentPath}']`)
306+
?.getAttribute('title');
307+
308+
const currentTitle = name
309+
? currentSection
310+
? `${name} - ${currentSection}`
311+
: name
312+
: currentSection;
306313

307314
// Update page title
308315
dom.$.title = currentTitle || this.#title;

src/core/render/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ export function Render(Base) {
343343
}
344344

345345
_bindEventOnRendered(activeEl) {
346-
const { autoHeader } = this.config;
346+
const { autoHeader, name } = this.config;
347347

348-
this.onRender();
348+
this.onRender(name);
349349

350350
if (autoHeader && activeEl) {
351351
const main = dom.getNode('#main');

src/plugins/search/component.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ function doSearch(value) {
4949

5050
let html = '';
5151
matches.forEach((post, i) => {
52+
const title = (post.title || '').replace(/<[^>]+>/g, '');
5253
html += /* html */ `
5354
<div class="matching-post" aria-label="search result ${i + 1}">
54-
<a href="${post.url}">
55+
<a href="${post.url}" title="${title}">
5556
<p class="title clamp-1">${post.title}</p>
5657
<p class="content clamp-2">${post.content}</p>
5758
</a>

0 commit comments

Comments
 (0)