artalk 2.2.5 → 2.2.6

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
@@ -64,7 +64,7 @@
64
64
  el: '#comments',
65
65
  pageKey: 'https://artalk.js.org/',
66
66
  pageTitle: 'Artalk Home',
67
- server: (import.meta.env.MODE === 'development') ? 'http://localhost:23366/api' : 'https://artalk.qwqaq.com/api',
67
+ server: (import.meta.env.MODE === 'development') ? 'http://localhost:23366' : 'https://artalk.qwqaq.com',
68
68
  site: 'ArtalkDemo',
69
69
  });
70
70
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "artalk",
3
- "version": "2.2.5",
3
+ "version": "2.2.6",
4
4
  "backendMinVersion": "2.1.2",
5
5
  "license": "LGPL-3.0",
6
6
  "description": "A Selfhosted Comment System",
package/src/api/index.ts CHANGED
@@ -9,7 +9,7 @@ export default class Api {
9
9
 
10
10
  constructor (ctx: Context) {
11
11
  this.ctx = ctx
12
- this.baseURL = ctx.conf.server
12
+ this.baseURL = `${ctx.conf.server}/api`
13
13
  }
14
14
 
15
15
  // ============================
package/src/artalk.ts CHANGED
@@ -33,22 +33,31 @@ export default class Artalk {
33
33
  constructor (customConf: ArtalkConfig) {
34
34
  // 配置
35
35
  this.conf = { ...Artalk.defaults, ...customConf }
36
- this.conf.server = this.conf.server.replace(/\/$/, '')
36
+ this.conf.server = this.conf.server.replace(/\/$/, '').replace(/\/api\/?$/, '')
37
37
 
38
38
  // 默认 pageKey
39
39
  if (!this.conf.pageKey) {
40
40
  // @link http://bl.ocks.org/abernier/3070589
41
- this.conf.pageKey = `${window.location.protocol}//${window.location.host}${window.location.pathname}`
41
+ this.conf.pageKey = `${window.location.pathname}`
42
+ }
43
+
44
+ // 默认 pageTitle
45
+ if (!this.conf.pageTitle) {
46
+ this.conf.pageTitle = `${document.title}`
42
47
  }
43
48
 
44
49
  // 装载元素
45
- try {
46
- const $root = document.querySelector<HTMLElement>(this.conf.el)
47
- if (!$root) throw Error(`Sorry, target element "${this.conf.el}" was not found.`)
48
- this.$root = $root
49
- } catch (e) {
50
- console.error(e)
51
- throw new Error('Please check your Artalk `el` config.')
50
+ if (!!this.conf.el && this.conf.el instanceof HTMLElement) {
51
+ this.$root = this.conf.el
52
+ } else {
53
+ try {
54
+ const $root = document.querySelector<HTMLElement>(this.conf.el)
55
+ if (!$root) throw Error(`Sorry, target element "${this.conf.el}" was not found.`)
56
+ this.$root = $root
57
+ } catch (e) {
58
+ console.error(e)
59
+ throw new Error('Please check your Artalk `el` config.')
60
+ }
52
61
  }
53
62
 
54
63
  // Context 初始化
@@ -88,7 +88,7 @@ export default class SidebarLayer extends Component {
88
88
 
89
89
  // 准备 Iframe 参数
90
90
  const baseURL = (import.meta.env.MODE === 'development') ? 'http://localhost:23367/'
91
- : Utils.getURLBasedOnApi(this.ctx, 'sidebar/')
91
+ : Utils.getURLBasedOnApi(this.ctx, '/sidebar/')
92
92
 
93
93
  const query: any = {
94
94
  pageKey: this.conf.pageKey,
@@ -15,7 +15,7 @@ const CaptchaChecker: Checker = {
15
15
  const $iframe = Utils.createElement<HTMLIFrameElement>(`<iframe class="atk-fade-in"></iframe>`)
16
16
  $iframe.style.display = 'none'
17
17
  Ui.showLoading($iframeWrap, { transparentBg: true })
18
- $iframe.src = `${that.ctx.conf.server}/captcha/get?t=${+new Date()}`
18
+ $iframe.src = `${that.ctx.conf.server}/api/captcha/get?t=${+new Date()}`
19
19
  $iframe.onload = () => {
20
20
  $iframe.style.display = ''
21
21
  Ui.hideLoading($iframeWrap)
package/src/lib/utils.ts CHANGED
@@ -286,7 +286,7 @@ export function isValidURL(urlRaw: string) {
286
286
 
287
287
  /** 获取基于 conf.server 的 URL */
288
288
  export function getURLBasedOnApi(ctx: Context, path: string) {
289
- return `${ctx.conf.server.replace(/\/api\/?$/, '')}/${path.replace(/^\//, '')}`
289
+ return getURLBasedOn(ctx.conf.server, path)
290
290
  }
291
291
 
292
292
  /** 获取基于某个 baseURL 的 URL */
@@ -1,6 +1,6 @@
1
1
  export default interface ArtalkConfig {
2
2
  /** 装载元素 */
3
- el: string
3
+ el: string|HTMLElement
4
4
 
5
5
  /** 页面唯一标识(完整 URL) */
6
6
  pageKey: string