Skip to content

Commit 8c25bde

Browse files
authored
Search: link for results from other projects (#625)
Closes #622
1 parent 64bbf31 commit 8c25bde

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/search.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export class SearchElement extends LitElement {
266266
<a
267267
@click=${this.followResultLink}
268268
class="hit-block-heading"
269-
href="${result.path}"
269+
href="${this.getResultLink(result)}"
270270
>
271271
<i>${listIcon.node[0]}</i>
272272
<h2>${result.title} ${this.renderExternalProject(result)}</h2>
@@ -292,6 +292,14 @@ export class SearchElement extends LitElement {
292292
document.dispatchEvent(event);
293293
}
294294

295+
getResultLink(result) {
296+
let link = result.path;
297+
if (result.project.slug !== this.config.projects.current.slug) {
298+
link = `${result.domain}${result.path}`;
299+
}
300+
return link;
301+
}
302+
295303
renderBlockResult(block, index, result) {
296304
// TODO: take a substring of the title as well in case it's too long?
297305
let title = block.title;
@@ -318,7 +326,7 @@ export class SearchElement extends LitElement {
318326
@mouseenter=${this.mouseenterResultHit}
319327
@click=${() => this.storeRecentSearch(block, result)}
320328
class="hit"
321-
href="${result.path}#${block.id}"
329+
href="${this.getResultLink(result)}#${block.id}"
322330
>
323331
<div id="hit-${index}">
324332
<p class="hit subheading">${title}</p>
@@ -355,7 +363,10 @@ export class SearchElement extends LitElement {
355363
({ block, result }) =>
356364
html`<div class="hit-block">
357365
<div class="hit-block-heading-container">
358-
<a class="hit-block-heading" href="${result.path}">
366+
<a
367+
class="hit-block-heading"
368+
href="${this.getResultLink(result)}"
369+
>
359370
<i>${listIcon.node[0]}</i>
360371
<h2>${result.title} ${this.renderExternalProject(result)}</h2>
361372
</a>

0 commit comments

Comments
 (0)