From f6eb4d5417797ebd603a35c5b3190c09a919f584 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Tue, 15 Mar 2022 20:01:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8F=92=E4=BB=B6=E4=B8=AD=E5=BF=83?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E6=A1=A3=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/cache/cache.ts | 3 ++- shared/index.tsx | 1 + shared/utils/url-helper.ts | 10 ++++++++++ web/.ministarrc.js | 8 ++++++++ web/plugins/com.msgbyte.webview/README.md | 7 +++++++ web/plugins/com.msgbyte.webview/manifest.json | 1 + web/src/components/Markdown.less | 18 ++++++++++++++++++ web/src/components/Markdown.tsx | 1 + web/src/plugin/PluginStore/Item.tsx | 3 ++- web/src/plugin/builtin.ts | 1 + web/src/styles/global.less | 4 ++++ web/src/styles/index.ts | 2 +- web/src/styles/tailwind.less | 19 +++++++++++++++++++ 13 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 shared/utils/url-helper.ts create mode 100644 web/plugins/com.msgbyte.webview/README.md create mode 100644 web/src/components/Markdown.less create mode 100644 web/src/styles/tailwind.less diff --git a/shared/cache/cache.ts b/shared/cache/cache.ts index 14f11249..54cfd9f2 100644 --- a/shared/cache/cache.ts +++ b/shared/cache/cache.ts @@ -8,6 +8,7 @@ import { PluginManifest, } from '../model/plugin'; import { fetchUserInfo, UserBaseInfo } from '../model/user'; +import { parseUrlStr } from '../utils/url-helper'; import { queryClient } from './index'; /** @@ -68,7 +69,7 @@ export async function getCachedRegistryPlugins(): Promise { list.map((manifest) => ({ ...manifest, // 后端url策略。根据前端的url在获取时自动变更为当前链接的后端地址 - url: String(manifest.url).replace('{BACKEND}', getServiceUrl()), + url: parseUrlStr(manifest.url), })) ) .catch(() => []), diff --git a/shared/index.tsx b/shared/index.tsx index 767f5a66..3eabf894 100644 --- a/shared/index.tsx +++ b/shared/index.tsx @@ -193,4 +193,5 @@ export { isValidJson } from './utils/json-helper'; export { MessageHelper } from './utils/message-helper'; export { uploadFile } from './utils/upload-helper'; export type { UploadFileResult } from './utils/upload-helper'; +export { parseUrlStr } from './utils/url-helper'; export { sleep } from './utils/utils'; diff --git a/shared/utils/url-helper.ts b/shared/utils/url-helper.ts new file mode 100644 index 00000000..672a71fa --- /dev/null +++ b/shared/utils/url-helper.ts @@ -0,0 +1,10 @@ +import { getServiceUrl } from '../manager/service'; + +/** + * 解析url, 将中间的常量替换成变量 + * @param originUrl 原始Url + * @returns 解析后的url + */ +export function parseUrlStr(originUrl: string): string { + return String(originUrl).replace('{BACKEND}', getServiceUrl()); +} diff --git a/web/.ministarrc.js b/web/.ministarrc.js index 0471b4d1..ee2f50c8 100644 --- a/web/.ministarrc.js +++ b/web/.ministarrc.js @@ -18,6 +18,14 @@ module.exports = { ), dest: path.resolve(__dirname, `./dist/plugins/${pluginName}/assets/`), }, + { + src: path.resolve( + __dirname, + `./plugins/${pluginName}`, + './README.md' + ), + dest: path.resolve(__dirname, `./dist/plugins/${pluginName}/`), + }, ], }), replace({ diff --git a/web/plugins/com.msgbyte.webview/README.md b/web/plugins/com.msgbyte.webview/README.md new file mode 100644 index 00000000..cc585504 --- /dev/null +++ b/web/plugins/com.msgbyte.webview/README.md @@ -0,0 +1,7 @@ +## com.msgbyte.webview + +为 `Tailchat` 增加 `Webview` 能力 + +### Usage + +在 群组设置 -> 创建面板 可以添加网页面板。 diff --git a/web/plugins/com.msgbyte.webview/manifest.json b/web/plugins/com.msgbyte.webview/manifest.json index 83d89b9a..be330d14 100644 --- a/web/plugins/com.msgbyte.webview/manifest.json +++ b/web/plugins/com.msgbyte.webview/manifest.json @@ -5,5 +5,6 @@ "version": "0.0.0", "author": "msgbyte", "description": "为群组提供创建网页面板的功能", + "documentUrl": "/plugins/com.msgbyte.webview/README.md", "requireRestart": false } diff --git a/web/src/components/Markdown.less b/web/src/components/Markdown.less new file mode 100644 index 00000000..19849981 --- /dev/null +++ b/web/src/components/Markdown.less @@ -0,0 +1,18 @@ +.tailchat-markdown { + h1, + h2, + h3, + h4, + h5, + h6 { + word-break: break-all; + margin: 20px 0; + line-height: 1.2; + text-align: left; + font-weight: bold; + } + + code { + @apply px-2 py-1 bg-black bg-opacity-20 rounded; + } +} diff --git a/web/src/components/Markdown.tsx b/web/src/components/Markdown.tsx index 03ab6971..192d63f3 100644 --- a/web/src/components/Markdown.tsx +++ b/web/src/components/Markdown.tsx @@ -1,6 +1,7 @@ import React, { useCallback } from 'react'; import { isValidStr } from 'tailchat-shared'; import { Loadable } from './Loadable'; +import './Markdown.less'; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore diff --git a/web/src/plugin/PluginStore/Item.tsx b/web/src/plugin/PluginStore/Item.tsx index bf0cb0bc..4a2125f7 100644 --- a/web/src/plugin/PluginStore/Item.tsx +++ b/web/src/plugin/PluginStore/Item.tsx @@ -3,6 +3,7 @@ import { Button, Space } from 'antd'; import React, { useCallback, useState } from 'react'; import { isValidStr, + parseUrlStr, PluginManifest, showAlert, showToasts, @@ -51,7 +52,7 @@ export const PluginStoreItem: React.FC<{ openModal( - + ); }, [manifest]); diff --git a/web/src/plugin/builtin.ts b/web/src/plugin/builtin.ts index 6c17a7cd..ba28cd59 100644 --- a/web/src/plugin/builtin.ts +++ b/web/src/plugin/builtin.ts @@ -13,6 +13,7 @@ export const builtinPlugins: PluginManifest[] = [ version: '0.0.0', author: 'msgbyte', description: '为群组提供创建网页面板的功能', + documentUrl: '/plugins/com.msgbyte.webview/README.md', requireRestart: false, }, { diff --git a/web/src/styles/global.less b/web/src/styles/global.less index e317f750..87d530d3 100644 --- a/web/src/styles/global.less +++ b/web/src/styles/global.less @@ -52,6 +52,10 @@ &.dark { @apply text-typography-dark bg-content-dark; + h1,h2,h3,h4,h5,h6 { + @apply text-typography-dark; + } + ::-webkit-scrollbar-corner { background-color: transparent; } diff --git a/web/src/styles/index.ts b/web/src/styles/index.ts index a7681a2b..ad3be091 100644 --- a/web/src/styles/index.ts +++ b/web/src/styles/index.ts @@ -1,4 +1,4 @@ import 'antd/dist/antd.css'; import './antd/index.less'; -import 'tailwindcss/tailwind.css'; +import './tailwind.less'; import './global.less'; diff --git a/web/src/styles/tailwind.less b/web/src/styles/tailwind.less new file mode 100644 index 00000000..602e0293 --- /dev/null +++ b/web/src/styles/tailwind.less @@ -0,0 +1,19 @@ +@tailwind base; + +@layer base { + h1 { + @apply text-2xl; + } + + h2 { + @apply text-xl; + } + + h3 { + @apply text-lg; + } +} + +@tailwind components; + +@tailwind utilities;