Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

feedback widget

Blue Mousea3d2bb78ce9c
diff --git a/package.json b/package.json
index 17c162418..400866b01 100644
--- a/package.json
+++ b/package.json
@@ -10,16 +10,18 @@
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
"serve": "docusaurus serve",
+ "format": "prettier --write .",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids"
},
"dependencies": {
- "@docusaurus/core": "2.4.1",
- "@docusaurus/preset-classic": "2.4.1",
+ "@docusaurus/core": "2.4.3",
+ "@docusaurus/preset-classic": "2.4.3",
"@mdx-js/react": "^1.6.22",
"@node-rs/jieba": "^1.7.0",
"autoprefixer": "^10.4.14",
"clsx": "^1.2.1",
+ "lucide-react": "^0.544.0",
"postcss": "^8.4.23",
"prism-react-renderer": "^1.3.5",
"prismjs": "^1.29.0",
@@ -28,7 +30,8 @@
"tailwindcss": "^3.3.2"
},
"devDependencies": {
- "@docusaurus/module-type-aliases": "2.4.1"
+ "@docusaurus/module-type-aliases": "2.4.3",
+ "prettier": "^3.6.2"
},
"browserslist": {
"production": [
diff --git a/src/components/FeedbackWidget.jsx b/src/components/FeedbackWidget.jsx
new file mode 100644
index 000000000..b840c286c
--- /dev/null
+++ b/src/components/FeedbackWidget.jsx
@@ -0,0 +1,188 @@
+import React, { useEffect, useMemo, useState } from 'react'
+import { useLocation } from '@docusaurus/router'
+import { ThumbsUpIcon, ThumbsDownIcon } from 'lucide-react'
+import Link from '@docusaurus/Link'
+
+const FEEDBACK_TTL_DAYS = 7
+const FEEDBACK_TTL_MS = FEEDBACK_TTL_DAYS * 24 * 60 * 60 * 1000
+
+const NEGATIVE_REASONS = [
+ 'Content is out of date',
+ 'Missing information',
+ 'Code examples not working as expected',
+ 'Other',
+]
+
+const getNowMs = () => {
+ return Date.now()
+}
+
+const storageKeyForPath = (pathname) => {
+ return `docs.feedback:${pathname}`
+}
+
+const hasRecentFeedback = (pathname) => {
+ if (typeof window === 'undefined') return false
+ try {
+ const key = storageKeyForPath(pathname)
+ const raw = window.localStorage.getItem(key)
+ if (raw) {
+ const data = JSON.parse(raw)
+ if (data && typeof data.ts === 'number' && getNowMs() - data.ts < FEEDBACK_TTL_MS) {
+ return true
+ }
+ }
+ } catch (reason) {
+ console.error('Error checking recent feedback:', reason)
+ }
+
+ return false
+}
+
+const persistFeedback = (pathname, answer, reason) => {
+ if (typeof window !== 'undefined') {
+ try {
+ const key = storageKeyForPath(pathname)
+ const value = JSON.stringify({ answer, reason, ts: getNowMs() })
+ window.localStorage.setItem(key, value)
+ } catch (reason) {
+ console.error('Error persisting feedback:', reason)
+ }
+ }
+}
+
+const trackFeedback = async (answer, pathname, reason) => {
+ try {
+ await window?.swetrix?.track({
+ ev: 'DOCS_FEEDBACK',
+ props: {
+ answer,
+ path: pathname,
+ ...(reason ? { reason } : {}),
+ },
+ })
+ } catch (reason) {
+ console.error('Error tracking feedback:', reason)
+ }
+}
+
+export default function FeedbackWidget() {
+ const { pathname } = useLocation()
+ const [submitted, setSubmitted] = useState(false)
+ const [showReasonForm, setShowReasonForm] = useState(false)
+ const [reason, setReason] = useState('')
+ const suppressed = useMemo(() => hasRecentFeedback(pathname), [pathname])
+
+ useEffect(() => {
+ setSubmitted(false)
+ setShowReasonForm(false)
+ setReason('')
+ }, [pathname])
+
+ const onClickYes = async () => {
+ await trackFeedback('Yes', pathname)
+ persistFeedback(pathname, 'Yes')
+ setSubmitted(true)
+ }
+
+ const onClickNo = () => {
+ setShowReasonForm(true)
+ }
+
+ const onSubmitReason = async (event) => {
+ event?.preventDefault?.()
+ if (!reason) return
+ await trackFeedback('No', pathname, reason)
+ persistFeedback(pathname, 'No', reason)
+ setSubmitted(true)
+ setShowReasonForm(false)
+ }
+
+ return (
+ <section className='swx-feedback-card' aria-label='Docs feedback widget'>
+ <div className='swx-feedback-art' aria-hidden='true'>
+ <img src='https://swetrix.com/logo512.png' alt='' />
+ </div>
+ <h2 className='swx-feedback-title'>Help us improve Swetrix</h2>
+ {submitted || suppressed ? (
+ <p aria-live='polite' className='swx-feedback-thanks'>
+ Thank you for your feedback ❤️
+ </p>
+ ) : (
+ <>
+ {showReasonForm ? (
+ <form className='swx-feedback-form' onSubmit={onSubmitReason}>
+ <p className='swx-feedback-question'>Why was this page not helpful to you?</p>
+ <div role='group' aria-label='Choose a reason' className='swx-feedback-reasons'>
+ {NEGATIVE_REASONS.map((label) => (
+ <label key={label} className='swx-feedback-reason'>
+ <input
+ type='radio'
+ name='feedback-reason'
+ value={label}
+ checked={reason === label}
+ onChange={() => setReason(label)}
+ />
+ <span>{label}</span>
+ </label>
+ ))}
+ </div>
+ <button
+ type='submit'
+ className='button button--lg button--primary swx-feedback-submit'
+ disabled={!reason}
+ aria-disabled={!reason}
+ >
+ Submit
+ </button>
+ </form>
+ ) : (
+ <>
+ <p className='swx-feedback-question'>Was this page helpful to you?</p>
+ <div role='group' className='swx-feedback-actions'>
+ <button
+ type='button'
+ className='button button--lg swx-feedback-btn swx-feedback-btn--yes'
+ onClick={onClickYes}
+ aria-label='Yes, this page was helpful'
+ >
+ <ThumbsUpIcon width={18} height={18} />
+ Yes
+ </button>
+ <button
+ type='button'
+ className='button button--lg swx-feedback-btn swx-feedback-btn--no'
+ onClick={onClickNo}
+ aria-label='No, this page was not helpful'
+ >
+ <ThumbsDownIcon width={18} height={18} />
+ No
+ </button>
+ </div>
+ </>
+ )}
+ </>
+ )}
+ <div className='swx-feedback-links'>
+ {/* {editUrl ? (
+ <Link className="swx-feedback-link" to={editUrl} target="_blank" rel="noopener noreferrer">
+ Edit this page on GitHub
+ </Link>
+ ) : null} */}
+
+ <Link className='swx-feedback-contribute' to='/contribute'>
+ Learn how to contribute
+ </Link>
+ <span className='swx-feedback-sep'>•</span>
+ <Link
+ className='swx-feedback-link'
+ to='https://github.com/Swetrix/docs/issues'
+ target='_blank'
+ rel='noopener noreferrer'
+ >
+ Report a problem with this content
+ </Link>
+ </div>
+ </section>
+ )
+}
diff --git a/src/css/custom.css b/src/css/custom.css
index 49ba3d371..f4cc6b922 100644
--- a/src/css/custom.css
+++ b/src/css/custom.css
@@ -4,30 +4,31 @@
* work well for content-centric websites.
*/
-/* You can override the default Infima variables here. */
-
:root {
--ifm-color-primary: #312e81;
- --ifm-color-primary-dark: #3730A3;
- --ifm-color-primary-darker: #4338CA;
- --ifm-color-primary-darkest: #4F46E5;
- --ifm-color-primary-light: #6366F1;
- --ifm-color-primary-lighter: #818CF8;
- --ifm-color-primary-lightest: #A5B4FC;
+ --ifm-color-primary-dark: #3730a3;
+ --ifm-color-primary-darker: #4338ca;
+ --ifm-color-primary-darkest: #4f46e5;
+ --ifm-color-primary-light: #6366f1;
+ --ifm-color-primary-lighter: #818cf8;
+ --ifm-color-primary-lightest: #a5b4fc;
+ /* tailwind green-600 */
+ --ifm-color-green: oklch(62.7% 0.194 149.214);
--ifm-code-font-size: 95%;
--docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.1);
--ifm-footer-link-hover-color: var(--ifm-color-primary-lightest);
}
-/* For readability concerns, you should choose a lighter palette in dark mode. */
[data-theme='dark'] {
- --ifm-color-primary: #A5B4FC;
- --ifm-color-primary-dark: #E0E7FF;
- --ifm-color-primary-darker: #C7D2FE;
- --ifm-color-primary-darkest: #A5B4FC;
- --ifm-color-primary-light: #818CF8;
- --ifm-color-primary-lighter: #6366F1;
- --ifm-color-primary-lightest: #4F46E5;
+ --ifm-color-primary: #a5b4fc;
+ --ifm-color-primary-dark: #e0e7ff;
+ --ifm-color-primary-darker: #c7d2fe;
+ --ifm-color-primary-darkest: #a5b4fc;
+ --ifm-color-primary-light: #818cf8;
+ --ifm-color-primary-lighter: #6366f1;
+ --ifm-color-primary-lightest: #4f46e5;
+ /* tailwind green-500 */
+ --ifm-color-green: oklch(72.3% 0.219 149.579);
--docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3);
--ifm-footer-link-hover-color: var(--ifm-color-primary);
}
@@ -60,10 +61,137 @@
img {
border-radius: 0.5rem;
/* box-shadow: inset 0 0 0 calc(1px + 0px) rgb(15 23 42 / 0.05); */
- box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
+ box-shadow:
+ 0 20px 25px -5px rgba(0, 0, 0, 0.1),
+ 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}
.navbar-logo {
border-radius: 0;
box-shadow: none;
}
+
+/* Docs feedback card (MDN-like) */
+.swx-feedback-card {
+ margin-top: 2rem;
+ border: 1px solid var(--ifm-toc-border-color);
+ border-radius: 8px;
+ padding: 1.25rem 1.25rem 1rem;
+ background: var(--ifm-card-background-color);
+ position: relative;
+ overflow: hidden;
+}
+
+.swx-feedback-title {
+ font-size: 1.75rem;
+ font-weight: 700;
+ margin: 0 0 0.5rem 0;
+}
+
+.swx-feedback-question {
+ margin: 0 0 1rem 0;
+ font-size: 1.125rem;
+}
+
+.swx-feedback-actions {
+ display: flex;
+ gap: 0.75rem;
+ margin-bottom: 0.75rem;
+}
+
+.swx-feedback-btn {
+ display: inline-flex;
+ align-items: center;
+ gap: 0.5rem;
+ border: 1px solid var(--ifm-color-green);
+ background: transparent;
+ color: var(--ifm-color-green);
+}
+
+.swx-feedback-btn:hover {
+ background: var(--ifm-color-green);
+ color: white;
+}
+
+.swx-feedback-btn--no {
+ border-color: var(--ifm-color-danger);
+ color: var(--ifm-color-danger);
+}
+
+.swx-feedback-btn--no:hover {
+ background: var(--ifm-color-danger);
+ color: #fff;
+}
+
+.swx-feedback-contribute {
+ font-weight: 600;
+}
+
+.swx-feedback-links {
+ margin-top: 0.75rem;
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ flex-wrap: wrap;
+}
+
+.swx-feedback-link {
+ font-weight: 600;
+}
+
+.swx-feedback-sep {
+ opacity: 0.6;
+}
+
+.swx-feedback-thanks {
+ margin: 0;
+ margin-bottom: 3rem;
+}
+
+.swx-feedback-art {
+ position: absolute;
+ right: 0rem;
+ top: -1rem;
+ width: 140px;
+ height: 140px;
+ opacity: 0.5;
+ pointer-events: none;
+}
+
+.swx-feedback-art img {
+ width: 100%;
+ height: 100%;
+ object-fit: contain;
+ rotate: -10deg;
+ border-radius: 0;
+ box-shadow: none;
+}
+
+/* Reason form */
+.swx-feedback-form {
+ margin-top: 0.5rem;
+}
+
+.swx-feedback-reasons {
+ display: grid;
+ gap: 0.5rem;
+ margin-bottom: 0.75rem;
+}
+
+.swx-feedback-reason {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+}
+
+.swx-feedback-submit[disabled],
+.swx-feedback-submit[aria-disabled='true'] {
+ opacity: 0.6;
+ cursor: not-allowed;
+}
+
+@media (max-width: 600px) {
+ .swx-feedback-card {
+ display: none;
+ }
+}
diff --git a/src/theme/DocItem/Footer/index.js b/src/theme/DocItem/Footer/index.js
new file mode 100644
index 000000000..31fddfe2a
--- /dev/null
+++ b/src/theme/DocItem/Footer/index.js
@@ -0,0 +1,12 @@
+import React from 'react'
+import OriginalFooter from '@theme-original/DocItem/Footer'
+import FeedbackWidget from '@site/src/components/FeedbackWidget'
+
+export default function FooterWrapper(props) {
+ return (
+ <>
+ <OriginalFooter {...props} />
+ <FeedbackWidget />
+ </>
+ )
+}
diff --git a/static/js/setupswetrix.js b/static/js/setupswetrix.js
index 782d069c3..9de817d11 100644
--- a/static/js/setupswetrix.js
+++ b/static/js/setupswetrix.js
@@ -1,4 +1,6 @@
document.addEventListener('DOMContentLoaded', function () {
- swetrix.init('gdXQqPERkpMA')
+ swetrix.init('gdXQqPERkpMA', {
+ devMode: true,
+ })
swetrix.trackViews()
})