Skip to content

Commit

Permalink
feat: 本地图床复制和插入markdown链接改为相对url #303
Browse files Browse the repository at this point in the history
  • Loading branch information
Mereithhh committed Jun 26, 2023
1 parent 51e21d8 commit 3290dec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/admin/src/components/Editor/imgUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const uploadImg = async (file: File) => {
});
const data = await res.json();
if (data && data.statusCode == 200) {
const url = getImgLink(data.data.src);
const url = getImgLink(data.data.src, false);
copyImgLink(data.data.src, true, '上传成功! ');
return url;
} else {
Expand Down
10 changes: 9 additions & 1 deletion packages/admin/src/pages/Static/img/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ const ImgPage = () => {
copyImgLink(clickItem.realPath);
break;
case 'copyMarkdown':
copyImgLink(clickItem.realPath, true);
copyImgLink(clickItem.realPath, true, undefined, false);
break;
case 'copyMarkdownAbsolutely':
copyImgLink(clickItem.realPath, true, undefined, true);
break;
case 'delete':
Modal.confirm({
Expand Down Expand Up @@ -216,6 +219,7 @@ const ImgPage = () => {
data.src,
true,
data.isNew ? '剪切板图片上传成功! ' : '剪切板图片已存在! ',
false
);

fetchData();
Expand All @@ -232,6 +236,7 @@ const ImgPage = () => {
info?.response?.data?.src,
true,
info?.response?.data?.isNew ? `${info.name} 上传成功! ` : `${info.name} 已存在! `,
false
);

fetchData();
Expand All @@ -250,6 +255,9 @@ const ImgPage = () => {
<Item onClick={handleItemClick} data="copyMarkdown">
复制 Markdown 链接
</Item>
<Item onClick={handleItemClick} data="copyMarkdownAbsolutely">
复制完整 Markdown 链接
</Item>
<Separator />
<Item onClick={handleItemClick} data="download">
下载
Expand Down
12 changes: 8 additions & 4 deletions packages/admin/src/pages/Static/img/tools.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { writeClipBoardText } from '@/services/van-blog/clipboard';
import { message } from 'antd';
import { StaticItem } from '../type';
export const getImgLink = (realPath) => {
let url = `${window.location.protocol}//${window.location.host}${realPath}`;
export const getImgLink = (realPath, autoCompleteHost = true) => {
let url = realPath;
if (realPath.includes('http://') || realPath.includes('https://')) {
url = realPath;
} else {
if (autoCompleteHost) {
url = `${window.location.protocol}//${window.location.host}${realPath}`;
}
}
url = url.replace(/\)/g, '%29');
url = url.replace(/\(/g, '%28');
return url;
};
export const copyImgLink = (realPath, isMarkdown = false, info = undefined) => {
let url = getImgLink(realPath);
export const copyImgLink = (realPath, isMarkdown = false, info = undefined, autoCompleteHost= true) => {
let url = getImgLink(realPath, autoCompleteHost);
if (isMarkdown) {
url = `![](${url})`;
}
Expand Down

0 comments on commit 3290dec

Please sign in to comment.