Skip to content

Commit 015a191

Browse files
committed
feat: handle external link on sidebar
1 parent 902b085 commit 015a191

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

example/router-mode-history/_sidebar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
- [Foo](/example/router-mode-history/foo.md#section-3)
33
- [Bar A Long Long Long Title](/example/router-mode-history/bar.md)
44
- [Baz](/example/router-mode-history/baz.md)
5+
- [External](https://github.com/)

src/pagination.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class Link {
5959
return {
6060
name: this.hyperlink.innerText,
6161
href: this.hyperlink.getAttribute('href'),
62-
chapterName: this.chapter && this.chapter.innerText || ''
62+
chapterName: this.chapter && this.chapter.innerText || '',
63+
isExternal: this.hyperlink.getAttribute('target') === '_blank',
6364
}
6465
}
6566
}
@@ -100,7 +101,7 @@ const template = {
100101
return [
101102
data.prev && `
102103
<div class="pagination-item pagination-item--previous">
103-
<a href="${data.prev.href}">
104+
<a href="${data.prev.href}" ${data.prev.isExternal ? 'target="_blank"' : ''}>
104105
<div class="pagination-item-label">
105106
<svg width="10" height="16" viewBox="0 0 10 16" xmlns="http://www.w3.org/2000/svg">
106107
<polyline fill="none" vector-effect="non-scaling-stroke" points="8,2 2,8 8,14"/>
@@ -115,7 +116,7 @@ const template = {
115116
`,
116117
data.next && `
117118
<div class="pagination-item pagination-item--next">
118-
<a href="${data.next.href}">
119+
<a href="${data.next.href}" ${data.next.isExternal ? 'target="_blank"' : ''}>
119120
<div class="pagination-item-label">
120121
<span>${nextText}</span>
121122
<svg width="10" height="16" viewBox="0 0 10 16" xmlns="http://www.w3.org/2000/svg">

0 commit comments

Comments
 (0)