Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
feat: editor supports selecting attachments to be inserted as links (#…
Browse files Browse the repository at this point in the history
…863)

#### What type of PR is this?

/kind feature

#### What this PR does / why we need it:

编辑器支持选择附件作为链接插入。目前在附件库选择附件时,如果非图片、视频、音频,那么就会作为链接插入。

#### Which issue(s) this PR fixes:

Fixes halo-dev/halo#2673

#### Screenshots:

![2023-02-17 21 02 43](https://user-images.githubusercontent.com/21301288/219660123-b910a4d5-32e6-4606-813e-c081720556d5.gif)

#### Special notes for your reviewer:

测试方式:

1. 测试从附件库选择非图片、视频、音频的时候是否会作为链接插入即可。

#### Does this PR introduce a user-facing change?

```release-note
Console 端默认编辑器支持以链接的形式插入非图片、音视频的附件。
```
  • Loading branch information
ruibaby authored Feb 24, 2023
1 parent 9490364 commit f7c0fd5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/modules/contents/attachments/composables/use-attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export function useAttachmentSelect(
},
};
}

if ("url" in attachment) {
return {
type: "image",
Expand All @@ -265,6 +266,7 @@ export function useAttachmentSelect(
},
};
}

if ("spec" in attachment) {
const { mediaType, displayName } = attachment.spec;
const { permalink } = attachment.status || {};
Expand Down Expand Up @@ -295,9 +297,23 @@ export function useAttachmentSelect(
},
};
}

return {
type: "text",
marks: [
{
type: "link",
attrs: {
href: permalink,
},
},
],
text: displayName,
};
}
})
.filter(Boolean) as Content[];

editor.value
?.chain()
.focus()
Expand Down

1 comment on commit f7c0fd5

@vercel
Copy link

@vercel vercel bot commented on f7c0fd5 Feb 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-halo-dev.vercel.app
ui-git-main-halo-dev.vercel.app
halo-admin-ui.vercel.app

Please sign in to comment.