add option Embed into webpage (#5065)

add option Embed into webpage

---------

Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
so95 2025-02-18 12:41:19 +07:00 committed by GitHub
parent 84b4b38cbb
commit d6ba4bd255
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 63 additions and 2 deletions

View File

@ -19,3 +19,6 @@
color: white;
.darkBg();
}
.optionContainer {
padding: 10px;
}

View File

@ -3,10 +3,22 @@ import HightLightMarkdown from '@/components/highlight-markdown';
import { SharedFrom } from '@/constants/chat';
import { useTranslate } from '@/hooks/common-hooks';
import { IModalProps } from '@/interfaces/common';
import { Card, Modal, Tabs, TabsProps, Typography } from 'antd';
import {
Card,
Checkbox,
Flex,
Form,
Modal,
Select,
Tabs,
TabsProps,
Typography,
} from 'antd';
import { useState } from 'react';
import { useIsDarkTheme } from '@/components/theme-provider';
import { cn } from '@/lib/utils';
import { languageOptions } from '@/locales/config';
import styles from './index.less';
const { Paragraph, Link } = Typography;
@ -27,10 +39,26 @@ const EmbedModal = ({
const { t } = useTranslate('chat');
const isDarkTheme = useIsDarkTheme();
const [visibleAvatar, setVisibleAvatar] = useState(false);
const [locale, setLocale] = useState('');
const generateIframeSrc = () => {
let src = `${location.origin}/chat/share?shared_id=${token}&from=${form}&auth=${beta}`;
if (visibleAvatar) {
src += '&visible_avatar=1';
}
if (locale) {
src += `&locale=${locale}`;
}
return src;
};
const iframeSrc = generateIframeSrc();
const text = `
~~~ html
<iframe
src="${location.origin}/chat/share?shared_id=${token}&from=${form}&auth=${beta}"
src="${iframeSrc}"
style="width: 100%; height: 100%; min-height: 600px"
frameborder="0"
>
@ -48,6 +76,23 @@ const EmbedModal = ({
extra={<CopyToClipboard text={text}></CopyToClipboard>}
className={styles.codeCard}
>
<Flex vertical className={styles.optionContainer}>
<h2>Option</h2>
<Form.Item label={t('avatarHidden')}>
<Checkbox
checked={visibleAvatar}
onChange={(e) => setVisibleAvatar(e.target.checked)}
></Checkbox>
</Form.Item>
<Form.Item label={t('locale')}>
<Select
placeholder="Select a locale"
onChange={(value) => setLocale(value)}
options={languageOptions}
style={{ width: '100%' }}
/>
</Form.Item>
</Flex>
<HightLightMarkdown>{text}</HightLightMarkdown>
</Card>
),

View File

@ -65,4 +65,15 @@ i18n
},
});
export const languageOptions = [
{ value: 'en', label: 'English' },
{ value: 'zh', label: 'Chinese' },
{ value: 'zh-TRADITIONAL', label: 'Traditional Chinese' },
{ value: 'id', label: 'Indonesian' },
{ value: 'es', label: 'Spanish' },
{ value: 'vi', label: 'Vietnamese' },
{ value: 'ja', label: 'Japanese' },
{ value: 'pt-BR', label: 'Brazilian Portuguese' },
];
export default i18n;

View File

@ -525,6 +525,8 @@ This procedure will improve precision of retrieval by adding more information to
keywordTip: `Apply LLM to analyze user's questions, extract keywords which will be emphesize during the relevance omputation.`,
languageTip:
'Allows sentence rewriting with the specified language or defaults to the latest question if not selected.',
avatarHidden: 'Hide avatar',
locale: 'Locale',
},
setting: {
profile: 'Profile',