Skip to content

Commit

Permalink
update plugin page
Browse files Browse the repository at this point in the history
  • Loading branch information
corlard3y committed Sep 13, 2024
1 parent dfc0e6f commit 503a0a8
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 155 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const config = {
: 'https://push.org/',
// Set the /<baseUrl>/ pathname under which your site is served
// For GitHub pages deployment, it is often '/<projectName>/'
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.
Expand Down
4 changes: 3 additions & 1 deletion plugins/blog-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/theme/NotFound/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -34,6 +32,7 @@ export default function Index(): JSX.Element {
}
>
<NotFoundContent />
<div>koko</div>
</Layout>
</>
);
Expand Down
198 changes: 54 additions & 144 deletions src/theme/Root.js
Original file line number Diff line number Diff line change
@@ -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 (
// <div className={returnAdditionalClasses(superimposedConditions)}>
// <ServerStyle from={children} />

// {/* Main react children */}
// {children}

// {excludeDefaultConfigAt('/BRB') &&
// excludeDefaultConfigAt('/DOCS') &&
// excludeDefaultConfigAt('/BOOTCAMP') && (
// <>
// <Footer />
// <CookieComponent />
// </>
// )}
// </div>
// );
// }

// 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',
Expand All @@ -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 (
<div className={returnAdditionalClasses(superimposedConditions)}>
<ServerStyle from={children} />

{/* Main react children */}
{children}

{excludeDefaultConfigAt('/BRB') &&
excludeDefaultConfigAt('/DOCS') &&
excludeDefaultConfigAt('/BOOTCAMP') && (
Expand Down
4 changes: 1 addition & 3 deletions src/theme/ServerStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@ 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;

const location = useLocation();
const context = useDocusaurusContext();
const sheet = new ServerStyleSheet();
const previewBasePath = getPreviewBasePath();

try {
renderToString(
sheet.collectStyles(
<HelmetProvider>
<StaticRouter location={previewBasePath || location}>
<StaticRouter location={location}>
<CookiesProvider>
<DocusaurusContext.Provider value={context}>
<Header />
Expand Down

0 comments on commit 503a0a8

Please sign in to comment.