Skip to content

Commit 1a47f8c

Browse files
committed
Add Giscus to docs-pages
1 parent ee7437b commit 1a47f8c

File tree

6 files changed

+197
-0
lines changed

6 files changed

+197
-0
lines changed

giscus.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"origins": [
3+
"https://pester.dev",
4+
"https://pester-docs.netlify.app"
5+
],
6+
"originsRegex": [
7+
"https://deploy-preview-[0-9]+--pester-docs.netlify.app",
8+
"http://localhost:[0-9]+"
9+
],
10+
"defaultCommentOrder": "oldest"
11+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"dependencies": {
1717
"@docusaurus/core": "^2.4.0",
1818
"@docusaurus/preset-classic": "^2.4.0",
19+
"@giscus/react": "^2.2.8",
1920
"@mdx-js/react": "^1.6.22",
2021
"@svgr/webpack": "^5.5.0",
2122
"classnames": "^2.2.6",

src/components/Giscus.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import Head from '@docusaurus/Head';
2+
import { useLocation } from '@docusaurus/router';
3+
import { useColorMode } from '@docusaurus/theme-common';
4+
import useBaseUrl from '@docusaurus/useBaseUrl';
5+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
6+
import Giscus from "@giscus/react";
7+
import React from 'react';
8+
9+
/**
10+
* Adds a meta-tag to ensure new dicussion always add the canonical link in the initial post.
11+
* Avoids any localhost etc. if first reaction/post was made from a preview build
12+
*
13+
* See https://github.com/giscus/giscus/blob/main/ADVANCED-USAGE.md#giscusbacklink
14+
*/
15+
export function GiscusHead() {
16+
const {
17+
siteConfig: { url: siteUrl },
18+
} = useDocusaurusContext();
19+
const { pathname } = useLocation();
20+
const canonicalUrl = siteUrl + useBaseUrl(pathname);
21+
22+
return (
23+
<Head>
24+
<meta name="giscus:backlink" content={canonicalUrl} />
25+
</Head>
26+
)
27+
}
28+
29+
export function GiscusComponent() {
30+
const { colorMode } = useColorMode();
31+
32+
return (
33+
<Giscus
34+
repo="fflaten/docs"
35+
repoId="MDEwOlJlcG9zaXRvcnkzMDY2ODYxNTc"
36+
category="Comments"
37+
categoryId="DIC_kwDOEkeozc4CWO6M"
38+
mapping="pathname"
39+
strict="1"
40+
reactionsEnabled="1"
41+
emitMetadata="0"
42+
inputPosition="top"
43+
theme={colorMode}
44+
lang="en"
45+
loading="lazy"
46+
crossorigin="anonymous"
47+
async
48+
/>
49+
);
50+
}

src/theme/DocItem/Layout/index.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Unsafe swizzle = might break in future minor upgrades.
3+
* Run "yarn swizzle @docusaurus/theme-classic DocItem/Layout --eject --danger" and compare the diff.
4+
*
5+
* Our customizations are marked with comments below
6+
*/
7+
8+
import React from 'react';
9+
import clsx from 'clsx';
10+
import { useWindowSize } from '@docusaurus/theme-common';
11+
import { useDoc } from '@docusaurus/theme-common/internal';
12+
import DocItemPaginator from '@theme/DocItem/Paginator';
13+
import DocVersionBanner from '@theme/DocVersionBanner';
14+
import DocVersionBadge from '@theme/DocVersionBadge';
15+
import DocItemFooter from '@theme/DocItem/Footer';
16+
import DocItemTOCMobile from '@theme/DocItem/TOC/Mobile';
17+
import DocItemTOCDesktop from '@theme/DocItem/TOC/Desktop';
18+
import DocItemContent from '@theme/DocItem/Content';
19+
import DocBreadcrumbs from '@theme/DocBreadcrumbs';
20+
import styles from './styles.module.css';
21+
/* Customization start */
22+
import { GiscusHead, GiscusComponent } from '../../../components/Giscus';
23+
/* Customization end */
24+
25+
/**
26+
* Decide if the toc should be rendered, on mobile or desktop viewports
27+
*/
28+
function useDocTOC() {
29+
const { frontMatter, toc } = useDoc();
30+
const windowSize = useWindowSize();
31+
const hidden = frontMatter.hide_table_of_contents;
32+
const canRender = !hidden && toc.length > 0;
33+
const mobile = canRender ? <DocItemTOCMobile /> : undefined;
34+
const desktop =
35+
canRender && (windowSize === 'desktop' || windowSize === 'ssr') ? (
36+
<DocItemTOCDesktop />
37+
) : undefined;
38+
return {
39+
hidden,
40+
mobile,
41+
desktop,
42+
};
43+
}
44+
export default function DocItemLayout({ children }) {
45+
const docTOC = useDocTOC();
46+
return (
47+
<div className="row">
48+
<div className={clsx('col', !docTOC.hidden && styles.docItemCol)}>
49+
<DocVersionBanner />
50+
<div className={styles.docItemContainer}>
51+
<article>
52+
<DocBreadcrumbs />
53+
<DocVersionBadge />
54+
{docTOC.mobile}
55+
<DocItemContent>{children}</DocItemContent>
56+
<DocItemFooter />
57+
</article>
58+
<DocItemPaginator />
59+
</div>
60+
{/* Customization start */}
61+
<br />
62+
<GiscusHead />
63+
<GiscusComponent />
64+
{/* Customization end */}
65+
</div>
66+
{docTOC.desktop && <div className="col col--3">{docTOC.desktop}</div>}
67+
</div>
68+
);
69+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.docItemContainer header + *,
2+
.docItemContainer article > *:first-child {
3+
margin-top: 0;
4+
}
5+
6+
@media (min-width: 997px) {
7+
.docItemCol {
8+
max-width: 75% !important;
9+
}
10+
}

yarn.lock

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,13 @@
17311731
url-loader "^4.1.1"
17321732
webpack "^5.73.0"
17331733

1734+
"@giscus/react@^2.2.8":
1735+
version "2.2.8"
1736+
resolved "https://registry.yarnpkg.com/@giscus/react/-/react-2.2.8.tgz#ae02463a0bb27d1decc11e756f41182cc0797288"
1737+
integrity sha512-dPk3GMmsx5hHXXi8Xye7aen+lsZ/PR4I7AwTXKxKtAvxXsH5XAVB/bI6uWr4BrLEH3plZMzgOlVUIPOFJsHQCw==
1738+
dependencies:
1739+
giscus "^1.2.8"
1740+
17341741
"@hapi/hoek@^9.0.0":
17351742
version "9.3.0"
17361743
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.3.0.tgz#8368869dcb735be2e7f5cb7647de78e167a251fb"
@@ -1815,6 +1822,18 @@
18151822
resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b"
18161823
integrity sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A==
18171824

1825+
"@lit-labs/ssr-dom-shim@^1.0.0", "@lit-labs/ssr-dom-shim@^1.1.0":
1826+
version "1.1.1"
1827+
resolved "https://registry.yarnpkg.com/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.1.1.tgz#64df34e2f12e68e78ac57e571d25ec07fa460ca9"
1828+
integrity sha512-kXOeFbfCm4fFf2A3WwVEeQj55tMZa8c8/f9AKHMobQMkzNUfUj+antR3fRPaZJawsa1aZiP/Da3ndpZrwEe4rQ==
1829+
1830+
"@lit/reactive-element@^1.3.0", "@lit/reactive-element@^1.6.0":
1831+
version "1.6.1"
1832+
resolved "https://registry.yarnpkg.com/@lit/reactive-element/-/reactive-element-1.6.1.tgz#0d958b6d479d0e3db5fc1132ecc4fa84be3f0b93"
1833+
integrity sha512-va15kYZr7KZNNPZdxONGQzpUr+4sxVu7V/VG7a8mRfPPXUyhEYj5RzXCQmGrlP3tAh0L3HHm5AjBMFYRqlM9SA==
1834+
dependencies:
1835+
"@lit-labs/ssr-dom-shim" "^1.0.0"
1836+
18181837
"@mdx-js/mdx@^1.6.22":
18191838
version "1.6.22"
18201839
resolved "https://registry.yarnpkg.com/@mdx-js/mdx/-/mdx-1.6.22.tgz#8a723157bf90e78f17dc0f27995398e6c731f1ba"
@@ -2382,6 +2401,11 @@
23822401
dependencies:
23832402
"@types/node" "*"
23842403

2404+
"@types/trusted-types@^2.0.2":
2405+
version "2.0.3"
2406+
resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-2.0.3.tgz#a136f83b0758698df454e328759dbd3d44555311"
2407+
integrity sha512-NfQ4gyz38SL8sDNrSixxU2Os1a5xcdFxipAFxYEuLUlvU2uDwS4NUpsImcf1//SlWItCVMMLiylsxbmNMToV/g==
2408+
23852409
"@types/unist@*", "@types/unist@^2.0.0", "@types/unist@^2.0.2", "@types/unist@^2.0.3":
23862410
version "2.0.6"
23872411
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.6.tgz#250a7b16c3b91f672a24552ec64678eeb1d3a08d"
@@ -4386,6 +4410,13 @@ get-symbol-description@^1.0.0:
43864410
call-bind "^1.0.2"
43874411
get-intrinsic "^1.1.1"
43884412

4413+
giscus@^1.2.8:
4414+
version "1.2.8"
4415+
resolved "https://registry.yarnpkg.com/giscus/-/giscus-1.2.8.tgz#557964e1cb5e46c4b0abf69ed0b974c0718b8142"
4416+
integrity sha512-pufrgQYt1W+4ztiWp/PilLPN8NdyKvpbQ8jNqbAa1g84t6qqyevXHfkOYCi4x4d+y191vJAUc6seL1Dq74yUeA==
4417+
dependencies:
4418+
lit "^2.6.1"
4419+
43894420
github-slugger@^1.4.0:
43904421
version "1.5.0"
43914422
resolved "https://registry.yarnpkg.com/github-slugger/-/github-slugger-1.5.0.tgz#17891bbc73232051474d68bd867a34625c955f7d"
@@ -5329,6 +5360,31 @@ lines-and-columns@^1.1.6:
53295360
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632"
53305361
integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==
53315362

5363+
lit-element@^3.3.0:
5364+
version "3.3.2"
5365+
resolved "https://registry.yarnpkg.com/lit-element/-/lit-element-3.3.2.tgz#9913bf220b85065f0e5f1bb8878cc44f36b50cfa"
5366+
integrity sha512-xXAeVWKGr4/njq0rGC9dethMnYCq5hpKYrgQZYTzawt9YQhMiXfD+T1RgrdY3NamOxwq2aXlb0vOI6e29CKgVQ==
5367+
dependencies:
5368+
"@lit-labs/ssr-dom-shim" "^1.1.0"
5369+
"@lit/reactive-element" "^1.3.0"
5370+
lit-html "^2.7.0"
5371+
5372+
lit-html@^2.7.0:
5373+
version "2.7.3"
5374+
resolved "https://registry.yarnpkg.com/lit-html/-/lit-html-2.7.3.tgz#903bfa61f9d3296a0ec94128695e452beb9b1a3a"
5375+
integrity sha512-9DyLzcn/kbRGowz2vFmSANFbRZTxYUgYYFqzie89w6GLpPUiBCDHfcdeRUV/k3Q2ueYxNjfv46yPCtKAEAPOVw==
5376+
dependencies:
5377+
"@types/trusted-types" "^2.0.2"
5378+
5379+
lit@^2.6.1:
5380+
version "2.7.3"
5381+
resolved "https://registry.yarnpkg.com/lit/-/lit-2.7.3.tgz#7f7920dbaba12828d359ca3439cd6f73619061da"
5382+
integrity sha512-0a+u+vVbmgSfPu+fyvqjMPBX0Kwbyj9QOv9MbQFZhWGlV2cyk3lEwgfUQgYN+i/lx++1Z3wZknSIp3QCKxHLyg==
5383+
dependencies:
5384+
"@lit/reactive-element" "^1.6.0"
5385+
lit-element "^3.3.0"
5386+
lit-html "^2.7.0"
5387+
53325388
loader-runner@^4.2.0:
53335389
version "4.3.0"
53345390
resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-4.3.0.tgz#c1b4a163b99f614830353b16755e7149ac2314e1"

0 commit comments

Comments
 (0)