From d78220a818ca254ca2cb4e597a01dab07e47cf60 Mon Sep 17 00:00:00 2001 From: Yangshun Tay Date: Wed, 13 Mar 2019 22:51:16 -0700 Subject: [PATCH] feat(v2): embed Canny feedback widget (#1280) * feat(v2): embed Canny feedback widget * docs(v2): Mention source of Canny widget * misc(v2): add newline --- v2-website/pages/feedback/index.js | 28 ++++++++++++++ v2-website/pages/feedback/styles.module.css | 4 ++ v2-website/scripts/canny.js | 37 +++++++++++++++++++ v2/lib/webpack/base.js | 2 +- .../docusaurus-plugin-content-pages/index.js | 3 +- 5 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 v2-website/pages/feedback/index.js create mode 100644 v2-website/pages/feedback/styles.module.css create mode 100644 v2-website/scripts/canny.js diff --git a/v2-website/pages/feedback/index.js b/v2-website/pages/feedback/index.js new file mode 100644 index 0000000000..f470213e40 --- /dev/null +++ b/v2-website/pages/feedback/index.js @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import React, {useEffect} from 'react'; +import canny from '../../scripts/canny'; + +import styles from './styles.module.css'; + +const BOARD_TOKEN = '054e0e53-d951-b14c-7e74-9eb8f9ed2f91'; + +function Feedback() { + useEffect(() => { + canny(); + window.Canny && + window.Canny('render', { + boardToken: BOARD_TOKEN, + basePath: '/feedback', + }); + }, []); + + return
; +} + +export default Feedback; diff --git a/v2-website/pages/feedback/styles.module.css b/v2-website/pages/feedback/styles.module.css new file mode 100644 index 0000000000..bce892533d --- /dev/null +++ b/v2-website/pages/feedback/styles.module.css @@ -0,0 +1,4 @@ +.feedbackPage { + margin: 64px auto; + max-width: 1024px; +} diff --git a/v2-website/scripts/canny.js b/v2-website/scripts/canny.js new file mode 100644 index 0000000000..c95021a02f --- /dev/null +++ b/v2-website/scripts/canny.js @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// Provided by Canny. + +function canny() { + !(function(w, d, i, s) { + function l() { + if (!d.getElementById(i)) { + var f = d.getElementsByTagName(s)[0], + e = d.createElement(s); + (e.type = 'text/javascript'), + (e.async = !0), + (e.src = 'https://canny.io/sdk.js'), + f.parentNode.insertBefore(e, f); + } + } + if ('function' != typeof w.Canny) { + var c = function() { + c.q.push(arguments); + }; + (c.q = []), + (w.Canny = c), + 'complete' === d.readyState + ? l() + : w.attachEvent + ? w.attachEvent('onload', l) + : w.addEventListener('load', l, !1); + } + })(window, document, 'canny-jssdk', 'script'); +} + +export default canny; diff --git a/v2/lib/webpack/base.js b/v2/lib/webpack/base.js index bcccbcaeb1..aa1e2c60b4 100644 --- a/v2/lib/webpack/base.js +++ b/v2/lib/webpack/base.js @@ -92,7 +92,7 @@ module.exports = function createBaseConfig(props, isServer) { const jsRule = config.module .rule('js') - .test(/\.js$/) + .test(/\.jsx?$/) .exclude.add(filepath => { // Always transpile lib directory if (filepath.startsWith(path.join(__dirname, '..'))) { diff --git a/v2/plugins/docusaurus-plugin-content-pages/index.js b/v2/plugins/docusaurus-plugin-content-pages/index.js index 34d1fb4ea3..a153655092 100644 --- a/v2/plugins/docusaurus-plugin-content-pages/index.js +++ b/v2/plugins/docusaurus-plugin-content-pages/index.js @@ -104,8 +104,7 @@ class DocusaurusPluginContentPages { } getPathsToWatch() { - // Not needed, all pages are loaded as modules and watched by webpack. - return []; + return [this.contentPath]; } }