Skip to content

Commit 91605d0

Browse files
committed
feat: Add MDX docs app with Nextra
1 parent 1956140 commit 91605d0

File tree

16 files changed

+17436
-9312
lines changed

16 files changed

+17436
-9312
lines changed

apps/docs/babel.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// babel.config.js
2+
module.exports = function (api) {
3+
api.cache(true);
4+
return {
5+
presets: ["babel-preset-expo"],
6+
};
7+
};

apps/docs/docs.theme.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
/* --- Styles ---------------------------------------------------------------------------------- */
3+
4+
const styles = {
5+
footer: {
6+
verticalAlign: 'middle',
7+
},
8+
tagLink: {
9+
padding: '3px 8px',
10+
backgroundColor: '#333333',
11+
borderRadius: '4px',
12+
},
13+
}
14+
15+
/* --- Theme ----------------------------------------------------------------------------------- */
16+
17+
/** @type {import('nextra-theme-docs').DocsThemeConfig} */
18+
export default {
19+
logo: <span><strong>FullProduct.dev</strong> ⚡️ Universal Base Starter</span>,
20+
project: {
21+
link: 'https://github.com/Aetherspace/universal-app-router',
22+
},
23+
footer: {
24+
text: <span>Need a <strong>Full-Product</strong> / Universal App Setup? 🚀 Check out <a href="https://codinsonn.dev" target="_blank" style={{ ...styles.tagLink, fontWeight: 'bold' }}>FullProduct.dev</a> by <a href="https://codinsonn.dev" target="_blank" style={styles.tagLink}>Thorr ⚡️ codinsonn</a></span>
25+
},
26+
navigation: true,
27+
sidebar: {
28+
autoCollapse: true,
29+
defaultMenuCollapseLevel: 2,
30+
toggleButton: true,
31+
},
32+
}

apps/docs/global.css

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* -i- Upgrade from the CSS reset that came with Expo's default Next.js setup */
2+
/* Follows the setup for react-native-web: */
3+
/* https://necolas.github.io/react-native-web/docs/setup/#root-element */
4+
/* Plus additional React Native scroll and text parity styles for various browsers. */
5+
/* Force Next-generated DOM elements to fill their parent's height */
6+
7+
html, body, #__next {
8+
width: 100%;
9+
/* To smooth any scrolling behavior */
10+
-webkit-overflow-scrolling: touch;
11+
margin: 0px;
12+
padding: 0px;
13+
/* Allows content to fill the viewport and go beyond the bottom */
14+
min-height: 100%;
15+
}
16+
17+
#__next {
18+
flex-shrink: 0;
19+
flex-basis: auto;
20+
flex-direction: column;
21+
flex-grow: 1;
22+
display: flex;
23+
flex: 1;
24+
}
25+
26+
html {
27+
scroll-behavior: smooth;
28+
/* Prevent text size change on orientation change https://gist.github.com/tfausak/2222823#file-ios-8-web-app-html-L138 */
29+
-webkit-text-size-adjust: 100%;
30+
height: 100%;
31+
}
32+
33+
body {
34+
display: flex;
35+
/* Allows you to scroll below the viewport; default value is visible */
36+
overflow-y: auto;
37+
overscroll-behavior-y: none;
38+
font-family: -apple-system, system, Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
39+
text-rendering: optimizeLegibility;
40+
-webkit-font-smoothing: antialiased;
41+
-moz-osx-font-smoothing: grayscale;
42+
-ms-overflow-style: scrollbar;
43+
}

apps/docs/next-env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

apps/docs/next.config.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const { withExpo } = require("@expo/next-adapter");
2+
const withNextra = require("nextra")({
3+
theme: "nextra-theme-docs",
4+
themeConfig: "./docs.theme.js",
5+
});
6+
7+
/** @type {import('next').NextConfig} */
8+
const nextConfig = withNextra(withExpo({
9+
reactStrictMode: true,
10+
swcMinify: true,
11+
transpilePackages: [
12+
"react-native",
13+
"react-native-web",
14+
"expo",
15+
"@bacons/mdx",
16+
"@bacons/react-views",
17+
"@expo/html-elements",
18+
// Add more React Native / Expo packages here...
19+
],
20+
pageExtensions: ["js", "jsx", "ts", "tsx", "md", "mdx"],
21+
experimental: {
22+
forceSwcTransforms: true,
23+
},
24+
images: {
25+
remotePatterns: [
26+
{
27+
protocol: "https",
28+
hostname: "codinsonn.dev",
29+
}
30+
]
31+
}
32+
}));
33+
34+
module.exports = nextConfig;

apps/docs/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "@app/docs",
3+
"version": "1.0.0",
4+
"private": true,
5+
"dependencies": {
6+
"@mdx-js/loader": "^3.0.1",
7+
"@mdx-js/react": "^3.0.1",
8+
"@next/mdx": "^14.1.4",
9+
"@types/mdx": "^2.0.12",
10+
"next": "~14.0.4",
11+
"nextra": "^2.13.4",
12+
"nextra-theme-docs": "^2.13.4"
13+
},
14+
"scripts": {
15+
"dev": "next dev -p 4000",
16+
"build": "next build",
17+
"start": "next start -p 4000",
18+
"env:local": "cp .env.example .env.local"
19+
}
20+
}

apps/docs/pages/_app.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import UniversalAppProviders from '@app/core/screens/UniversalAppProviders'
2+
3+
export default function App({ Component, pageProps }) {
4+
return (
5+
<UniversalAppProviders>
6+
<Component {...pageProps} />
7+
</UniversalAppProviders>
8+
)
9+
}

apps/docs/pages/_meta.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"index": "Introduction",
3+
"plugins": "Plugin Branches"
4+
}

apps/docs/pages/index.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { default as ReadMe } from '@app/core/mdx/readme.mdx'
2+
3+
<div className="nx-h-4" />
4+
5+
<ReadMe />
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { RemoteContent } from 'nextra/data'
2+
import { buildDynamicMDX, buildDynamicMeta } from 'nextra/remote'
3+
import { pluginsConfig } from '../../remote/pluginsConfig'
4+
5+
export async function getStaticProps({ params }) {
6+
7+
const pluginBranch = params.pluginBranchSlug?.join('/') || null
8+
const branchNamePath = pluginsConfig.branches.find(filePath => filePath.replace(/\.mdx?/, '') === pluginBranch)
9+
const branchName = branchNamePath?.replace(/\.mdx?/, '')?.replace?.('plugins/', '')
10+
let pageMarkdown = '# 404 | Plugin Not Found\n\nThe page may not exist, or a remote MDX rate limit may have triggered'
11+
try {
12+
if (branchName) {
13+
const githubApiBranchPRsUrl = `https://api.github.com/repos/Aetherspace/universal-app-router/pulls?head=Aetherspace:with/${branchName}`
14+
const response = await fetch(githubApiBranchPRsUrl)
15+
const branchPRs = await response.json()
16+
const branchPR = branchPRs[0]
17+
const branchPRMarkdown = branchPR.body
18+
const branchPRTitle = branchPR.title
19+
pageMarkdown = branchPRMarkdown.split('\n').reduce((acc, line) => {
20+
let newLine = line
21+
if (line.includes('<img ') && line.includes('">')) newLine = newLine.replace('">', '" />')
22+
return acc + newLine + '\n'
23+
}, `# \`${branchPRTitle}\`\n\n`)
24+
}
25+
} catch (error) {
26+
if (!error) console.error(error)
27+
}
28+
const dynamicMDX = await buildDynamicMDX(pageMarkdown, { defaultShowCopyCode: true })
29+
const dynamicMeta = await buildDynamicMeta()
30+
return {
31+
props: {
32+
...dynamicMeta,
33+
...dynamicMDX,
34+
},
35+
revalidate: false,
36+
}
37+
}
38+
39+
export const getStaticPaths = () => ({
40+
fallback: 'blocking',
41+
paths: pluginsConfig.branches.map(filePath => ({
42+
params: { pluginBranchSlug: filePath.replace(/\.mdx?$/, '').split('/') }
43+
}))
44+
})
45+
46+
<RemoteContent />

0 commit comments

Comments
 (0)