Merge pull request #764 from slumbering/bump-up-docusaurus-core-2.0.0-beta.2
This commit is contained in:
commit
26f9990507
@ -16,8 +16,8 @@
|
|||||||
"write-heading-ids": "docusaurus write-heading-ids"
|
"write-heading-ids": "docusaurus write-heading-ids"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@docusaurus/core": "2.0.0-beta.0",
|
"@docusaurus/core": "2.0.0-beta.2",
|
||||||
"@docusaurus/preset-classic": "2.0.0-beta.0",
|
"@docusaurus/preset-classic": "2.0.0-beta.2",
|
||||||
"@mdx-js/react": "^1.6.21",
|
"@mdx-js/react": "^1.6.21",
|
||||||
"@svgr/webpack": "^5.5.0",
|
"@svgr/webpack": "^5.5.0",
|
||||||
"amplitude-js": "^8.3.1",
|
"amplitude-js": "^8.3.1",
|
||||||
|
47
website/src/components/DocPageCustom.js
Normal file
47
website/src/components/DocPageCustom.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import qs from 'querystringify';
|
||||||
|
import isEmpty from 'lodash/isEmpty';
|
||||||
|
import { checkUserCollaboratorStatus } from '../api/github'
|
||||||
|
import Spinner from './Spinner';
|
||||||
|
import DocPageAuthentication from './DocPageAuthentication';
|
||||||
|
import DocPageRedirect from './DocPageRedirect';
|
||||||
|
|
||||||
|
function DocPageCustom({ location, userAccessStatus, setUserAccessStatus }) {
|
||||||
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
|
const [redirectState, setRedirectState] = useState()
|
||||||
|
const authQuery = qs.parse(location.search);
|
||||||
|
|
||||||
|
useEffect(async () => {
|
||||||
|
if (!isEmpty(authQuery) && userAccessStatus === null) { //callback after successful auth with github
|
||||||
|
const user = await checkUserCollaboratorStatus(authQuery.code);
|
||||||
|
setUserAccessStatus(user)
|
||||||
|
if (user?.permission) {
|
||||||
|
window.localStorage.setItem('user', JSON.stringify(user));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setIsLoading(false)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
import('amplitude-js').then(amplitude => {
|
||||||
|
if (userAccessStatus?.login) {
|
||||||
|
var amplitudeInstance = amplitude.getInstance().init(process.env.REACT_APP_AMPLITUDE_ID, userAccessStatus?.login.toLowerCase(), {
|
||||||
|
apiEndpoint: `${window.location.hostname}/t`
|
||||||
|
});
|
||||||
|
amplitude.getInstance().logEvent('Docs Viewed', { "hostname": window.location.hostname, "path": location.pathname });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, [location.pathname, userAccessStatus])
|
||||||
|
|
||||||
|
if (isLoading) return <Spinner />
|
||||||
|
|
||||||
|
if (userAccessStatus?.permission === false) {
|
||||||
|
return <DocPageRedirect />
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userAccessStatus === null) {
|
||||||
|
return <DocPageAuthentication />
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DocPageCustom
|
@ -80,6 +80,7 @@ h2 {
|
|||||||
|
|
||||||
code {
|
code {
|
||||||
margin: 0 1px;
|
margin: 0 1px;
|
||||||
|
color: var(--ifm-code-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown {
|
.markdown {
|
||||||
@ -139,6 +140,7 @@ h1[class^="docTitle"] {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
margin: 2rem 0 5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#__docusaurus {
|
#__docusaurus {
|
||||||
@ -170,7 +172,7 @@ h1[class^="docTitle"] {
|
|||||||
|
|
||||||
// sidebar
|
// sidebar
|
||||||
@media (min-width: 997px) {
|
@media (min-width: 997px) {
|
||||||
div[class^="docSidebarContainer"] {
|
aside[class^="docSidebarContainer"] {
|
||||||
width: 250px;
|
width: 250px;
|
||||||
margin-right: 3rem;
|
margin-right: 3rem;
|
||||||
|
|
||||||
@ -234,11 +236,15 @@ div[class^="codeBlockContainer"] {
|
|||||||
border-bottom-left-radius: 0;
|
border-bottom-left-radius: 0;
|
||||||
border-bottom-right-radius: 0;
|
border-bottom-right-radius: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
border-radius: var(--ifm-global-radius);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
div[class^="codeBlockLines"] {
|
code[class^="codeBlockLines"] {
|
||||||
background-color: var(--ifm-color-primary-dark) !important;
|
background-color: var(--ifm-color-primary-dark) !important;
|
||||||
margin-bottom: 0;
|
margin: 0;
|
||||||
.token-line {
|
.token-line {
|
||||||
color: var(--ifm-color-primary-light) !important;
|
color: var(--ifm-color-primary-light) !important;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* This source code is licensed under the MIT license found in the
|
* This source code is licensed under the MIT license found in the
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
import React, { useState, useEffect, useCallback } from 'react';
|
import React, { useState, useCallback } from 'react';
|
||||||
import { MDXProvider } from '@mdx-js/react';
|
import { MDXProvider } from '@mdx-js/react';
|
||||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||||
import renderRoutes from '@docusaurus/renderRoutes';
|
import renderRoutes from '@docusaurus/renderRoutes';
|
||||||
@ -18,21 +18,40 @@ import { translate } from '@docusaurus/Translate';
|
|||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
import { ThemeClassNames, docVersionSearchTag } from '@docusaurus/theme-common';
|
import { ThemeClassNames, docVersionSearchTag } from '@docusaurus/theme-common';
|
||||||
import { Redirect } from "react-router";
|
import DocPageCustom from '../../components/DocPageCustom'
|
||||||
import qs from 'querystringify';
|
|
||||||
import isEmpty from 'lodash/isEmpty';
|
|
||||||
import { checkUserCollaboratorStatus } from '../../api/github'
|
|
||||||
import { GithubLoginButton } from 'react-social-login-buttons';
|
|
||||||
import Spinner from '../../components/Spinner';
|
|
||||||
import DocPageAuthentication from '../../components/DocPageAuthentication';
|
|
||||||
import DocPageRedirect from '../../components/DocPageRedirect';
|
|
||||||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
||||||
|
|
||||||
|
function getSidebar({ versionMetadata, currentDocRoute }) {
|
||||||
|
function addTrailingSlash(str) {
|
||||||
|
return str.endsWith('/') ? str : `${str}/`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeTrailingSlash(str) {
|
||||||
|
return str.endsWith('/') ? str.slice(0, -1) : str;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { permalinkToSidebar, docsSidebars } = versionMetadata; // With/without trailingSlash, we should always be able to get the appropriate sidebar
|
||||||
|
// note: docs plugin permalinks currently never have trailing slashes
|
||||||
|
// trailingSlash is handled globally at the framework level, not plugin level
|
||||||
|
|
||||||
|
const sidebarName =
|
||||||
|
permalinkToSidebar[currentDocRoute.path] ||
|
||||||
|
permalinkToSidebar[addTrailingSlash(currentDocRoute.path)] ||
|
||||||
|
permalinkToSidebar[removeTrailingSlash(currentDocRoute.path)];
|
||||||
|
const sidebar = docsSidebars[sidebarName];
|
||||||
|
return {
|
||||||
|
sidebar,
|
||||||
|
sidebarName,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function DocPageContent({ currentDocRoute, versionMetadata, children }) {
|
function DocPageContent({ currentDocRoute, versionMetadata, children }) {
|
||||||
const { siteConfig, isClient } = useDocusaurusContext();
|
const { siteConfig, isClient } = useDocusaurusContext();
|
||||||
const { pluginId, permalinkToSidebar, docsSidebars, version } = versionMetadata;
|
const { pluginId, version } = versionMetadata;
|
||||||
const sidebarName = permalinkToSidebar[currentDocRoute.path];
|
const { sidebarName, sidebar } = getSidebar({
|
||||||
const sidebar = docsSidebars[sidebarName];
|
versionMetadata,
|
||||||
|
currentDocRoute,
|
||||||
|
});
|
||||||
const [hiddenSidebarContainer, setHiddenSidebarContainer] = useState(false);
|
const [hiddenSidebarContainer, setHiddenSidebarContainer] = useState(false);
|
||||||
const [hiddenSidebar, setHiddenSidebar] = useState(false);
|
const [hiddenSidebar, setHiddenSidebar] = useState(false);
|
||||||
const toggleSidebar = useCallback(() => {
|
const toggleSidebar = useCallback(() => {
|
||||||
@ -42,7 +61,6 @@ function DocPageContent({ currentDocRoute, versionMetadata, children }) {
|
|||||||
|
|
||||||
setHiddenSidebarContainer(!hiddenSidebarContainer);
|
setHiddenSidebarContainer(!hiddenSidebarContainer);
|
||||||
}, [hiddenSidebar]);
|
}, [hiddenSidebar]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout
|
<Layout
|
||||||
key={isClient}
|
key={isClient}
|
||||||
@ -54,7 +72,7 @@ function DocPageContent({ currentDocRoute, versionMetadata, children }) {
|
|||||||
}}>
|
}}>
|
||||||
<div className={styles.docPage}>
|
<div className={styles.docPage}>
|
||||||
{sidebar && (
|
{sidebar && (
|
||||||
<div
|
<aside
|
||||||
className={clsx(styles.docSidebarContainer, {
|
className={clsx(styles.docSidebarContainer, {
|
||||||
[styles.docSidebarContainerHidden]: hiddenSidebarContainer,
|
[styles.docSidebarContainerHidden]: hiddenSidebarContainer,
|
||||||
})}
|
})}
|
||||||
@ -68,8 +86,7 @@ function DocPageContent({ currentDocRoute, versionMetadata, children }) {
|
|||||||
if (hiddenSidebarContainer) {
|
if (hiddenSidebarContainer) {
|
||||||
setHiddenSidebar(true);
|
setHiddenSidebar(true);
|
||||||
}
|
}
|
||||||
}}
|
}}>
|
||||||
role="complementary">
|
|
||||||
<DocSidebar
|
<DocSidebar
|
||||||
key={
|
key={
|
||||||
// Reset sidebar state on sidebar changes
|
// Reset sidebar state on sidebar changes
|
||||||
@ -107,7 +124,7 @@ function DocPageContent({ currentDocRoute, versionMetadata, children }) {
|
|||||||
<IconArrow className={styles.expandSidebarButtonIcon} />
|
<IconArrow className={styles.expandSidebarButtonIcon} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</aside>
|
||||||
)}
|
)}
|
||||||
<main
|
<main
|
||||||
className={clsx(styles.docMainContainer, {
|
className={clsx(styles.docMainContainer, {
|
||||||
@ -116,7 +133,7 @@ function DocPageContent({ currentDocRoute, versionMetadata, children }) {
|
|||||||
})}>
|
})}>
|
||||||
<div
|
<div
|
||||||
className={clsx(
|
className={clsx(
|
||||||
'container padding-vert--lg',
|
'container padding-top--md padding-bottom--lg',
|
||||||
styles.docItemWrapper,
|
styles.docItemWrapper,
|
||||||
{
|
{
|
||||||
[styles.docItemWrapperEnhanced]: hiddenSidebarContainer,
|
[styles.docItemWrapperEnhanced]: hiddenSidebarContainer,
|
||||||
@ -141,50 +158,15 @@ function DocPage(props) {
|
|||||||
);
|
);
|
||||||
const userAgent = ExecutionEnvironment.canUseDOM ? navigator.userAgent : null;
|
const userAgent = ExecutionEnvironment.canUseDOM ? navigator.userAgent : null;
|
||||||
|
|
||||||
// CUSTOM DOCPAGE
|
// DocPage Swizzle
|
||||||
if (process.env.OAUTH_ENABLE == 'true' && userAgent !== 'Algolia DocSearch Crawler') {
|
const [userAccessStatus, setUserAccessStatus] = useState((() => {
|
||||||
const [isLoading, setIsLoading] = useState(true)
|
if (typeof window !== "undefined") return JSON.parse(window.localStorage.getItem('user'))
|
||||||
const [redirectState, setRedirectState] = useState()
|
})())
|
||||||
const authQuery = qs.parse(location.search);
|
|
||||||
const [userAccessStatus, setUserAccessStatus] = useState((() => {
|
|
||||||
if (typeof window !== "undefined") return JSON.parse(window.localStorage.getItem('user'))
|
|
||||||
})())
|
|
||||||
|
|
||||||
useEffect(async () => {
|
if (process.env.OAUTH_ENABLE == 'true' && userAccessStatus?.permission !== true && userAgent !== 'Algolia DocSearch Crawler') {
|
||||||
if (!isEmpty(authQuery) && userAccessStatus === null) { //callback after successful auth with github
|
return <DocPageCustom location={location} userAccessStatus={userAccessStatus} setUserAccessStatus={setUserAccessStatus} />
|
||||||
const user = await checkUserCollaboratorStatus(authQuery.code);
|
|
||||||
setUserAccessStatus(user)
|
|
||||||
if (user?.permission) {
|
|
||||||
if (typeof window !== "undefined") window.localStorage.setItem('user', JSON.stringify(user));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setIsLoading(false)
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
import('amplitude-js').then(amplitude => {
|
|
||||||
if (userAccessStatus?.login) {
|
|
||||||
var amplitudeInstance = amplitude.getInstance().init(process.env.REACT_APP_AMPLITUDE_ID, userAccessStatus?.login.toLowerCase(), {
|
|
||||||
apiEndpoint: `${window.location.hostname}/t`
|
|
||||||
});
|
|
||||||
amplitude.getInstance().logEvent('Docs Viewed', { "hostname": window.location.hostname, "path": location.pathname });
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}, [location.pathname, userAccessStatus])
|
|
||||||
|
|
||||||
if (isLoading) return <Spinner />
|
|
||||||
|
|
||||||
if (userAccessStatus?.permission === false) {
|
|
||||||
return <DocPageRedirect />
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userAccessStatus === null) {
|
|
||||||
return (
|
|
||||||
<DocPageAuthentication />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// END CUSTOM DOCPAGE
|
// End DocPageSwizzle
|
||||||
|
|
||||||
if (!currentDocRoute) {
|
if (!currentDocRoute) {
|
||||||
return <NotFound {...props} />;
|
return <NotFound {...props} />;
|
||||||
@ -194,7 +176,9 @@ function DocPage(props) {
|
|||||||
<DocPageContent
|
<DocPageContent
|
||||||
currentDocRoute={currentDocRoute}
|
currentDocRoute={currentDocRoute}
|
||||||
versionMetadata={versionMetadata}>
|
versionMetadata={versionMetadata}>
|
||||||
{renderRoutes(docRoutes)}
|
{renderRoutes(docRoutes, {
|
||||||
|
versionMetadata,
|
||||||
|
})}
|
||||||
</DocPageContent>
|
</DocPageContent>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
:root {
|
:root {
|
||||||
--doc-sidebar-width: 300px;
|
--doc-sidebar-width: 300px;
|
||||||
|
--doc-sidebar-hidden-width: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
:global(.docs-wrapper) {
|
:global(.docs-wrapper) {
|
||||||
@ -26,7 +27,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.docMainContainerEnhanced {
|
.docMainContainerEnhanced {
|
||||||
max-width: none;
|
max-width: calc(100% - var(--doc-sidebar-hidden-width));
|
||||||
}
|
}
|
||||||
|
|
||||||
.docSidebarContainer {
|
.docSidebarContainer {
|
||||||
@ -39,7 +40,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.docSidebarContainerHidden {
|
.docSidebarContainerHidden {
|
||||||
width: 30px;
|
width: var(--doc-sidebar-hidden-width);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,27 +73,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.docItemWrapperEnhanced {
|
.docItemWrapperEnhanced {
|
||||||
max-width: calc(var(--ifm-container-width) + var(--doc-sidebar-width));
|
max-width: calc(
|
||||||
|
var(--ifm-container-width) + var(--doc-sidebar-width)
|
||||||
|
) !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 996px) {
|
@media (max-width: 996px) {
|
||||||
.docSidebarContainer {
|
.docSidebarContainer {
|
||||||
margin-top: 0;
|
display: none;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (min-width: 997px) and (max-width: 1320px) {
|
|
||||||
.docItemWrapper {
|
|
||||||
max-width: calc(
|
|
||||||
var(--ifm-container-width) - var(--doc-sidebar-width) -
|
|
||||||
var(--ifm-spacing-horizontal) * 2
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
.docItemWrapperEnhanced {
|
|
||||||
max-width: calc(
|
|
||||||
var(--ifm-container-width) - var(--ifm-spacing-horizontal) * 2
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,20 @@ import './styles.css';
|
|||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
import AnchorIcon from "./anchor.svg"
|
import AnchorIcon from "./anchor.svg"
|
||||||
|
|
||||||
const Heading = (Tag) =>
|
export const MainHeading = function MainHeading({...props}) {
|
||||||
|
return (
|
||||||
|
<header>
|
||||||
|
<h1
|
||||||
|
{...props}
|
||||||
|
id={undefined} // h1 headings do not need an id because they don't appear in the TOC
|
||||||
|
className={styles.h1Heading}>
|
||||||
|
{props.children}
|
||||||
|
</h1>
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const createAnchorHeading = (Tag) =>
|
||||||
function TargetComponent({id, ...props}) {
|
function TargetComponent({id, ...props}) {
|
||||||
const {
|
const {
|
||||||
navbar: {hideOnScroll},
|
navbar: {hideOnScroll},
|
||||||
@ -49,4 +62,8 @@ const Heading = (Tag) =>
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Heading = (headingType) => {
|
||||||
|
return headingType === 'h1' ? MainHeading : createAnchorHeading(headingType);
|
||||||
|
};
|
||||||
|
|
||||||
export default Heading;
|
export default Heading;
|
||||||
|
@ -8,3 +8,8 @@
|
|||||||
.enhancedAnchor {
|
.enhancedAnchor {
|
||||||
top: calc(var(--ifm-navbar-height) * -1 - 0.5rem);
|
top: calc(var(--ifm-navbar-height) * -1 - 0.5rem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.h1Heading {
|
||||||
|
font-size: 3rem;
|
||||||
|
margin-bottom: calc(var(--ifm-leading-desktop) * var(--ifm-leading));
|
||||||
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user