mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-25 23:05:23 +00:00
get data extraction working
This commit is contained in:
@@ -52,6 +52,7 @@ module.exports = {
|
||||
remarkPlugins,
|
||||
},
|
||||
},
|
||||
path.join(__dirname, './plugins/md-layout-preloader'),
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
const fm = require('gray-matter');
|
||||
const path = require('path');
|
||||
|
||||
const layouts = {
|
||||
apis: 'LayoutAPI',
|
||||
learn: 'LayoutLearn',
|
||||
};
|
||||
|
||||
module.exports = async function (src) {
|
||||
const callback = this.async();
|
||||
const code = `
|
||||
import * as AllComponents from 'components_new/AllComponents.server';
|
||||
global.COMPONENTS = AllComponents;
|
||||
${src}
|
||||
${src.replace('const layoutProps = {', 'const layoutProps = { data,')}
|
||||
`;
|
||||
return callback(null, code);
|
||||
};
|
||||
|
||||
11
beta/plugins/md-layout-preloader.js
Normal file
11
beta/plugins/md-layout-preloader.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const fm = require('gray-matter');
|
||||
|
||||
module.exports = async function (src) {
|
||||
const callback = this.async();
|
||||
const {content, data} = fm(src);
|
||||
const code = `
|
||||
export const data = ${JSON.stringify(data)};
|
||||
${content}
|
||||
`;
|
||||
return callback(null, code);
|
||||
};
|
||||
@@ -1,17 +1,28 @@
|
||||
import Link from './Link.client';
|
||||
import LayoutAPI from './LayoutAPI.server';
|
||||
import LayoutLearn from './LayoutLearn.server';
|
||||
|
||||
export const a = Link;
|
||||
|
||||
export function Hello() {
|
||||
return <h1>hi</h1>;
|
||||
}
|
||||
|
||||
export const wrapper = function Wrapper({children}) {
|
||||
export const wrapper = function Wrapper({router, data, children}) {
|
||||
if (!router) {
|
||||
throw Error('noooo');
|
||||
}
|
||||
|
||||
let Layout = LayoutLearn;
|
||||
if (router.pathname.startsWith('/apis/')) {
|
||||
Layout = LayoutAPI;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
border: '1px solid red',
|
||||
}}>
|
||||
<Layout>
|
||||
{JSON.stringify(data)}
|
||||
<hr />
|
||||
{children}
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
17
beta/src/components_new/LayoutAPI.server.tsx
Normal file
17
beta/src/components_new/LayoutAPI.server.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*/
|
||||
|
||||
import * as React from 'react';
|
||||
|
||||
// @ts-ignore
|
||||
export default function LayoutAPI({children}: {children: any}) {
|
||||
return (
|
||||
<>
|
||||
<h1>your in api</h1>
|
||||
<input placeholder="Search" />
|
||||
<hr />
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
}
|
||||
21
beta/src/components_new/LayoutLearn.server.tsx
Normal file
21
beta/src/components_new/LayoutLearn.server.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*/
|
||||
|
||||
import * as React from 'react';
|
||||
|
||||
if (typeof alert !== 'undefined') {
|
||||
alert('lalala');
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
export default function LayoutLearn({children}: {children: any}) {
|
||||
return (
|
||||
<>
|
||||
<h1>your in learn</h1>
|
||||
<input placeholder="Search" />
|
||||
<hr />
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
---
|
||||
title: useState
|
||||
---
|
||||
|
||||
## usestate page {/*usestate-page*/}
|
||||
|
||||
lalalal [go to props](/learn/props)
|
||||
|
||||
3
beta/src/pages/test.server.js
Normal file
3
beta/src/pages/test.server.js
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function Hi() {
|
||||
return <h1>hi</h1>;
|
||||
}
|
||||
Reference in New Issue
Block a user