Skip to content

Commit

Permalink
fix: sync the page title regarding the title config (#2478)
Browse files Browse the repository at this point in the history
Co-authored-by: Luffy <[email protected]>
  • Loading branch information
Koooooo-7 and sy-records authored Aug 11, 2024
1 parent 676f5f8 commit 2eec7c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/core/event/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/search/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 2eec7c4

Please sign in to comment.