From 503a0a88a55662c687ad9b7ece12d464ed8e9314 Mon Sep 17 00:00:00 2001 From: corlard3y Date: Fri, 13 Sep 2024 16:03:37 +0100 Subject: [PATCH] update plugin page --- .github/workflows/preview.yml | 7 +- docusaurus.config.js | 7 +- plugins/blog-plugin.js | 4 +- src/theme/NotFound/index.tsx | 5 +- src/theme/Root.js | 198 ++++++++++------------------------ src/theme/ServerStyle.js | 4 +- 6 files changed, 70 insertions(+), 155 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 55b03236552..7ded32d495e 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -25,12 +25,17 @@ jobs: echo "GENERATE_SOURCEMAP=true" >> $GITHUB_ENV - name: Checkout uses: actions/checkout@v3 + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: 16.x + cache: yarn - name: Install and Build if: github.event.action != 'closed' # You might want to skip the build if the PR has been closed run: | - yarn install + yarn install --frozen-lockfile --non-interactive yarn build:pr:preview - name: Deploy preview diff --git a/docusaurus.config.js b/docusaurus.config.js index 02c3a02e747..e00d6fb25f8 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -16,9 +16,10 @@ const config = { : 'https://push.org/', // Set the // pathname under which your site is served // For GitHub pages deployment, it is often '//' - baseUrl: - `/push-website/pr-preview/${process.env.REACT_APP_PREVIEW_BASE}` || '/', - trailingSlash: true, + baseUrl: process.env.GITHUB_ACTIONS + ? `/push-website/pr-preview/${process.env.REACT_APP_PREVIEW_BASE}` + : '/', + trailingSlash: false, // GitHub pages deployment config. // If you aren't using GitHub pages, you don't need these. diff --git a/plugins/blog-plugin.js b/plugins/blog-plugin.js index bdeb0511050..449cfe8e828 100644 --- a/plugins/blog-plugin.js +++ b/plugins/blog-plugin.js @@ -79,7 +79,9 @@ async function blogPluginExtended(...pluginArgs) { actions.addRoute({ // Add route for the home page - path: '/', + path: process.env.GITHUB_ACTIONS + ? `/push-website/pr-preview/${process.env.REACT_APP_PREVIEW_BASE}` + : '/push-website/pr-preview/', exact: true, // The component to use for the "Home" page route diff --git a/src/theme/NotFound/index.tsx b/src/theme/NotFound/index.tsx index f90c7224fab..0973d0a5069 100644 --- a/src/theme/NotFound/index.tsx +++ b/src/theme/NotFound/index.tsx @@ -11,12 +11,10 @@ import { PageMetadata } from '@docusaurus/theme-common'; import Layout from '@theme/Layout'; import NotFoundContent from '@theme/NotFound/Content'; import { useLocation } from '@docusaurus/router'; -import { getPreviewBasePath } from '../../../basePath'; export default function Index(): JSX.Element { const location = useLocation(); - const previewBasePath = getPreviewBasePath(); - const pathname = previewBasePath || location.pathname; + const pathname = location.pathname; const title = translate({ id: 'theme.NotFound.title', @@ -34,6 +32,7 @@ export default function Index(): JSX.Element { } > +
koko
); diff --git a/src/theme/Root.js b/src/theme/Root.js index 55c67748bad..444babf3fa9 100644 --- a/src/theme/Root.js +++ b/src/theme/Root.js @@ -1,140 +1,20 @@ -// // React + Web3 Essentials -// import { useLocation } from '@docusaurus/router'; -// import React from 'react'; - -// // External Components -// import i18nInitialize from '@site/src/utils/i18n'; - -// // Internal Components -// import Footer from '@site/src/segments/Footer'; -// import ServerStyle from '@site/src/theme/ServerStyle'; -// import CookieComponent from '../components/CookieComponent'; -// import { getPreviewBasePath } from '../../basePath'; - -// // Initialize Internalization -// i18nInitialize(); - -// export default function Root({ children }) { -// const previewBasePath = getPreviewBasePath(); - -// // superimposed conditions -// const superimposedConditions = [ -// { -// classname: 'DocsHub PushDocs DocusaurusNavbar NavBarDark', -// pathname: '/DOCS', -// condition: 'exact', -// }, -// { -// classname: 'PushDocs DocusaurusNavbar', -// pathname: '/DOCS', -// condition: 'subpaths', -// }, -// { -// classname: 'BlogHub PushBlog DocusaurusNavbar', -// pathname: '/BLOG', -// condition: 'exact', -// }, -// { -// classname: 'PushBlog DocusaurusNavbar', -// pathname: '/BLOG', -// condition: 'subpaths', -// }, -// ]; - -// // return superimposed class names if conditions are met -// function returnAdditionalClasses(conditions) { -// let result = ''; -// for (var i = 0; i < conditions.length; i++) { -// const item = conditions[i]; - -// if (locationPathExists(item.pathname, item.condition)) { -// result = item.classname; -// break; -// } -// } - -// // return result -// return result; -// } - -// // enable disable default config -// function excludeDefaultConfigAt(pathname, condition) { -// return !locationPathExists(pathname, condition); -// } - -// // check if location path exists -// function locationPathExists(pathname, condition, comingfrom = null) { -// let result = false; -// pathname = pathname.toUpperCase(); - -// // Define location -// const location = previewBasePath || useLocation(); - -// const str = location.pathname.toUpperCase(); -// const modstr = -// str != null && str.length >= pathname.length -// ? str.substring(0, pathname.length) -// : null; - -// result = modstr === pathname ? true : false; -// if (condition === 'exact' || condition === 'subpaths') { -// // check if sub path exist in pathname and change result; -// if ( -// str.length > pathname.length && -// str.substring(0, pathname.length) === pathname -// ) { -// // path has more -// const remainingLength = -// str.substring(pathname.length, pathname.length + 1) === '/' -// ? str.length - pathname.length - 1 -// : str.length - pathname.length; - -// if (condition === 'exact') { -// result = remainingLength == 0 ? true : false; -// } else if (condition === 'subpaths') { -// result = remainingLength > 0 ? true : false; -// } -// } -// } - -// return result; -// } - -// return ( -//
-// - -// {/* Main react children */} -// {children} - -// {excludeDefaultConfigAt('/BRB') && -// excludeDefaultConfigAt('/DOCS') && -// excludeDefaultConfigAt('/BOOTCAMP') && ( -// <> -//
-// -// -// )} -//
-// ); -// } - +// React + Web3 Essentials import { useLocation } from '@docusaurus/router'; import React from 'react'; + +// External Components import i18nInitialize from '@site/src/utils/i18n'; + +// Internal Components import Footer from '@site/src/segments/Footer'; import ServerStyle from '@site/src/theme/ServerStyle'; import CookieComponent from '../components/CookieComponent'; -import { getPreviewBasePath } from '../../basePath'; // Initialize Internalization i18nInitialize(); export default function Root({ children }) { - const location = useLocation(); // Correctly use useLocation - const previewBasePath = getPreviewBasePath(); - - // Superimposed conditions + // superimposed conditions const superimposedConditions = [ { classname: 'DocsHub PushDocs DocusaurusNavbar NavBarDark', @@ -158,42 +38,72 @@ export default function Root({ children }) { }, ]; - // Return additional classes based on conditions - const returnAdditionalClasses = (conditions) => { + // return superimposed class names if conditions are met + function returnAdditionalClasses(conditions) { let result = ''; - for (const item of conditions) { + for (var i = 0; i < conditions.length; i++) { + const item = conditions[i]; + if (locationPathExists(item.pathname, item.condition)) { result = item.classname; break; } } + + // return result return result; - }; + } + + // enable disable default config + function excludeDefaultConfigAt(pathname, condition) { + return !locationPathExists(pathname, condition); + } - // Check if location path exists - const locationPathExists = (pathname, condition) => { - const str = (previewBasePath || location.pathname).toUpperCase(); + // check if location path exists + function locationPathExists(pathname, condition) { + let result = false; pathname = pathname.toUpperCase(); - if (str.startsWith(pathname)) { - const remainingLength = str.length - pathname.length; - if (condition === 'exact') { - return remainingLength === 0; - } else if (condition === 'subpaths') { - return remainingLength > 0; + // Define location + const location = useLocation(); + + const str = location.pathname.toUpperCase(); + const modstr = + str != null && str.length >= pathname.length + ? str.substring(0, pathname.length) + : null; + + result = modstr === pathname ? true : false; + if (condition === 'exact' || condition === 'subpaths') { + // check if sub path exist in pathname and change result; + if ( + str.length > pathname.length && + str.substring(0, pathname.length) === pathname + ) { + // path has more + const remainingLength = + str.substring(pathname.length, pathname.length + 1) === '/' + ? str.length - pathname.length - 1 + : str.length - pathname.length; + + if (condition === 'exact') { + result = remainingLength == 0 ? true : false; + } else if (condition === 'subpaths') { + result = remainingLength > 0 ? true : false; + } } } - return false; - }; - // Exclude default configuration for certain paths - const excludeDefaultConfigAt = (pathname) => - !locationPathExists(pathname, 'exact'); + return result; + } return (
+ + {/* Main react children */} {children} + {excludeDefaultConfigAt('/BRB') && excludeDefaultConfigAt('/DOCS') && excludeDefaultConfigAt('/BOOTCAMP') && ( diff --git a/src/theme/ServerStyle.js b/src/theme/ServerStyle.js index 9603dccd1fd..8f1f4693e59 100644 --- a/src/theme/ServerStyle.js +++ b/src/theme/ServerStyle.js @@ -13,7 +13,6 @@ import { ServerStyleSheet } from 'styled-components'; import Footer from '@site/src/segments/Footer'; import Header from '@site/src/segments/Header'; import { CookiesProvider } from 'react-cookie'; -import { getPreviewBasePath } from '../../basePath'; function ServerStyle({ from: children }) { let style = null; @@ -21,13 +20,12 @@ function ServerStyle({ from: children }) { const location = useLocation(); const context = useDocusaurusContext(); const sheet = new ServerStyleSheet(); - const previewBasePath = getPreviewBasePath(); try { renderToString( sheet.collectStyles( - +