Skip to content

Commit 58e2ea5

Browse files
committed
CrateSidebar::Link: Display docs.rs icon if link goes to docs.rs
1 parent 162b840 commit 58e2ea5

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

app/components/crate-sidebar/link.hbs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<div ...attributes>
22
<h3 data-test-title>{{@title}}</h3>
33
<div local-class="content">
4-
{{#if this.isGitHub}}
4+
{{#if this.isDocsRs}}
5+
{{svg-jar "docs-rs" local-class="icon" data-test-icon="docs-rs"}}
6+
{{else if this.isGitHub}}
57
{{svg-jar "GitHub-Mark" local-class="icon" data-test-icon="github"}}
68
{{else}}
79
{{svg-jar "link" local-class="icon" data-test-icon="link"}}

app/components/crate-sidebar/link.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export default class CrateSidebarLink extends Component {
1313
return url;
1414
}
1515

16+
get isDocsRs() {
17+
return this.text.startsWith('docs.rs/');
18+
}
19+
1620
get isGitHub() {
1721
return this.text.startsWith('github.com/');
1822
}

public/assets/docs-rs.svg

Lines changed: 4 additions & 0 deletions
Loading

tests/components/crate-sidebar/link-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ module('Component | CrateSidebar::Link', function (hooks) {
2424
.hasText('github.com/rust-lang/crates.io');
2525
});
2626

27+
test('renders docs.rs icon for docs.rs links', async function (assert) {
28+
await render(hbs`<CrateSidebar::Link @url="https://docs.rs/tracing" />`);
29+
assert.dom('[data-test-icon]').exists({ count: 1 }).hasAttribute('data-test-icon', 'docs-rs');
30+
assert.dom('[data-test-link]').hasAttribute('href', 'https://docs.rs/tracing').hasText('docs.rs/tracing');
31+
});
32+
2733
test('does not shorten HTTP links', async function (assert) {
2834
await render(hbs`<CrateSidebar::Link @url="http://www.rust-lang.org" />`);
2935
assert.dom('[data-test-link]').hasAttribute('href', 'http://www.rust-lang.org').hasText('http://www.rust-lang.org');

0 commit comments

Comments
 (0)