Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCS]chore: optimisation #971

Merged
merged 14 commits into from
Oct 2, 2023
5 changes: 5 additions & 0 deletions .changeset/wicked-squids-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kadena/docs': minor
---

updating to next 13.5 and some small performance updates
2 changes: 1 addition & 1 deletion packages/apps/docs/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { darkThemeClass } from '@kadena/react-ui/theme';

import { themes } from '@storybook/theming';
import { RouterContext } from 'next/dist/shared/lib/router-context'; // next 12
import { RouterContext } from 'next/dist/shared/lib/router-context.shared-runtime'; // next 13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed to fix the build after next update


export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
Expand Down
3 changes: 3 additions & 0 deletions packages/apps/docs/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ const nextConfig = {
eslint: {
ignoreDuringBuilds: true, // lint is a different task/phase
},

pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
reactStrictMode: true,
productionBrowserSourceMaps: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we enabling sourcemaps for prod?


transpilePackages: ['@kadena/react-ui', 'react-tweet'],
images: {
remotePatterns: [
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"mdast-util-to-markdown": "~1.5.0",
"mdast-util-to-string": "~3.2.0",
"mobx": "~6.9.0",
"next": "13.4.5",
"next": "13.5.3",
"next-themes": "~0.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ export const BottomPageSection: FC<IProps> = ({
)}
</Stack>
<Divider />
<Stack justifyContent="space-between" width="100%">
<Stack
direction={{ xs: 'column', lg: 'row' }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aligning the subscribe and the helpful component on mobile

justifyContent="space-between"
width="100%"
>
<PageHelpful editLink={editLink} />
<Subscribe />
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { Stack, Text } from '@kadena/react-ui';

import { formatISODate } from '@/utils/dates';
import { isValid } from 'date-fns';
import type { FC } from 'react';
import React from 'react';

Expand All @@ -11,7 +12,7 @@ interface IProps {
}

export const LastModifiedDate: FC<IProps> = ({ date }) => {
if (!date) return null;
if (!isValid(date) || !date) return null;
const dateString = formatISODate(date);
return (
<Stack justifyContent="flex-end">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import { asideListClass, asideListInnerVariants } from './styles.css';

import classNames from 'classnames';
import type { FC, ReactNode } from 'react';
import type { ReactNode } from 'react';
import React from 'react';

interface IProps {
children: ReactNode;
inner?: boolean;
// eslint-disable-next-line @rushstack/no-new-null
ref?: React.MutableRefObject<HTMLUListElement | null>;
}

export const AsideList: FC<IProps> = ({ children, inner = false, ref }) => {
const classes = classNames(
asideListClass,
asideListInnerVariants[inner ? 'true' : 'false'],
);
return (
<ul ref={ref} className={classes}>
{children}
</ul>
);
};
export const AsideList = React.forwardRef<HTMLUListElement, IProps>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes a console warning

({ children, inner = false }, ref) => {
const classes = classNames(
asideListClass,
asideListInnerVariants[inner ? 'true' : 'false'],
);
return (
<ul ref={ref} className={classes}>
{children}
</ul>
);
},
);

AsideList.displayName = 'AsideList';
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,37 @@ export const HomeHeader: FC<IProps> = ({ popularPages }) => {
return (
<header className={loaderHeaderClass}>
<div className={wrapperClass}>
<Grid.Root columns={{ sm: 1, md: 2 }}>
<Grid.Item>
<Heading as="h1" variant="h2">
Kadena
</Heading>
<Stack direction="column" gap="$2xs">
<Heading as="h2" variant="h4">
Build your <GradientText>own</GradientText> Internet
<Box marginX={{ xs: '$1', sm: '$4' }}>
<Grid.Root columns={{ sm: 1, md: 2 }}>
<Grid.Item>
<Heading as="h1" variant="h2">
Kadena
</Heading>
<span className={subheaderClass}>
Explore our guides and examples to build on Kadena
</span>
<Stack direction="column" gap="$2xs">
<Heading as="h2" variant="h4">
Build your <GradientText>own</GradientText> Internet
</Heading>
<span className={subheaderClass}>
Explore our guides and examples to build on Kadena
</span>

<Box marginTop="$5" marginRight="$40">
<SearchBar onKeyUp={handleKeyPress} />
</Box>
</Stack>
</Grid.Item>
<Grid.Item>
{popularPages.length > 0 && (
<Box
paddingLeft={{ sm: '$1', lg: '$15', xl: '$32', xxl: '$48' }}
marginRight="$10"
>
<MostPopular pages={popularPages} title="Most viewed docs" />
</Box>
)}
</Grid.Item>
</Grid.Root>
<Box marginTop="$5" marginRight="$40">
<SearchBar onKeyUp={handleKeyPress} />
</Box>
</Stack>
</Grid.Item>
<Grid.Item>
{popularPages.length > 0 && (
<Box
paddingLeft={{ sm: '$1', lg: '$15', xl: '$32', xxl: '$48' }}
marginRight="$10"
>
<MostPopular pages={popularPages} title="Most viewed docs" />
</Box>
)}
</Grid.Item>
</Grid.Root>
</Box>
</div>
</header>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import { style } from '@vanilla-extract/css';
export const headerClass = style([
sprinkles({
position: 'relative',
margin: 0,
padding: 0,
}),
{
width: '100vw',
gridArea: 'pageheader',
zIndex: 2,
selectors: {
Expand Down Expand Up @@ -50,13 +53,14 @@ export const wrapperClass = style([
alignItems: 'flex-start',
width: '100%',
paddingTop: '$20',
paddingRight: '$12',

paddingBottom: '$20',
paddingLeft: '$4',

marginX: 'auto',
marginBottom: '$16',
}),
{
paddingInline: 0,
maxWidth: $$pageWidth,
backgroundColor: $$backgroundOverlayColor,
},
Expand Down
1 change: 1 addition & 0 deletions packages/apps/docs/src/components/Layout/basestyles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { createVar, globalStyle, style } from '@vanilla-extract/css';

globalStyle('html, body', {
margin: 0,
backgroundColor: vars.colors.$background,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const Header: FC<IProps> = ({ menuItems, layout = 'full' }) => {
</a>
<div className={innerWrapperClass}>
<div className={logoClass}>
<Link href="/" passHref>
<Link href="/" passHref aria-label="Go to the home page">
<DocsLogo overwriteTheme="dark" />
</Link>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const SearchButton: FC = () => {
<button
className={classNames(searchButtonClass, headerButtonClass)}
onClick={handleOpenSearch}
aria-label="Open the search modal"
>
<SystemIcon.Magnify />
<span className={searchButtonSlashClass}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@ export const MenuBack: FC<IProps> = ({ isOpen = false, onClick }) => {
menuBackOpenVariants[isOpen ? 'isOpen' : 'isClosed'],
);

return <button type="button" className={classes} onClick={onClick} />;
return (
<button
type="button"
className={classes}
onClick={onClick}
aria-label="Close the slide menu"
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const TitleHeader: FC<IProps> = ({ title, subTitle, avatar }) => {
</Stack>
{subTitle !== undefined && (
<span className={subheaderClass}>
<Heading as="h6" bold={false}>
<Heading as="h2" variant="h6" bold={false}>
{subTitle}
</Heading>
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { breakpoints, sprinkles } from '@kadena/react-ui/theme';
import { breakpoints, sprinkles, vars } from '@kadena/react-ui/theme';

import type { LayoutType } from '@/types/Layout';
import { style, styleVariants } from '@vanilla-extract/css';
Expand All @@ -7,9 +7,16 @@ export const articleClass = style([
sprinkles({
width: '100%',
paddingY: 0,
paddingX: '$10',
paddingX: '$4',
backgroundColor: 'transparent',
}),
{
'@media': {
[`screen and ${breakpoints.md}`]: {
paddingInline: vars.sizes.$10,
},
},
},
]);

export const contentClass = style([
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/docs/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const MyApp = ({
Component: FC<IPageProps>;
}): JSX.Element => {
const props = deserializePageProps(pageProps);

const Layout = getLayout(props.frontmatter.layout);

// check for a router query
Expand All @@ -60,6 +59,7 @@ export const MyApp = ({
<title>{props.frontmatter.title}</title>
<meta name="title" content={props.frontmatter.title} />
<meta name="description" content={props.frontmatter.description} />
<meta name="viewport" content="width=device-width, initial-scale=1" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍🏽

</Head>
<MDXProvider components={markDownComponents}>
<ThemeProvider
Expand Down
9 changes: 7 additions & 2 deletions packages/apps/docs/src/scripts/getdocstree.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { frontmatterFromMarkdown } from 'mdast-util-frontmatter';
import { exec } from 'child_process';
import { promisify } from 'util';
import logUpdate from 'log-update';
import { isValid } from 'date-fns';

const promiseExec = promisify(exec);
const errors = [];
Expand Down Expand Up @@ -43,11 +44,15 @@ const isMarkDownFile = (name) => {
return extension.toLowerCase() === 'md' || extension.toLowerCase() === 'mdx';
};

const getLastModifiedDate = async (root) => {
export const getLastModifiedDate = async (root) => {
const { stdout } = await promiseExec(
`git log -1 --pretty="format:%ci" ${root}`,
);
return stdout;

const date = new Date(stdout);
if (!isValid(date)) return;

return date.toUTCString();
};

const isIndex = (file) => {
Expand Down
11 changes: 1 addition & 10 deletions packages/apps/docs/src/scripts/importReadme.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { toMarkdown } from 'mdast-util-to-markdown';
import { toString } from 'mdast-util-to-string';
import { importReadMes } from './utils.mjs';
import chalk from 'chalk';
import { exec } from 'child_process';
import { promisify } from 'util';
import { getLastModifiedDate } from './getdocstree.mjs';

const promiseExec = promisify(exec);
const errors = [];

const DOCSROOT = './src/pages/docs/';
Expand Down Expand Up @@ -216,13 +214,6 @@ const relinkReferences = (md, pages, root) => {
relinkImageReferences(imageReferences, definitions, pages, root);
};

const getLastModifiedDate = async (root) => {
const { stdout } = await promiseExec(
`git log -1 --pretty="format:%ci" ${root}`,
);
return stdout;
};

const importDocs = async (filename, destination, parentTitle, options) => {
const doc = fs.readFileSync(`./../../${filename}`, 'utf-8');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getData } from './getData.mjs';
import path from 'path';

const omit = (obj, ...keysToOmit) =>
const omit = (obj, keysToOmit) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes sure we need a lot less data in the getstaticprops.
making the website much faster

Object.keys(obj)
.filter((key) => !keysToOmit.includes(key))
.reduce((acc, key) => ({ ...acc, [key]: obj[key] }), {});
Expand Down Expand Up @@ -46,6 +46,8 @@ const mapSubTree = (pathname, noChildren, isRoot) => (item) => {
'lastModifiedDate',
'publishDate',
'author',
'wordCount',
'readingTimeInMinutes',
]);

if (IsMenuOpen(pathname, newItem.root)) {
Expand Down
1 change: 1 addition & 0 deletions packages/apps/immutable-records/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"@kadena/react-ui": "workspace:*",
"@vanilla-extract/css": "1.12.0",
"mini-css-extract-plugin": "2.7.6",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reason this was not in this app. and it kills the build

"next": "13.4.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
Loading