Compare commits

...
6 Commits
Author SHA1 Message Date
qwqcode bd621067b5 v2.2.6
Signed-off-by: qwqcode <qwqcode@gmail.com>
2022-04-20 19:40:53 +08:00
qwqcode 01ae389264 chore(devops): Update Artalk latest version in docs
Signed-off-by: qwqcode <qwqcode@gmail.com>
2022-04-20 19:34:45 +08:00
qwqcode 84700cfc2f feat(conf): Allow HTMLElement type vaule as conf.el
Signed-off-by: qwqcode <qwqcode@gmail.com>
2022-04-20 18:12:15 +08:00
qwqcode b68f609a44 feat(conf): Remove server /api by default
Signed-off-by: qwqcode <qwqcode@gmail.com>
2022-04-20 16:38:23 +08:00
qwqcode 703e198780 feat(conf): pageTitle default value
Signed-off-by: qwqcode <qwqcode@gmail.com>
2022-04-20 15:25:50 +08:00
qwqcode 4f75ef8709 feat: Remove conf.server /api suffix path & Use relative path as default
Signed-off-by: qwqcode <qwqcode@gmail.com>
2022-04-19 23:23:09 +08:00
12 changed files with 30 additions and 20 deletions

No files matched your search

+1
View File
@@ -66,6 +66,7 @@ jobs:
- name: Update CDN links
run: |
sed -i 's#artalk@.[^/]*#artalk@${{ steps.get_version.outputs.VERSION }}#g' docs/code/ArtalkCDN.json
perl -pi -e 's#"Artalk"(\W+)?:(\W+)?".*?"#"Artalk": "${{ steps.get_version.outputs.VERSION }}"#g' docs/code/ArtalkVersion.json
sed -i 's#artalk@.[^/]*#artalk@${{ steps.get_version.outputs.VERSION }}#g' docs/code/quick-start/cdn.html
- uses: stefanzweifel/git-auto-commit-action@v4
+1 -1
View File
@@ -21,7 +21,7 @@
InitSidebar({
el: '#ArtalkSidebar',
server: (import.meta.env.MODE === 'development') ? 'http://localhost:23366/api' : '../api',
server: (import.meta.env.MODE === 'development') ? 'http://localhost:23366' : '../',
pageKey,
site,
darkMode,
@@ -135,7 +135,7 @@ export default class TransferView extends SidebarView {
formData.append('token', this.ctx.user.data.token)
// 开始上传
xhr.open('post', `${this.ctx.conf.server}/admin/import-upload`)
xhr.open('post', `${this.ctx.conf.server}/api/admin/import-upload`)
xhr.timeout = 2*60*1000 // 2min
xhr.send(formData)
@@ -256,7 +256,7 @@ export default class TransferView extends SidebarView {
const $formTmp = document.createElement('form')
$formTmp.style.display = 'none'
$formTmp.setAttribute('method', 'post')
$formTmp.setAttribute('action', `${this.ctx.conf.server}/admin/import`)
$formTmp.setAttribute('action', `${this.ctx.conf.server}/api/admin/import`)
$formTmp.setAttribute("target", frameName)
Object.entries(formParams).forEach(([key, val]) => {
+1 -1
View File
@@ -64,7 +64,7 @@
el: '#comments',
pageKey: 'https://artalk.js.org/',
pageTitle: 'Artalk Home',
server: (import.meta.env.MODE === 'development') ? 'http://localhost:23366/api' : 'https://artalk.qwqaq.com/api',
server: (import.meta.env.MODE === 'development') ? 'http://localhost:23366' : 'https://artalk.qwqaq.com',
site: 'ArtalkDemo',
});
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "artalk",
"version": "2.2.5",
"version": "2.2.6",
"backendMinVersion": "2.1.2",
"license": "LGPL-3.0",
"description": "A Selfhosted Comment System",
+1 -1
View File
@@ -9,7 +9,7 @@ export default class Api {
constructor (ctx: Context) {
this.ctx = ctx
this.baseURL = ctx.conf.server
this.baseURL = `${ctx.conf.server}/api`
}
// ============================
+18 -9
View File
@@ -33,22 +33,31 @@ export default class Artalk {
constructor (customConf: ArtalkConfig) {
// 配置
this.conf = { ...Artalk.defaults, ...customConf }
this.conf.server = this.conf.server.replace(/\/$/, '')
this.conf.server = this.conf.server.replace(/\/$/, '').replace(/\/api\/?$/, '')
// 默认 pageKey
if (!this.conf.pageKey) {
// @link http://bl.ocks.org/abernier/3070589
this.conf.pageKey = `${window.location.protocol}//${window.location.host}${window.location.pathname}`
this.conf.pageKey = `${window.location.pathname}`
}
// 默认 pageTitle
if (!this.conf.pageTitle) {
this.conf.pageTitle = `${document.title}`
}
// 装载元素
try {
const $root = document.querySelector<HTMLElement>(this.conf.el)
if (!$root) throw Error(`Sorry, target element "${this.conf.el}" was not found.`)
this.$root = $root
} catch (e) {
console.error(e)
throw new Error('Please check your Artalk `el` config.')
if (!!this.conf.el && this.conf.el instanceof HTMLElement) {
this.$root = this.conf.el
} else {
try {
const $root = document.querySelector<HTMLElement>(this.conf.el)
if (!$root) throw Error(`Sorry, target element "${this.conf.el}" was not found.`)
this.$root = $root
} catch (e) {
console.error(e)
throw new Error('Please check your Artalk `el` config.')
}
}
// Context 初始化
@@ -88,7 +88,7 @@ export default class SidebarLayer extends Component {
// 准备 Iframe 参数
const baseURL = (import.meta.env.MODE === 'development') ? 'http://localhost:23367/'
: Utils.getURLBasedOnApi(this.ctx, 'sidebar/')
: Utils.getURLBasedOnApi(this.ctx, '/sidebar/')
const query: any = {
pageKey: this.conf.pageKey,
@@ -15,7 +15,7 @@ const CaptchaChecker: Checker = {
const $iframe = Utils.createElement<HTMLIFrameElement>(`<iframe class="atk-fade-in"></iframe>`)
$iframe.style.display = 'none'
Ui.showLoading($iframeWrap, { transparentBg: true })
$iframe.src = `${that.ctx.conf.server}/captcha/get?t=${+new Date()}`
$iframe.src = `${that.ctx.conf.server}/api/captcha/get?t=${+new Date()}`
$iframe.onload = () => {
$iframe.style.display = ''
Ui.hideLoading($iframeWrap)
+1 -1
View File
@@ -286,7 +286,7 @@ export function isValidURL(urlRaw: string) {
/** 获取基于 conf.server 的 URL */
export function getURLBasedOnApi(ctx: Context, path: string) {
return `${ctx.conf.server.replace(/\/api\/?$/, '')}/${path.replace(/^\//, '')}`
return getURLBasedOn(ctx.conf.server, path)
}
/** 获取基于某个 baseURL 的 URL */
+1 -1
View File
@@ -1,6 +1,6 @@
export default interface ArtalkConfig {
/** 装载元素 */
el: string
el: string|HTMLElement
/** 页面唯一标识(完整 URL) */
pageKey: string
+1 -1
View File
@@ -20,7 +20,7 @@
el: '#comments',
pageKey: 'https://artalk.js.org/',
pageTitle: 'Artalk Home',
server: (import.meta.env.MODE === 'development') ? 'http://localhost:23366/api' : 'https://artalk.qwqaq.com/api',
server: (import.meta.env.MODE === 'development') ? 'http://localhost:23366' : 'https://artalk.qwqaq.com',
site: 'ArtalkDemo',
});
</script>