Skip to content

[docs] More docs infra changes #304

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

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
REPO_ROOT=https://github.com/mui/pigment-css
DEFAULT_BRANCH=master

3 changes: 0 additions & 3 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

# env files (can opt-in for commiting if needed)
.env*

# vercel
.vercel

Expand Down
10 changes: 10 additions & 0 deletions docs/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare global {
namespace NodeJS {
interface ProcessEnv {
NODE_ENV: string;
REPO_ROOT: string;
DATA_DIR: string;
DEFAULT_BRANCH: string;
}
}
}
31 changes: 26 additions & 5 deletions docs/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
import * as url from 'url';
import * as path from 'path';
import type { NextConfig } from 'next';
// @ts-ignore
// eslint-disable-next-line no-restricted-imports
import withDocsInfra from '@mui/monorepo/docs/nextConfigDocsInfra.js';
import { withPigment, extendTheme } from '@pigment-css/nextjs-plugin';
import path from 'path';

import { theme as baseTheme } from './src/theme';
import rootPackage from '../package.json';

const DATA_DIR = path.join(process.cwd(), 'data');
const currentDirectory = url.fileURLToPath(new URL('.', import.meta.url));
const DATA_DIR = path.join(currentDirectory, 'data');

const nextConfig: NextConfig = {
trailingSlash: false,
env: {
DATA_DIR,
CURRENT_VERSION: rootPackage.version,
Copy link
Member

Choose a reason for hiding this comment

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

Where is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be used in version dropdown (or span).

},
distDir: 'export',
output: process.env.NODE_ENV === 'production' ? 'export' : undefined,
eslint: {
ignoreDuringBuilds: true,
},
devIndicators: {
buildActivity: true,
buildActivityPosition: 'bottom-right',
appIsrStatus: false,
},
experimental: {
esmExternals: true,
workerThreads: false,
turbo: undefined,
},
};

const theme = extendTheme({
Expand All @@ -23,11 +41,14 @@ const theme = extendTheme({
},
});

export default withPigment(nextConfig, {
export default withPigment(withDocsInfra(nextConfig), {
theme,
displayName: true,
sourceMap: true,
sourceMap: process.env.NODE_ENV !== 'production',
babelOptions: {
plugins: ['@babel/plugin-proposal-explicit-resource-management'],
plugins: [
'@babel/plugin-proposal-explicit-resource-management',
'@babel/plugin-transform-unicode-property-regex',
],
},
});
6 changes: 5 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@
"@pigment-css/react": "workspace:*",
"@stefanprobst/rehype-extract-toc": "^2.2.0",
"clsx": "^2.1.1",
"next": "15.0.2",
"react": "18.3.1",
"react-dom": "18.3.1",
"next": "15.0.2",
"rehype-pretty-code": "0.14.0",
"rehype-slug": "^6.0.0",
"remark-frontmatter": "^5.0.0",
"remark-gfm": "^4.0.0",
"remark-mdx-frontmatter": "^5.0.0",
"shiki": "^1.22.2",
"to-vfile": "^8.0.0",
"vfile-matter": "^5.0.0"
},
"devDependencies": {
"@babel/plugin-proposal-explicit-resource-management": "^7.25.9",
"@babel/plugin-transform-unicode-property-regex": "^7.25.9",
"@mui/monorepo": "github:mui/material-ui#ae455647016fe5dee968b017aa191e176bc113dd",
"@pigment-css/nextjs-plugin": "workspace:*",
"@types/node": "^20",
"@types/react": "^18",
Expand Down
16 changes: 11 additions & 5 deletions docs/src/app/(content)/getting-started/[slug]/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import * as React from 'react';
import { MainContent } from '@/components/MainContent';
import { MainContent, MainContentContainer } from '@/components/MainContent';
import { Description } from '@/components/mdx/Description';

export default function NotFoundPage() {
return (
<MainContent as="main">
<h1>Not Found</h1>
<p>The page that you were looking for could not be found.</p>
</MainContent>
<MainContentContainer as="main">
<MainContent sx={{ textAlign: 'center' }}>
<h1>Page not found</h1>
<Description>
Apologies, but the page you were looking for wasn&apos;t found. Try reaching for the
search button on the nav bar above to look for another one.
</Description>
</MainContent>
</MainContentContainer>
);
}
42 changes: 27 additions & 15 deletions docs/src/app/(content)/getting-started/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as React from 'react';
import { notFound } from 'next/navigation';
import { getSlugs } from '@data/pages';
import { Metadata } from 'next';
import { getMarkdownPage, getMarkdownPageMetadata } from '@data/getMarkdownPage';
import routes, { getSlugs } from '@data/pages';
import { EditPageOnGithub } from '@/components/EditPageOnGithub';
import { SiblingPageLinks } from '@/components/SiblingPageLinks';
import { TableOfContents } from '@/components/TableOfContents';
import { Description } from '@/components/mdx/Description';
import { components } from '@/components/mdx/MDXComponents';
import { MainContent } from '@/components/MainContent';
import { MainContentContainer, MainContent } from '@/components/MainContent';

interface Props {
params: Promise<{ slug: string }>;
Expand All @@ -16,8 +17,9 @@ const SEGMENT = 'getting-started';

export default async function GettingStartedPage(props: Props) {
const { slug } = await props.params;
const { getMarkdownPage } = await import('@/utils/getMarkdownPage');
try {
const { MDXContent, metadata, tableOfContents } = await getMarkdownPage(SEGMENT, slug);
const { isMd, MDXContent, metadata, tableOfContents } = await getMarkdownPage(SEGMENT, slug);
const allComponents = {
...components,
Description: () => <Description className="description" text={metadata.description} />,
Expand All @@ -26,22 +28,31 @@ export default async function GettingStartedPage(props: Props) {

return (
<React.Fragment>
<MainContent as="main">
<MDXContent components={allComponents} />
{/* <div>
<div
<MainContentContainer as="main">
<MainContent>
<MDXContent components={allComponents} />
</MainContent>
<footer
sx={{
padding: 'var(--space-9) 0',
}}
>
<div>
<EditPageOnGithub category={SEGMENT} slug={slug} isMd={isMd} />
</div>
<hr
sx={{
padding: 'var(--space-9) 0',
margin: 'var(--space-4) 0',
borderWidth: '0 0 thin',
borderStyle: 'solid',
borderColor: 'var(--gray-outline-1)',
}}
>
<EditPageOnGithub category={SEGMENT} slug={slug} />
</div>
/>
<div>
<SiblingPageLinks currentSlug={`/${SEGMENT}/${slug}`} pages={routes} />
</div>
</div> */}
</MainContent>

</footer>
</MainContentContainer>
<TableOfContents toc={tableOfContents} />
</React.Fragment>
);
Expand All @@ -58,6 +69,7 @@ export function generateStaticParams() {
}

export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { getMarkdownPageMetadata } = await import('@/utils/getMarkdownPage');
const { slug } = await params;
const { title = 'Getting started', description } = await getMarkdownPageMetadata(SEGMENT, slug);

Expand Down
Binary file modified docs/src/app/favicon.ico
Binary file not shown.
30 changes: 24 additions & 6 deletions docs/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,27 @@ body {
text-decoration: none;
}
}
/*
@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;
}
} */

.shiki,
.shiki span,
[data-theme],
[data-theme] span {
color: var(--shiki-light) !important;
background-color: var(--shiki-light-bg) !important;
/* Optional, if you also want font styles */
font-style: var(--shiki-light-font-style) !important;
font-weight: var(--shiki-light-font-weight) !important;
text-decoration: var(--shiki-light-text-decoration) !important;
}

html.dark .shiki,
html.dark [data-theme],
html.dark .shiki span,
html.dark [data-theme] span {
color: var(--shiki-dark) !important;
background-color: var(--shiki-dark-bg) !important;
/* Optional, if you also want font styles */
font-style: var(--shiki-dark-font-style) !important;
font-weight: var(--shiki-dark-font-weight) !important;
text-decoration: var(--shiki-dark-text-decoration) !important;
}
1 change: 1 addition & 0 deletions docs/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const geistMono = localFont({
export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
generator: `Pigment Docs (Next.js)${process.env.COMMIT_REF ? ` ${process.env.COMMIT_REF}` : ''}`,
};

export default function RootLayout({
Expand Down
6 changes: 4 additions & 2 deletions docs/src/components/AppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export function AppBar() {
<IconLinkButton useNextLink href="/" label="Pigment CSS" size={3}>
<PigmentIcon />
</IconLinkButton>
<DocsVersionSelector currentVersion={currentVersion} versions={supportedVersions} />
{supportedVersions.length > 1 && (
Copy link
Member

Choose a reason for hiding this comment

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

Instead of hiding we can have a span to show the current version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will update in a followup.

<DocsVersionSelector currentVersion={currentVersion} versions={supportedVersions} />
)}
</div>
<div
sx={{
Expand All @@ -54,7 +56,7 @@ export function AppBar() {
}}
>
<IconLinkButton
href="https://github.com/mui/pigment-css"
href={process.env.REPO_ROOT}
target="_blank"
label="GitHub"
rel="noreferrer noopener"
Expand Down
29 changes: 14 additions & 15 deletions docs/src/components/EditPageOnGithub.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { styled } from '@pigment-css/react';
import { css } from '@pigment-css/react';
import * as React from 'react';
import Link from 'next/link';
import { GitHubIcon } from './icons/Github';

export interface EditPageOnGithubProps {
category: string;
slug: string;
isMd: boolean;
}

const REPO_ROOT = 'https://github.com/mui/pigment-css';
// #default-branch-switch
const DEFAULT_BRANCH = 'master';

const Link = styled.a(({ theme }) => ({
const linkClass = css(({ theme }) => ({
display: 'inline-flex',
alignItems: 'center',
gap: theme.vars.space[1],
cursor: 'pointer',
textDecoration: 'underline',
textDecorationLine: 'underline',
textDecorationStyle: 'solid',
textDecorationThickness: '1px',
textUnderlineOffset: 'calc(0.1em + 3px)',
textDecoration: 'none !important',
color: 'inherit',
position: 'relative',
zIndex: 0,
Expand All @@ -27,12 +25,13 @@ const Link = styled.a(({ theme }) => ({
}));

export function EditPageOnGithub(props: EditPageOnGithubProps) {
const { category, slug } = props;
const { category, slug, isMd } = props;

const url = `${REPO_ROOT}/edit/${DEFAULT_BRANCH}/docs/data/${category}/${slug}/${slug}.mdx`;
const url = `${process.env.REPO_ROOT}/edit/${process.env.DEFAULT_BRANCH}/docs/data/${category}/${slug}/${slug}.${isMd ? 'md' : 'mdx'}`;
return (
<Link href={url} target="_blank" rel="noopener nofollow">
Edit this page on GitHub
<Link href={url} className={linkClass} target="_blank" rel="noopener nofollow">
<GitHubIcon />
<span>Edit this page</span>
</Link>
);
}
28 changes: 21 additions & 7 deletions docs/src/components/MainContent.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { styled } from '@pigment-css/react';

export const MainContent = styled.div({
export const MainContentContainer = styled.div(({ theme }) => ({
boxSizing: 'content-box',
maxWidth: '714px',
paddingTop: 'var(--space-9)',
paddingLeft: 'var(--space-6)',
paddingRight: 'var(--space-6)',
maxWidth: 714,
paddingTop: theme.vars.space[9],
paddingLeft: theme.vars.space[6],
paddingRight: theme.vars.space[6],
marginLeft: 'auto',
marginRight: 'auto',
marginBottom: 'var(--space-9)',
marginBottom: theme.vars.space[9],
'@media (max-width: 1242px)': {
marginRight: 'calc((100vw - 240px - 762px) / 2)',
},
'@media (max-width: 1002px)': { marginLeft: 'auto', marginRight: 'auto' },
}));

export const MainContent = styled.div({
'p:not(.description)': {
margin: '0',
marginBottom: 'var(--space-4)',
Expand Down Expand Up @@ -71,6 +74,17 @@ export const MainContent = styled.div({
letterSpacing: '-0.012em',
},
code: { fontFamily: 'var(--ff-code)' },
'pre[data-language]': {
position: 'relative',
'&::after': {
position: 'absolute',
top: 5,
right: 10,
opacity: 0.5,
fontSize: '0.8rem',
content: 'attr(data-language)',
},
},
':not(pre) > code': {
marginLeft: '1px',
marginRight: '1px',
Expand Down Expand Up @@ -105,7 +119,7 @@ export const MainContent = styled.div({
whiteSpace: 'pre',
color: 'var(--gray-text-1)',
border: '1px solid var(--gray-outline-2)',
borderRadius: '12px',
borderRadius: 8,
},
kbd: {
padding: '6px',
Expand Down
Loading
Loading