Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add href option #589

Merged
merged 1 commit into from
Sep 11, 2023
Merged

feat: add href option #589

merged 1 commit into from
Sep 11, 2023

Conversation

Android-KitKat
Copy link
Contributor

@Android-KitKat Android-KitKat commented Sep 8, 2023

描述

在有镜像站点的情况下,允许管理员规范邮件通知使用的网址。

为前端 twikoo.init 方法新增 href 选项。
以及全局覆盖变量 TWIKOO_MAGIC_HREF
用于指定相关接口的 href 参数。

尝试解决从镜像站点发送评论时,邮件通知里网址不统一的情况。
也就是模板中的 ${POST_URL} 变量。

使用示例

先自定义获取理想网址的方法。

const getHref = () => {
  const url = new URL(location);
  url.protocol = 'https:';
  url.hostname = 'example.com';
  url.port = '';
  return url.href;
};

然后在初始化评论区时调用并传入 href 选项。

twikoo.init({
  envId: 'https://comment.example.com',
  el: '#tcomment',
  href: getHref()
});

或者直接在网页中声明全局变量进行覆盖。

Object.defineProperty(window, 'TWIKOO_MAGIC_HREF', {
  configurable: true,
  get: getHref
});

@Android-KitKat Android-KitKat marked this pull request as ready for review September 9, 2023 14:27
@imaegoo imaegoo merged commit 04ac33e into twikoojs:main Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants