artalk 2.2.7 → 2.2.8

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/index.html CHANGED
@@ -1,5 +1,5 @@
1
1
  <!DOCTYPE html>
2
- <html>
2
+ <html lang="zh-CN">
3
3
  <head>
4
4
  <meta charset="UTF-8">
5
5
  <title>Artalk DEMO</title>
@@ -16,7 +16,8 @@
16
16
  .title > a:hover { margin-left:0 }
17
17
  .title > a > span { opacity:0 }
18
18
  .title > a:hover>span { opacity:1 }
19
- .desc { font-size:12px;color:#757e91 }
19
+ .desc { font-size:12px;color:#697182 }
20
+ body.dark-mode .desc { color:#848da3 }
20
21
  .social { margin-top:20px }
21
22
  .social > a:not(:last-child) { margin-right:2px }
22
23
  @media only screen and (max-width: 768px) {
@@ -26,7 +27,7 @@
26
27
  }
27
28
  .float-btn { user-select: none;bottom: 25px;display: block;cursor: pointer;text-align: center;width: 60px;height: 37px;line-height: 37px;font-size: 13px;color: #757e91;background: #fff;opacity: 0.8;border-radius: 4px;border: 1px solid #eceff2;position: fixed; }
28
29
  .to-night { z-index: 99999;left: 25px;background: #1e2223;color: #fff; }
29
- body.dark-mode .to-night { background: #fff;border: 1px solid #2d3235;color: #0083ff; }
30
+ body.dark-mode .to-night { background: #006fd9;border: 1px solid #2d3235;color: #fff; }
30
31
  .to-top { right: 25px; }
31
32
  </style>
32
33
  <!--<link rel="stylesheet"
@@ -45,11 +46,11 @@
45
46
  <div class="title"><a href="https://github.com/ArtalkJS/Artalk" target="_blank"><span>『 </span>Artalk<span> 』</span></a></div>
46
47
  <div class="desc">一款简洁的自托管评论系统 <span id="ArtalkPV"></span></div>
47
48
  <div class="social">
48
- <a href="https://www.npmjs.com/package/artalk" target="_blank"><img src="https://img.shields.io/npm/v/artalk.svg?style=flat-square"></a>
49
- <a href="https://www.npmjs.com/package/artalk" target="_blank"><img src="https://img.shields.io/npm/dt/artalk.svg?style=flat-square"></a>
50
- <a href="https://github.com/ArtalkJS/Artalk/commits/master" target="_blank"><img src="https://img.shields.io/github/last-commit/ArtalkJS/Artalk?style=flat-square"></a>
51
- <a href="https://github.com/ArtalkJS/Artalk/blob/master/LICENSE" target="_blank"><img src="https://img.shields.io/github/license/ArtalkJS/Artalk.svg?style=flat-square"></a>
52
- <a href="https://github.com/ArtalkJS/Artalk" target="_blank"><img src="https://img.shields.io/github/stars/ArtalkJS/Artalk?style=flat-square"></a>
49
+ <a href="https://www.npmjs.com/package/artalk" aria-label="npm package version" target="_blank"><img src="https://img.shields.io/npm/v/artalk.svg?style=flat-square"></a>
50
+ <a href="https://www.npmjs.com/package/artalk" aria-label="npm package download number" target="_blank"><img src="https://img.shields.io/npm/dt/artalk.svg?style=flat-square"></a>
51
+ <a href="https://github.com/ArtalkJS/Artalk/commits/master" aria-label="last commit" target="_blank"><img src="https://img.shields.io/github/last-commit/ArtalkJS/Artalk?style=flat-square"></a>
52
+ <a href="https://github.com/ArtalkJS/Artalk/blob/master/LICENSE" aria-label="open source license" target="_blank"><img src="https://img.shields.io/github/license/ArtalkJS/Artalk.svg?style=flat-square"></a>
53
+ <a href="https://github.com/ArtalkJS/Artalk" aria-label="GitHub star number" target="_blank"><img src="https://img.shields.io/github/stars/ArtalkJS/Artalk?style=flat-square"></a>
53
54
  </div>
54
55
  </div>
55
56
  <div class="card atk-fade-in">
@@ -66,6 +67,7 @@
66
67
  pageTitle: 'Artalk Home',
67
68
  server: (import.meta.env.MODE === 'development') ? 'http://localhost:23366' : 'https://artalk.qwqaq.com',
68
69
  site: 'ArtalkDemo',
70
+ //useBackendConf: true,
69
71
  });
70
72
 
71
73
  window.artalk = artalk;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "artalk",
3
- "version": "2.2.7",
4
- "backendMinVersion": "2.1.2",
3
+ "version": "2.2.8",
4
+ "backendMinVersion": "2.1.4",
5
5
  "license": "LGPL-3.0",
6
6
  "description": "A Selfhosted Comment System",
7
7
  "keywords": [
package/src/api/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { CommentData, ListData, UserData, PageData, SiteData, NotifyData } from '~/types/artalk-data'
2
+ import ArtalkConfig from '~/types/artalk-config'
2
3
  import Context from '../context'
3
4
  import { Fetch, ToFormData, POST, GET } from './request'
4
5
  import * as Utils from '../lib/utils'
@@ -294,7 +295,22 @@ export default class Api {
294
295
 
295
296
  const json = await Fetch(this.ctx, `${this.baseURL}/img-upload`, init)
296
297
  return ((json.data || {}) as any) as { img_file: string, img_url: string }
298
+ }
299
+
300
+ /** 获取配置 */
301
+ public async conf() {
302
+ const data = await POST<any>(this.ctx, `${this.baseURL}/conf`)
303
+ const conf = (data.frontend_conf || {}) as ArtalkConfig
304
+
305
+ // Patch: `emoticons` config string to json
306
+ if (conf.emoticons && typeof conf.emoticons === "string") {
307
+ conf.emoticons = conf.emoticons.trim()
308
+ if (conf.emoticons.startsWith("[") || conf.emoticons.startsWith("{")) {
309
+ conf.emoticons = JSON.parse(conf.emoticons) // pase json
310
+ }
311
+ }
297
312
 
313
+ return conf
298
314
  }
299
315
 
300
316
  // ============================
package/src/artalk.ts CHANGED
@@ -13,6 +13,7 @@ import SidebarLayer from './components/sidebar-layer'
13
13
  import Layer, { GetLayerWrap } from './components/layer'
14
14
  import Api from './api'
15
15
  import * as Utils from './lib/utils'
16
+ import * as Ui from './lib/ui'
16
17
 
17
18
  /**
18
19
  * Artalk
@@ -21,18 +22,18 @@ import * as Utils from './lib/utils'
21
22
  export default class Artalk {
22
23
  public static readonly defaults: ArtalkConfig = defaults
23
24
 
24
- public ctx: Context
25
- public conf: ArtalkConfig
26
- public $root: HTMLElement
25
+ public ctx!: Context
26
+ public conf!: ArtalkConfig
27
+ public $root!: HTMLElement
27
28
 
28
- public checkerLauncher: CheckerLauncher
29
- public editor: Editor
30
- public list: List
31
- public sidebarLayer: SidebarLayer
29
+ public checkerLauncher!: CheckerLauncher
30
+ public editor!: Editor
31
+ public list!: List
32
+ public sidebarLayer!: SidebarLayer
32
33
 
33
34
  constructor (customConf: ArtalkConfig) {
34
35
  // 配置
35
- this.conf = { ...Artalk.defaults, ...customConf }
36
+ this.conf = Utils.mergeDeep(Artalk.defaults, customConf)
36
37
  this.conf.server = this.conf.server.replace(/\/$/, '').replace(/\/api\/?$/, '')
37
38
 
38
39
  // 默认 pageKey
@@ -66,10 +67,25 @@ export default class Artalk {
66
67
  // 界面初始化
67
68
  this.$root.classList.add('artalk')
68
69
  this.$root.innerHTML = ''
69
- this.initLayer()
70
- this.initDarkMode()
71
70
 
71
+ // 初始化组件
72
+ if (this.conf.useBackendConf) {
73
+ // 复用后端的配置
74
+ // @ts-ignore
75
+ return (async () => {
76
+ await this.loadConfRemote()
77
+ this.initCore()
78
+ return this // Promise<Artalk>
79
+ })()
80
+ }
81
+
82
+ this.initCore()
83
+ }
84
+
85
+ private initCore() {
72
86
  // 组件初始化
87
+ this.initLayer()
88
+ this.initDarkMode()
73
89
  this.checkerLauncher = new CheckerLauncher(this.ctx)
74
90
  Utils.initMarked(this.ctx) // 初始化 marked
75
91
 
@@ -102,6 +118,17 @@ export default class Artalk {
102
118
  })
103
119
  }
104
120
 
121
+ /** 获取远程配置 */
122
+ private async loadConfRemote() {
123
+ Ui.showLoading(this.$root)
124
+ let backendConf = {}
125
+ try {
126
+ backendConf = await (new Api(this.ctx)).conf()
127
+ } catch (err) { console.error("配置远程获取失败", err) }
128
+ this.ctx.conf = Utils.mergeDeep(this.ctx.conf, backendConf)
129
+ Ui.hideLoading(this.$root)
130
+ }
131
+
105
132
  /** 事件绑定 · 初始化 */
106
133
  private initEventBind() {
107
134
  // 锚点快速跳转评论
@@ -38,7 +38,7 @@ export default class Pagination {
38
38
  `<div class="atk-pagination-wrap">
39
39
  <div class="atk-pagination">
40
40
  <div class="atk-btn atk-btn-prev">Prev</div>
41
- <input type="text" class="atk-input" />
41
+ <input type="text" class="atk-input" aria-label="Enter the number of page" />
42
42
  <div class="atk-btn atk-btn-next">Next</div>
43
43
  </div>
44
44
  </div>`)
package/src/defaults.ts CHANGED
@@ -40,6 +40,7 @@ const defaults: ArtalkConfig = {
40
40
  imgUpload: true,
41
41
  reqTimeout: 15000,
42
42
  versionCheck: true,
43
+ useBackendConf: false,
43
44
  }
44
45
 
45
46
  export default defaults
package/src/lib/utils.ts CHANGED
@@ -293,3 +293,33 @@ export function getURLBasedOnApi(ctx: Context, path: string) {
293
293
  export function getURLBasedOn(baseURL: string, path: string) {
294
294
  return `${baseURL.replace(/\/$/, '')}/${path.replace(/^\//, '')}`
295
295
  }
296
+
297
+ /**
298
+ * Performs a deep merge of `source` into `target`.
299
+ * Mutates `target` only but not its objects and arrays.
300
+ *
301
+ * @author inspired by [jhildenbiddle](https://stackoverflow.com/a/48218209).
302
+ * @link https://gist.github.com/ahtcx/0cd94e62691f539160b32ecda18af3d6
303
+ */
304
+ export function mergeDeep(target: any, source: any) {
305
+ const isObject = (obj: any) => obj && typeof obj === 'object'
306
+
307
+ if (!isObject(target) || !isObject(source)) {
308
+ return source
309
+ }
310
+
311
+ Object.keys(source).forEach(key => {
312
+ const targetValue = target[key]
313
+ const sourceValue = source[key]
314
+
315
+ if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
316
+ target[key] = targetValue.concat(sourceValue)
317
+ } else if (isObject(targetValue) && isObject(sourceValue)) {
318
+ target[key] = mergeDeep({ ...targetValue}, sourceValue)
319
+ } else {
320
+ target[key] = sourceValue
321
+ }
322
+ })
323
+
324
+ return target
325
+ }
@@ -2,8 +2,8 @@
2
2
  --at-color-font: #2a2e2e;
3
3
  --at-color-deep: #2a2e2e;
4
4
  --at-color-sub: #757575;
5
- --at-color-grey: #999;
6
- --at-color-meta: #757e91;
5
+ --at-color-grey: #747474;
6
+ --at-color-meta: #697182;
7
7
  --at-color-border: #eceff2;
8
8
  --at-color-light: #4285f4;
9
9
  --at-color-bg: #FFF;
@@ -88,6 +88,9 @@ export default interface ArtalkConfig {
88
88
 
89
89
  /** 版本检测 */
90
90
  versionCheck?: boolean
91
+
92
+ /** 复用后端配置 */
93
+ useBackendConf?: boolean
91
94
  }
92
95
 
93
96
  export interface LocalUser {