Skip to content

Commit

Permalink
docs: Add comments for proposal section (#1517)
Browse files Browse the repository at this point in the history
* Add utterances

* Update repo
  • Loading branch information
NickSeagull authored Jan 25, 2024
1 parent 869d1c5 commit 7464d16
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const lightCodeTheme = themes.palenight
const config = {
title: 'Booster Framework',
staticDirectories: ['static'],
url: 'https://boosterframework.com',
url: 'https://docs.boosterframework.com',
baseUrl: '/',
onBrokenLinks: 'warn',
onBrokenMarkdownLinks: 'warn',
Expand Down
24 changes: 24 additions & 0 deletions website/src/components/Utterance.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { useMemo } from 'react'
// import { useColorMode } from "@docusaurus/theme-common";

import useUtterance from '../hooks/useUtterance'

export type Props = React.HTMLAttributes<HTMLDivElement>

export default function Utterance(props: Props) {
// const { colorMode } = useColorMode();
const colorMode = 'light'
const options = useMemo(
() =>
({
repo: 'boostercloud/docs-discussion',
theme: `github-${colorMode}`,
label: 'comment-section',
} as const),
[colorMode]
)

const { anchor } = useUtterance<HTMLDivElement>(options)

return <div ref={anchor} {...props} />
}
4 changes: 4 additions & 0 deletions website/src/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,8 @@ svg {
.navbar_custom_item--button {
margin-right: 3rem
}
}

.utterances {
max-width: 100%;
}
52 changes: 52 additions & 0 deletions website/src/hooks/useUtterance.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useEffect, useRef } from 'react'

export type Params = {
repo: string
theme:
| 'github-light'
| 'github-dark'
| 'preferred-color-scheme'
| 'github-dark-orange'
| 'icy-dark'
| 'dark-blue'
| 'photon-dark'
| 'boxy-light'
| 'gruvbox-dark'
label?: string
'issue-term'?: 'pathname' | 'url' | 'title' | 'og:title'
'issue-number'?: string
}

export default function useUtterance<T extends HTMLElement>(params?: Params) {
const anchor = useRef<T>(null)

useEffect(() => {
while (anchor.current.firstChild) {
anchor.current.removeChild(anchor.current.firstChild)
}

anchor.current.appendChild(createUtteranceScript(params))
}, [params])

return { anchor }
}

function createUtteranceScript(option?: Record<string, unknown>) {
const script = document.createElement('script')

script.src = 'https://utteranc.es/client.js'
script.crossOrigin = 'anonymous'
script.async = true

Object.entries({ ...defaultAttributes, ...option }).forEach(([key, value]) => {
script.setAttribute(key, value)
})

return script
}

const defaultAttributes = {
'issue-term': 'title',
label: 'comment-section',
theme: 'github-light',
}
12 changes: 12 additions & 0 deletions website/src/theme/BlogPostPaginator/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react'
import BlogPostPaginator from '@theme-original/BlogPostPaginator'
import Utterance from '@site/src/components/Utterance'

export default function BlogPostPaginatorWrapper(props) {
return (
<>
<BlogPostPaginator {...props} />
<Utterance />
</>
)
}

0 comments on commit 7464d16

Please sign in to comment.