Skip to content

Commit f9a2977

Browse files
authored
Better handling for external link "mailto:" in Hovered Card in GBO (#3630)
1 parent 24f601d commit f9a2977

File tree

12 files changed

+33
-4
lines changed

12 files changed

+33
-4
lines changed

.changeset/young-dryers-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Better handling for external link "mailto:" in Hovered Card in GBO

packages/gitbook/src/components/DocumentView/InlineLink/InlineLink.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export async function InlineLink(props: InlineProps<DocumentInlineLink>) {
4646
);
4747
}
4848
const isExternal = inline.data.ref.kind === 'url';
49+
const isMailto = resolved.href.startsWith('mailto:');
4950
const content = (
5051
<StyledLink
5152
href={resolved.href}
@@ -63,7 +64,12 @@ export async function InlineLink(props: InlineProps<DocumentInlineLink>) {
6364
nodes={inline.nodes}
6465
ancestorInlines={[...ancestorInlines, inline]}
6566
/>
66-
{isExternal ? (
67+
{isMailto ? (
68+
<Icon
69+
icon="envelope"
70+
className="ml-1 inline size-3 links-accent:text-tint-subtle"
71+
/>
72+
) : isExternal ? (
6773
<Icon
6874
icon="arrow-up-right"
6975
className="ml-0.5 inline size-3 links-accent:text-tint-subtle"
@@ -96,16 +102,24 @@ function InlineLinkTooltipWrapper(props: {
96102
const { inline, language, resolved, children } = props;
97103

98104
let breadcrumbs = resolved.ancestors ?? [];
105+
const isMailto = resolved.href.startsWith('mailto:');
99106
const isExternal = inline.data.ref.kind === 'url';
100107
const isSamePage = inline.data.ref.kind === 'anchor' && inline.data.ref.page === undefined;
101-
if (isExternal) {
108+
109+
if (isMailto) {
110+
resolved.text = resolved.text.split('mailto:')[1] ?? resolved.text;
111+
breadcrumbs = [
112+
{
113+
label: tString(language, 'link_tooltip_email'),
114+
},
115+
];
116+
} else if (isExternal) {
102117
breadcrumbs = [
103118
{
104119
label: tString(language, 'link_tooltip_external_link'),
105120
},
106121
];
107-
}
108-
if (isSamePage) {
122+
} else if (isSamePage) {
109123
breadcrumbs = [
110124
{
111125
label: tString(language, 'link_tooltip_page_anchor'),

packages/gitbook/src/intl/translations/de.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const de = {
6868
pdf_limit_reached_continue: 'Mit ${1} weiteren Seiten erweitern.',
6969
more: 'Mehr',
7070
link_tooltip_external_link: 'Externe Verlinkung zu',
71+
link_tooltip_email: 'E-Mail senden an',
7172
link_tooltip_page_anchor: 'Zum Abschnitt springen',
7273
open_in_new_tab: 'In neuem Tab öffnen',
7374
ai_chat_assistant_name: 'GitBook-Assistent',

packages/gitbook/src/intl/translations/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const en = {
6565
pdf_limit_reached_continue: 'Extend with ${1} more pages.',
6666
more: 'More',
6767
link_tooltip_external_link: 'External link to',
68+
link_tooltip_email: 'Send an email to',
6869
link_tooltip_page_anchor: 'Jump to section',
6970
open_in_new_tab: 'Open in new tab',
7071
ai_chat_assistant_name: 'GitBook Assistant',

packages/gitbook/src/intl/translations/es.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const es: TranslationLanguage = {
6969
pdf_limit_reached_continue: 'Extender con ${1} páginas más.',
7070
more: 'Más',
7171
link_tooltip_external_link: 'Enlace externo a',
72+
link_tooltip_email: 'Enviar un correo electrónico a',
7273
link_tooltip_page_anchor: 'Saltar a la sección',
7374
open_in_new_tab: 'Abrir en una nueva pestaña',
7475
ai_chat_assistant_name: 'Asistente de GitBook',

packages/gitbook/src/intl/translations/fr.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const fr = {
6464
pdf_limit_reached_continue: 'Ajouter ${1} pages supplémentaires',
6565
more: 'Plus',
6666
link_tooltip_external_link: 'Lien externe vers',
67+
link_tooltip_email: 'Envoyer un e-mail à',
6768
link_tooltip_page_anchor: 'Aller à la section',
6869
open_in_new_tab: 'Ouvrir dans un nouvel onglet',
6970
ai_chat_assistant_name: 'Assistant GitBook',

packages/gitbook/src/intl/translations/ja.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const ja: TranslationLanguage = {
6767
pdf_limit_reached_continue: 'さらに${1}ページで拡張',
6868
more: '詳細',
6969
link_tooltip_external_link: '外部リンク先',
70+
link_tooltip_email: 'メールを送信',
7071
link_tooltip_page_anchor: 'ページ内リンク先',
7172
open_in_new_tab: '新しいタブで開く',
7273
ai_chat_assistant_name: 'GitBookアシスタント',

packages/gitbook/src/intl/translations/nl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const nl: TranslationLanguage = {
6767
pdf_limit_reached_continue: "Verleng met ${1} extra pagina's.",
6868
more: 'Meer',
6969
link_tooltip_external_link: 'Externe link naar',
70+
link_tooltip_email: 'E-mail versturen naar',
7071
link_tooltip_page_anchor: 'Spring naar sectie',
7172
open_in_new_tab: 'Open in nieuw tabblad',
7273
ai_chat_assistant_name: 'GitBook Assistent',

packages/gitbook/src/intl/translations/no.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const no: TranslationLanguage = {
6868
pdf_limit_reached_continue: 'Utvid med ${1} flere sider.',
6969
more: 'Mer',
7070
link_tooltip_external_link: 'Ekstern lenke til',
71+
link_tooltip_email: 'Send e-post til',
7172
link_tooltip_page_anchor: 'Hopp til seksjon',
7273
open_in_new_tab: 'Åpne i ny fane',
7374
ai_chat_assistant_name: 'GitBook-assistent',

packages/gitbook/src/intl/translations/pt-br.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const pt_br = {
6767
pdf_limit_reached_continue: 'Extender com mais ${1} páginas.',
6868
more: 'Mais',
6969
link_tooltip_external_link: 'Link externo para',
70+
link_tooltip_email: 'Enviar e-mail para',
7071
link_tooltip_page_anchor: 'Pular para a seção',
7172
open_in_new_tab: 'Abrir em uma nova guia',
7273
ai_chat_assistant_name: 'Assistente do GitBook',

0 commit comments

Comments
 (0)