diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index af565a1..498f63a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,9 +3,15 @@ name: npm publish on: release: types: [created] + jobs: build: runs-on: ubuntu-latest + + permissions: + contents: read + id-token: write # OIDC 必須 + steps: - uses: actions/checkout@v4 # Setup .npmrc file to publish to npm @@ -13,7 +19,9 @@ jobs: with: node-version: '20.x' registry-url: 'https://registry.npmjs.org' + - run: npm install - - run: npm publish + + - run: npm publish --provenance --access public env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/_config.yml b/_config.yml index da4ee3d..496616e 100644 --- a/_config.yml +++ b/_config.yml @@ -659,7 +659,7 @@ artalk: # -------------------------------------- chat: - # Choose: chatra/tidio/crisp + # Choose: chatra/tidio/crisp/knocket # Leave it empty if you don't need chat use: # Chat Button [recommend] @@ -680,6 +680,10 @@ tidio: crisp: website_id: +# https://trtc.io/solutions/knocket +knocket: + identifier: + # -------------------------------------- # Analysis # -------------------------------------- diff --git a/layout/includes/third-party/chat/index.pug b/layout/includes/third-party/chat/index.pug index dada453..ace9b3b 100644 --- a/layout/includes/third-party/chat/index.pug +++ b/layout/includes/third-party/chat/index.pug @@ -4,4 +4,6 @@ case theme.chat.use when 'tidio' include ./tidio.pug when 'crisp' - include ./crisp.pug \ No newline at end of file + include ./crisp.pug + when 'knocket' + include ./knocket.pug \ No newline at end of file diff --git a/layout/includes/third-party/chat/knocket.pug b/layout/includes/third-party/chat/knocket.pug new file mode 100644 index 0000000..0f76439 --- /dev/null +++ b/layout/includes/third-party/chat/knocket.pug @@ -0,0 +1,44 @@ +//- Knocket live chat — https://trtc.io/solutions/knocket +script. + (() => { + const id = '#{theme.knocket.identifier}' + if (!id) return + + btf.getScript(`https://trtc.io/knocket-sdk/sdk.js?identifier=${id}`).then(() => { + const isChatBtn = !{theme.chat.rightside_button} + const isChatHideShow = !{theme.chat.button_hide_show} + + const getWidget = () => document.getElementById('contact-widget-auto') + + if (isChatBtn) { + const hide = () => { const w = getWidget(); if (w) w.style.display = 'none' } + const show = () => { const w = getWidget(); if (w) w.style.display = '' } + + // Hide the native Knocket floating button + const observer = new MutationObserver(() => { + if (getWidget()) { hide(); observer.disconnect() } + }) + observer.observe(document.body, { childList: true, subtree: true }) + hide() + + window.chatBtnFn = () => { + const w = getWidget() + if (!w) return + if (w.style.display === 'none') show() + else hide() + } + + document.getElementById('chat-btn').style.display = 'block' + } else if (isChatHideShow) { + const observer = new MutationObserver(() => { + if (getWidget()) observer.disconnect() + }) + observer.observe(document.body, { childList: true, subtree: true }) + + window.chatBtn = { + hide: () => { const w = getWidget(); if (w) w.style.display = 'none' }, + show: () => { const w = getWidget(); if (w) w.style.display = '' } + } + } + }) + })() diff --git a/scripts/common/default_config.js b/scripts/common/default_config.js index ab3f01f..5ae0cd4 100644 --- a/scripts/common/default_config.js +++ b/scripts/common/default_config.js @@ -394,6 +394,9 @@ module.exports = { crisp: { website_id: null }, + knocket: { + identifier: null + }, google_tag_manager: { tag_id: null, domain: 'https://www.googletagmanager.com'