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 ability for the user to comment on the documentation #254

Merged
merged 5 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs-website/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NEXT_PUBLIC_COMMENTS_REPO_ID=""
NEXT_PUBLIC_COMMENTS_CATEGORY_ID=""
NEXT_PUBLIC_COMMENTS_APP_HOST=""
5 changes: 4 additions & 1 deletion docs-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"browserslist": "defaults, not ie <= 11",
"dependencies": {
"@docsearch/react": "^3.1.1",
"@giscus/react": "^2.2.0",
"@headlessui/react": "^1.6.5",
"@heroicons/react": "^1.0.6",
"@markdoc/markdoc": "^0.1.3",
Expand All @@ -26,6 +27,7 @@
"focus-visible": "^5.2.0",
"next": "12.2.0",
"next-sitemap": "^3.1.11",
"next-themes": "^0.2.1",
"plausible-tracker": "^0.3.8",
"postcss-focus-visible": "^6.0.4",
"postcss-import": "^14.1.0",
Expand All @@ -41,6 +43,7 @@
"eslint": "8.19.0",
"eslint-config-next": "12.2.0",
"prettier": "^2.7.1",
"prettier-plugin-tailwindcss": "^0.1.11"
"prettier-plugin-tailwindcss": "^0.1.11",
"typescript": "^4.8.4"
}
}
40 changes: 40 additions & 0 deletions docs-website/src/components/Comments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Giscus from '@giscus/react'
import { useTheme } from 'next-themes'

const Comments = () => {
const { theme, systemTheme } = useTheme()
return (
<div className="my-8">
<Giscus
id="comments"
repo="wundergraph/wundergraph"
repoId={
process.env.NEXT_PUBLIC_COMMENTS_REPO_ID
? process.env.NEXT_PUBLIC_COMMENTS_REPO_ID
: ''
}
category="Docs"
categoryId={
process.env.NEXT_PUBLIC_COMMENTS_CATEGORY_ID
? process.env.NEXT_PUBLIC_COMMENTS_CATEGORY_ID
: ''
}
mapping="title"
strict="1"
reactionsEnabled="1"
emitMetadata="0"
inputPosition="top"
theme={theme !== 'system' ? theme : systemTheme}
lang="en"
loading="lazy"
host={
process.env.NEXT_PUBLIC_COMMENTS_APP_HOST
? process.env.NEXT_PUBLIC_COMMENTS_APP_HOST
: ''
}
/>
</div>
)
}

export default Comments
2 changes: 2 additions & 0 deletions docs-website/src/components/Layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ThemeSelector } from '@/components/ThemeSelector'
import navigation from '../../config/navigation'
import { GitHubIcon } from './icons/Github'
import { DocsFooter } from './DocsFooter'
import Comments from './Comments'

function Header({ navigation }) {
let [isScrolled, setIsScrolled] = useState(false)
Expand Down Expand Up @@ -174,6 +175,7 @@ export function Layout({ children, title, tableOfContents, frontmatter }) {
</header>
)}
<Prose>{children}</Prose>
<Comments />
</article>
<dl className="mt-12 flex border-t border-slate-200 pt-6 dark:border-slate-800">
{previousPage && (
Expand Down
4 changes: 4 additions & 0 deletions docs-website/src/components/ThemeSelector.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react'
import { Listbox } from '@headlessui/react'
import clsx from 'clsx'
import { useTheme } from 'next-themes'

const themes = [
{ name: 'Light', value: 'light', icon: LightIcon },
Expand Down Expand Up @@ -46,6 +47,7 @@ function SystemIcon(props) {

export function ThemeSelector(props) {
let [selectedTheme, setSelectedTheme] = useState()
const { setTheme } = useTheme()

useEffect(() => {
if (selectedTheme) {
Expand All @@ -56,13 +58,15 @@ export function ThemeSelector(props) {
'content',
selectedTheme.value === 'dark' ? 'rgb(11, 15, 26)' : '#ffffff'
)
setTheme(selectedTheme.value)
} else {
setSelectedTheme(
themes.find(
(theme) =>
theme.value === document.documentElement.getAttribute('data-theme')
)
)
setTheme(document.documentElement.getAttribute('data-theme') || 'dark')
}
}, [selectedTheme])

Expand Down
17 changes: 10 additions & 7 deletions docs-website/src/pages/_app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'focus-visible'
import '@/styles/tailwind.css'
import Plausible from 'plausible-tracker'
import { useEffect } from 'react'
import { ThemeProvider } from 'next-themes'

export const plausible = Plausible({
domain: 'docs.wundergraph.com',
Expand Down Expand Up @@ -80,13 +81,15 @@ export default function App({ Component, pageProps }) {
<title>{pageTitle}</title>
{description && <meta name="description" content={description} />}
</Head>
<Layout
title={title}
tableOfContents={tableOfContents}
frontmatter={pageProps.markdoc?.frontmatter}
>
<Component {...pageProps} />
</Layout>
<ThemeProvider attribute="class" enableSystem>
<Layout
title={title}
tableOfContents={tableOfContents}
frontmatter={pageProps.markdoc?.frontmatter}
>
<Component {...pageProps} />
</Layout>
</ThemeProvider>
</>
)
}