mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-30 15:59:09 +08:00
refactor: better semantic of obsidian export options (#6926)
This commit is contained in:
parent
52758a71b6
commit
bb2b885c2d
@ -20,10 +20,16 @@ interface FileInfo {
|
|||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ObsidianProcessingMethod = {
|
||||||
|
APPEND: '1',
|
||||||
|
PREPEND: '2',
|
||||||
|
NEW_OR_OVERWRITE: '3'
|
||||||
|
} as const
|
||||||
|
|
||||||
interface PopupContainerProps {
|
interface PopupContainerProps {
|
||||||
title: string
|
title: string
|
||||||
obsidianTags: string | null
|
obsidianTags: string | null
|
||||||
processingMethod: string | '3'
|
processingMethod: (typeof ObsidianProcessingMethod)[keyof typeof ObsidianProcessingMethod]
|
||||||
open: boolean
|
open: boolean
|
||||||
resolve: (success: boolean) => void
|
resolve: (success: boolean) => void
|
||||||
message?: Message
|
message?: Message
|
||||||
@ -230,10 +236,10 @@ const PopupContainer: React.FC<PopupContainerProps> = ({
|
|||||||
markdown = ''
|
markdown = ''
|
||||||
}
|
}
|
||||||
let content = ''
|
let content = ''
|
||||||
if (state.processingMethod !== '3') {
|
if (state.processingMethod !== ObsidianProcessingMethod.NEW_OR_OVERWRITE) {
|
||||||
content = `\n---\n${markdown}`
|
content = `\n---\n${markdown}`
|
||||||
} else {
|
} else {
|
||||||
content = `---\n\ntitle: ${state.title}\ncreated: ${state.createdAt}\nsource: ${state.source}\ntags: ${state.tags}\n---\n${markdown}`
|
content = `---\ntitle: ${state.title}\ncreated: ${state.createdAt}\nsource: ${state.source}\ntags: ${state.tags}\n---\n${markdown}`
|
||||||
}
|
}
|
||||||
if (content === '') {
|
if (content === '') {
|
||||||
window.message.error(i18n.t('chat.topics.export.obsidian_export_failed'))
|
window.message.error(i18n.t('chat.topics.export.obsidian_export_failed'))
|
||||||
@ -280,9 +286,9 @@ const PopupContainer: React.FC<PopupContainerProps> = ({
|
|||||||
const titleWithoutExt = fileName.endsWith('.md') ? fileName.substring(0, fileName.length - 3) : fileName
|
const titleWithoutExt = fileName.endsWith('.md') ? fileName.substring(0, fileName.length - 3) : fileName
|
||||||
handleChange('title', titleWithoutExt)
|
handleChange('title', titleWithoutExt)
|
||||||
setHasTitleBeenManuallyEdited(false)
|
setHasTitleBeenManuallyEdited(false)
|
||||||
handleChange('processingMethod', '1')
|
handleChange('processingMethod', ObsidianProcessingMethod.APPEND)
|
||||||
} else {
|
} else {
|
||||||
handleChange('processingMethod', '3')
|
handleChange('processingMethod', ObsidianProcessingMethod.NEW_OR_OVERWRITE)
|
||||||
if (!hasTitleBeenManuallyEdited) {
|
if (!hasTitleBeenManuallyEdited) {
|
||||||
handleChange('title', title)
|
handleChange('title', title)
|
||||||
}
|
}
|
||||||
@ -390,9 +396,15 @@ const PopupContainer: React.FC<PopupContainerProps> = ({
|
|||||||
onChange={(value) => handleChange('processingMethod', value)}
|
onChange={(value) => handleChange('processingMethod', value)}
|
||||||
placeholder={i18n.t('chat.topics.export.obsidian_operate_placeholder')}
|
placeholder={i18n.t('chat.topics.export.obsidian_operate_placeholder')}
|
||||||
allowClear>
|
allowClear>
|
||||||
<Option value="1">{i18n.t('chat.topics.export.obsidian_operate_append')}</Option>
|
<Option value={ObsidianProcessingMethod.APPEND}>
|
||||||
<Option value="2">{i18n.t('chat.topics.export.obsidian_operate_prepend')}</Option>
|
{i18n.t('chat.topics.export.obsidian_operate_append')}
|
||||||
<Option value="3">{i18n.t('chat.topics.export.obsidian_operate_new_or_overwrite')}</Option>
|
</Option>
|
||||||
|
<Option value={ObsidianProcessingMethod.PREPEND}>
|
||||||
|
{i18n.t('chat.topics.export.obsidian_operate_prepend')}
|
||||||
|
</Option>
|
||||||
|
<Option value={ObsidianProcessingMethod.NEW_OR_OVERWRITE}>
|
||||||
|
{i18n.t('chat.topics.export.obsidian_operate_new_or_overwrite')}
|
||||||
|
</Option>
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label={i18n.t('chat.topics.export.obsidian_reasoning')}>
|
<Form.Item label={i18n.t('chat.topics.export.obsidian_reasoning')}>
|
||||||
@ -403,4 +415,4 @@ const PopupContainer: React.FC<PopupContainerProps> = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export { PopupContainer }
|
export { ObsidianProcessingMethod, PopupContainer }
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import { PopupContainer } from '@renderer/components/ObsidianExportDialog'
|
import { ObsidianProcessingMethod, PopupContainer } from '@renderer/components/ObsidianExportDialog'
|
||||||
import { TopView } from '@renderer/components/TopView'
|
import { TopView } from '@renderer/components/TopView'
|
||||||
import type { Topic } from '@renderer/types'
|
import type { Topic } from '@renderer/types'
|
||||||
import type { Message } from '@renderer/types/newMessage'
|
import type { Message } from '@renderer/types/newMessage'
|
||||||
|
|
||||||
interface ObsidianExportOptions {
|
interface ObsidianExportOptions {
|
||||||
title: string
|
title: string
|
||||||
processingMethod: string | '3'
|
processingMethod: (typeof ObsidianProcessingMethod)[keyof typeof ObsidianProcessingMethod]
|
||||||
topic?: Topic
|
topic?: Topic
|
||||||
message?: Message
|
message?: Message
|
||||||
messages?: Message[]
|
messages?: Message[]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user