jeawin-astro 3.0.32 → 3.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jeawin-astro",
3
- "version": "3.0.32",
3
+ "version": "3.0.35",
4
4
  "author": "chaegumi <chaegumi@qq.com>",
5
5
  "description": "",
6
6
  "license": "MIT",
@@ -60,7 +60,7 @@ const banners = await jeawinapi.get_nodes({ channel_id: 5 });
60
60
  {banners.nodes &&
61
61
  banners.nodes.map((banner: any, idx: number) => (
62
62
  <swiper-slide class:list={["swiper-slide", { hidden: idx > 0 }]}>
63
- {show_title ? (
63
+ {show_title && render_value(banner, 'show_text_block', '1') == '1' ? (
64
64
  <div class="relative h-full w-full">
65
65
  <div class="absolute inset-0 flex items-center justify-center text-white text-center p-4">
66
66
  <div class="p-2 bg-[rgba(0,0,0,0.5)]">
@@ -71,7 +71,6 @@ const banners = await jeawinapi.get_nodes({ channel_id: 5 });
71
71
  <h1 class="text-base md:text-3xl lg:text-4xl">{banner.node_title}</h1>
72
72
  )
73
73
  }
74
-
75
74
  <div class="text-xs line-clamp-2 md:line-clamp-none md:text-lg md:mt-4">{render_value(banner, 'sub_title')}</div>
76
75
  <Button tag_name="a" class="inline-block md:mt-2" href={render_url(render_value(banner, "linkurl"), base, null, url_suffix)}
77
76
  title={render_value(banner, 'btntext') || render_value(all_langs, 'read more')}>{render_value(banner, 'btntext') || render_value(all_langs, 'read more')}</Button>
@@ -0,0 +1,107 @@
1
+ ---
2
+ import {render_value, render_lang} from "../scripts/util.js";
3
+ const {jeawin_form_api_domain, jeawinapi, all_langs} = Astro.locals;
4
+ let chatbot_status = false;
5
+ let prompts = [];
6
+ let assistant_name = '';
7
+ let assistant_avatar = '';
8
+ let assistant_tagline = '';
9
+ try{
10
+ const res = await jeawinapi.get_chatbot();
11
+ // console.log(res);
12
+ if(res.code){
13
+
14
+ }else{
15
+ if(res.status){
16
+ chatbot_status = true;
17
+ prompts = render_value(res, 'prompts') || [];
18
+ assistant_name = res.assistant_name;
19
+ assistant_avatar = res.assistant_avatar;
20
+ assistant_tagline = res.assistant_tagline;
21
+ }
22
+ }
23
+ }catch{
24
+
25
+ }
26
+
27
+ ---
28
+ {
29
+ chatbot_status ? (
30
+ <Fragment>
31
+ <link rel="stylesheet" crossorigin href="https://img.jeawincdn.com/resource/web-chatbot-ui/dist/index.css" />
32
+ <script is:inline type="module" crossorigin="true" src="https://img.jeawincdn.com/resource/web-chatbot-ui/dist/index.js"></script>
33
+ <script define:vars={{
34
+ jeawin_form_api_domain:jeawin_form_api_domain,
35
+ assistant_name: assistant_name,
36
+ assistant_avatar: assistant_avatar,
37
+ assistant_tagline: assistant_tagline,
38
+ prompts: prompts,
39
+ title: render_lang(all_langs, 'JEAWIN ASSISTANT'),
40
+ composerPlaceholder: render_lang(all_langs, 'Please enter your question and use Shift+Enter to wrap the line.')
41
+ }}>
42
+
43
+ let new_prompts = [];
44
+ for(const p of prompts){
45
+ new_prompts.push({prompt: p});
46
+ }
47
+ // @ts-ignore
48
+ window.CHATBOT_CONFIG = {
49
+ title: title,
50
+ endpoint: `${jeawin_form_api_domain}/api.php?c=chatbot&m=chat`, // 可以替换为 https://{your-fc-http-trigger-domain}/chat
51
+ displayByDefault: false, // 默认不展示 AI 助手聊天框
52
+ aiChatOptions: { // aiChatOptions 中 options 会传递 aiChat 组件,自定义取值参考:https://docs.nlkit.com/nlux/reference/ui/ai-chat
53
+ conversationOptions: { // 自定义取值参考:https://docs.nlkit.com/nlux/reference/ui/ai-chat#conversation-options
54
+ conversationStarters: new_prompts
55
+ },
56
+ displayOptions: { // 自定义取值参考:https://docs.nlkit.com/nlux/reference/ui/ai-chat#display-options
57
+ height: 600,
58
+ },
59
+ composerOptions:{
60
+ placeholder: composerPlaceholder,
61
+ // hideStopButton: true
62
+ },
63
+ personaOptions: { // 自定义取值参考:https://docs.nlkit.com/nlux/reference/ui/ai-chat#chat-personas
64
+ assistant: {
65
+ name: assistant_name,
66
+ // AI 助手的图标
67
+ avatar: assistant_avatar,
68
+ tagline: assistant_tagline,
69
+ }
70
+ }
71
+ },
72
+ dataProcessor: {
73
+ /**
74
+ * 在向后端大模型应用发起请求前改写 Prompt。
75
+ * 比如可以用于总结网页场景,在发送前将网页内容包含在内,同时避免在前端显示这些内容。
76
+ * @param {string} prompt - 用户输入的 Prompt
77
+ * @param {string} - 改写后的 Prompt
78
+ */
79
+ rewritePrompt(prompt) {
80
+ return prompt;
81
+ }
82
+ }
83
+ };
84
+ </script>
85
+ <style>
86
+ :root {
87
+ /* webchat 工具栏的颜色 */
88
+ --webchat-toolbar-background-color: #1464E4;
89
+ /* webchat 工具栏文字和按钮的颜色 */
90
+ --webchat-toolbar-text-color: #FFF;
91
+ }
92
+ /* webchat 对话框如果被遮挡,可以尝试通过 z-index、bottom、right 等设置来调整位置 */
93
+ .webchat-container {
94
+ z-index: 2147483647;
95
+ bottom: 10px;
96
+ right: 10px;
97
+ }
98
+ /* webchat 的唤起按钮如果被遮挡,可以尝试通过 z-index、bottom、right 等设置来调整位置 */
99
+ .webchat-bubble-tip {
100
+ z-index: 2147483646;
101
+ bottom: 20px;
102
+ right: 20px;
103
+ }
104
+ </style>
105
+ </Fragment>
106
+ ) : null
107
+ }
@@ -57,6 +57,7 @@ export {default as Tabs} from "./tabs.astro";
57
57
  export {default as TagsCategoryList} from "./tags_category_list.astro";
58
58
  export {default as Vimeo} from "./vimeo.astro";
59
59
  export {default as Youtube} from "./youtube.astro";
60
+ export {default as Chatbot} from "./chatbot.astro";
60
61
 
61
62
  export * from "./bgs/index.ts";
62
63
  export * from "./blocks/index.ts";
@@ -1,4 +1,5 @@
1
1
  export {default as jeawinRuntimeConfig} from "./jeawin-runtime-config/index.ts";
2
2
  export {default as jeawinAstroPagefind} from "./jeawin-astro-pagefind/index.ts";
3
3
  export {default as jeawinCommonRoute} from "./jeawin-common-route/index.ts";
4
- export {default as jeawinSiteClearcache} from "./jeawin-site-clearcache/index.ts";
4
+ export {default as jeawinSiteClearcache} from "./jeawin-site-clearcache/index.ts";
5
+ export {default as jeawinAstroToolbar} from "./jeawin-astro-toolbar/index.ts";
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 定制toolbar
3
+ *
4
+ * @package jeawin-astro
5
+ * @author Chaegumi
6
+ * @copyright Copyright (c) 2025-2099 jeawin.com
7
+ * @email chaegumi@jeawin.com
8
+ * @filesource
9
+ */
10
+ import {defineIntegration, addVirtualImports,createResolver} from "astro-integration-kit";
11
+ const cacache = await import('cacache');
12
+ export default defineIntegration({
13
+ name: "jeawin-astro-toolbar",
14
+ setup({name}) {
15
+ const { resolve } = createResolver(import.meta.url);
16
+ return {
17
+ hooks:{
18
+ "astro:config:setup":(params) => {
19
+ const addDevToolbarApp = params.addDevToolbarApp;
20
+
21
+ addDevToolbarApp({
22
+ id: 'jeawin-clear-cache',
23
+ name: '清除缓存',
24
+ icon: '<svg xmlns="http://www.w3.org/2000/svg" width="448" height="512" viewBox="0 0 448 512"><path fill="currentColor" d="M135.2 17.7C140.6 6.8 151.7 0 163.8 0h120.4c12.1 0 23.2 6.8 28.6 17.7L320 32h96c17.7 0 32 14.3 32 32s-14.3 32-32 32H32C14.3 96 0 81.7 0 64s14.3-32 32-32h96zM32 128h384v320c0 35.3-28.7 64-64 64H96c-35.3 0-64-28.7-64-64zm96 64c-8.8 0-16 7.2-16 16v224c0 8.8 7.2 16 16 16s16-7.2 16-16V208c0-8.8-7.2-16-16-16m96 0c-8.8 0-16 7.2-16 16v224c0 8.8 7.2 16 16 16s16-7.2 16-16V208c0-8.8-7.2-16-16-16m96 0c-8.8 0-16 7.2-16 16v224c0 8.8 7.2 16 16 16s16-7.2 16-16V208c0-8.8-7.2-16-16-16"/></svg>',
25
+ entrypoint: resolve('./toolbar.ts')
26
+ })
27
+ },
28
+ // "astro:server:done": () => {
29
+
30
+ // },
31
+ // "astro:build:start":() => {
32
+
33
+ // }
34
+ }
35
+ }
36
+ }
37
+ })
@@ -0,0 +1,18 @@
1
+ import {defineToolbarApp} from "astro/toolbar";
2
+
3
+ export default defineToolbarApp({
4
+ init(canvas, app, server){
5
+ // const text = document.createTextNode('Hello World!');
6
+ // canvas.appendChild(text);
7
+ app.onToggled(async (options) => {
8
+ // 清除缓存
9
+ await fetch('/clear_cache');
10
+ alert('清除缓存成功');
11
+
12
+ });
13
+ },
14
+ beforeTogglingOff(){
15
+ const confirmation = window.confirm('Really exit?');
16
+ return confirmation;
17
+ }
18
+ })
@@ -1,129 +1,166 @@
1
- export default class JeawinApi {
2
- constructor({ apikey, api_domain, api_path }: {
3
- apikey: any;
4
- api_domain?: string;
5
- api_path?: string;
6
- });
7
- keyv: any;
8
- apikey: string;
9
- api_domain: string;
10
- api_path: string;
11
- server_api_url: string;
12
- jeawinFetch(url: any, options: any): Promise<any>;
13
- delete_cache(): Promise<void>;
14
- /**
15
- * 首页数据
16
- */
17
- get_index(): Promise<any>;
18
- /**
19
- * 分享按钮
20
- */
21
- get_share_button(params: any): Promise<any>;
22
- /**
23
- * 评论表单
24
- */
25
- get_comment_form(params: any): Promise<any>;
26
- /**
27
- * 统计代码
28
- */
29
- get_stats(params: any): Promise<any>;
30
- /**
31
- * 作者信息
32
- */
33
- get_author_info(params: any): Promise<any>;
34
- /**
35
- * 国家列表
36
- */
37
- get_country(): Promise<any>;
38
- /**
39
- * 获取glossary
40
- */
41
- get_glossary(): Promise<any>;
42
- /**
43
- * 获取表单
44
- */
45
- get_form(params: any): Promise<any>;
46
- get_all_langs(): Promise<any>;
47
- /**
48
- * 获取多语言
49
- */
50
- get_lang(params: any): Promise<any>;
51
- /**
52
- * 所有的uri
53
- */
54
- get_all_uri(): Promise<any>;
55
- /**
56
- * 全部site_option
57
- */
58
- get_site_options(): Promise<{
59
- data: any;
60
- siteinfo: any;
61
- base_url: any;
62
- channeluriarr: any;
63
- categoryuriarr: any;
64
- nodeuriarr: any;
65
- menuuriarr: any;
66
- }>;
67
- /**
68
- * 单个site_option
69
- */
70
- get_site_option(params: any): Promise<any>;
71
- /**
72
- * 菜单
73
- */
74
- get_menus(params: any): Promise<any>;
75
- /**
76
- * 树形菜单
77
- */
78
- get_menu_tree(params: any): Promise<any>;
79
- /**
80
- * 区块列表
81
- */
82
- get_blocks(): Promise<void>;
83
- /**
84
- * 单个区块
85
- */
86
- get_block(params: any): Promise<any>;
87
- /**
88
- * 单个栏目
89
- */
90
- get_channel(params: any): Promise<any>;
91
- /**
92
- * 全部类别
93
- */
94
- get_all_categories(params: any): Promise<any>;
95
- /**
96
- * 类别
97
- */
98
- get_categories(params: any): Promise<any>;
99
- /**
100
- * 类别树形
101
- */
102
- get_category_tree(params: any): Promise<any>;
103
- /**
104
- * 单个类别
105
- */
106
- get_category(params: any): Promise<any>;
107
- /**
108
- * 内容列表
109
- */
110
- get_nodes(params: any): Promise<any>;
111
- /**
112
- * 相关内容列表
113
- */
114
- get_rel_nodes(params: any): Promise<any>;
115
- /**
116
- * 单个内容
117
- */
118
- get_node(params: any): Promise<any>;
119
- get_prevnext_node(params: any): Promise<any>;
120
- get_channel_url(params: any): Promise<any>;
121
- get_category_url(params: any): Promise<any>;
122
- get_node_url(params: any): Promise<any>;
123
- get_friendlinks(params: any): Promise<any[]>;
124
- get_choose_language(params: any): Promise<any>;
125
- get_theme_render_image(params: any): Promise<any>;
126
- get_theme_image_url(params: any): Promise<any>;
127
- get_sitemap(): Promise<any>;
128
- get_filter_links(params: any): Promise<any>;
129
- }
1
+ export default class JeawinApi {
2
+ constructor({ apikey, api_domain, api_path }: {
3
+ apikey: any;
4
+ api_domain?: string;
5
+ api_path?: string;
6
+ });
7
+ cachePath: string;
8
+ apikey: string;
9
+ api_domain: string;
10
+ api_path: string;
11
+ server_api_url: string;
12
+ jeawinFetch(url: any, options: any): Promise<any>;
13
+ delete_cache(): Promise<void>;
14
+ /**
15
+ * 首页数据
16
+ */
17
+ get_index(): Promise<any>;
18
+ /**
19
+ * 分享按钮
20
+ */
21
+ get_share_button(params: any): Promise<any>;
22
+ /**
23
+ * 评论表单
24
+ */
25
+ get_comment_form(params: any): Promise<any>;
26
+ /**
27
+ * 统计代码
28
+ */
29
+ get_stats(params: any): Promise<any>;
30
+ /**
31
+ * 作者信息
32
+ */
33
+ get_author_info(params: any): Promise<any>;
34
+ /**
35
+ * 国家列表
36
+ */
37
+ get_country(): Promise<any>;
38
+ /**
39
+ * 获取glossary
40
+ */
41
+ get_glossary(): Promise<any>;
42
+ /**
43
+ * 获取表单
44
+ */
45
+ get_form(params: any): Promise<any>;
46
+ /**
47
+ * 全部翻译
48
+ */
49
+ get_all_langs(): Promise<any>;
50
+ /**
51
+ * 获取单个内容多语言
52
+ */
53
+ get_lang(params: any): Promise<any>;
54
+ /**
55
+ * 所有的uri
56
+ */
57
+ get_all_uri(): Promise<any>;
58
+ /**
59
+ * 全部site_option
60
+ */
61
+ get_site_options(): Promise<{
62
+ data: any;
63
+ siteinfo: any;
64
+ base_url: any;
65
+ channeluriarr: any;
66
+ categoryuriarr: any;
67
+ nodeuriarr: any;
68
+ menuuriarr: any;
69
+ }>;
70
+ /**
71
+ * 单个site_option
72
+ */
73
+ get_site_option(params: any): Promise<any>;
74
+ /**
75
+ * 菜单
76
+ */
77
+ get_menus(params: any): Promise<any>;
78
+ /**
79
+ * 树形菜单
80
+ */
81
+ get_menu_tree(params: any): Promise<any>;
82
+ /**
83
+ * 区块列表
84
+ */
85
+ get_blocks(): Promise<void>;
86
+ /**
87
+ * 单个区块
88
+ */
89
+ get_block(params: any): Promise<any>;
90
+ /**
91
+ * 单个栏目
92
+ */
93
+ get_channel(params: any): Promise<any>;
94
+ /**
95
+ * 全部类别
96
+ */
97
+ get_all_categories(params: any): Promise<any>;
98
+ /**
99
+ * 类别
100
+ */
101
+ get_categories(params: any): Promise<any>;
102
+ /**
103
+ * 类别树形
104
+ */
105
+ get_category_tree(params: any): Promise<any>;
106
+ /**
107
+ * 单个类别
108
+ */
109
+ get_category(params: any): Promise<any>;
110
+ /**
111
+ * 内容列表
112
+ */
113
+ get_nodes(params: any): Promise<any>;
114
+ /**
115
+ * 相关内容列表
116
+ */
117
+ get_rel_nodes(params: any): Promise<any>;
118
+ /**
119
+ * 单个内容
120
+ */
121
+ get_node(params: any): Promise<any>;
122
+ /**
123
+ * 上一个下一个
124
+ */
125
+ get_prevnext_node(params: any): Promise<any>;
126
+ /**
127
+ * 得到栏目url
128
+ */
129
+ get_channel_url(params: any): Promise<any>;
130
+ /**
131
+ * 类别url
132
+ */
133
+ get_category_url(params: any): Promise<any>;
134
+ /**
135
+ * 内容url
136
+ */
137
+ get_node_url(params: any): Promise<any>;
138
+ /**
139
+ * 友情链接html
140
+ */
141
+ get_friendlinks(params: any): Promise<any[]>;
142
+ /**
143
+ * 多语言切换html
144
+ */
145
+ get_choose_language(params: any): Promise<any>;
146
+ /**
147
+ * 图片html
148
+ */
149
+ get_theme_render_image(params: any): Promise<any>;
150
+ /**
151
+ * 得到图片优化后的url
152
+ */
153
+ get_theme_image_url(params: any): Promise<any>;
154
+ /**
155
+ * sitemap的html
156
+ */
157
+ get_sitemap(): Promise<any>;
158
+ /**
159
+ * 过滤条件html
160
+ */
161
+ get_filter_links(params: any): Promise<any>;
162
+ /**
163
+ * 获取杰赢助手配置
164
+ */
165
+ get_chatbot(): Promise<any>;
166
+ }
@@ -1173,4 +1173,22 @@ export default class JeawinApi {
1173
1173
  return res;
1174
1174
  }
1175
1175
 
1176
+ /**
1177
+ * 获取杰赢助手配置
1178
+ */
1179
+ async get_chatbot(){
1180
+ consolelog('get_chatbot start at');
1181
+ const res = await this.jeawinFetch(`${this.server_api_url}&m=chatbot`, {
1182
+ verbose: fetchVerbose,
1183
+ duration: fetchCacheDuration,
1184
+ type: "json"
1185
+ });
1186
+ consolelog('get_chatbot end at');
1187
+ if (Number(res.code) === 0) {
1188
+ return res.data;
1189
+ }
1190
+
1191
+ return res;
1192
+ }
1193
+
1176
1194
  }