Skip to content

Commit

Permalink
fix: prepend "https" if url without protocol when bookmark click to o…
Browse files Browse the repository at this point in the history
…pen (#3277)
  • Loading branch information
QiShaoXuan committed Jun 30, 2023
1 parent 0c09fd4 commit 9848f61
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/blocks/src/bookmark-block/bookmark-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ export class BookmarkBlockComponent extends BlockElement<BookmarkBlockModel> {
}, 100);
}

private _onCardClick() {
let link = this.model.url;

if (!link.match(/^[a-zA-Z]+:\/\//)) {
link = 'https://' + link;
}
window.open(link, '_blank');
}

private _onToolbarSelected: ToolbarActionCallback & MenuActionCallback =
type => {
if (type === 'caption') {
Expand Down Expand Up @@ -313,8 +322,8 @@ export class BookmarkBlockComponent extends BlockElement<BookmarkBlockModel> {
>
<div class="affine-bookmark-title">
<bookmark-loader
size="15px"
color="var(--affine-primary-color)"
.size=${'15px'}
.color=${'var(--affine-primary-color)'}
></bookmark-loader>
<div class="affine-bookmark-title-content">Loading...</div>
</div>
Expand All @@ -324,10 +333,9 @@ export class BookmarkBlockComponent extends BlockElement<BookmarkBlockModel> {
</div>`
: nothing;

const linkCard = html`<a
href="${url}"
target="_blank"
const linkCard = html`<div
class="affine-bookmark-link"
@click=${this._onCardClick}
>
<div class="affine-bookmark-content-wrapper">
<div class="affine-bookmark-title">
Expand All @@ -345,7 +353,7 @@ export class BookmarkBlockComponent extends BlockElement<BookmarkBlockModel> {
<div class="affine-bookmark-banner ${image ? 'shadow' : ''}">
${image ? html`<img src="${image}" alt="image" />` : DefaultBanner}
</div>
</a>`;
</div>`;

if (!url) {
return createModal;
Expand Down

0 comments on commit 9848f61

Please sign in to comment.