Skip to content

Commit 4cf3aba

Browse files
committed
Got React working properly
1 parent d73f148 commit 4cf3aba

File tree

7 files changed

+154
-5
lines changed

7 files changed

+154
-5
lines changed

content/github/getting-started-with-github/access-permissions-on-github.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ A repository owned by a user account has two permission levels: the *repository
1717

1818
### Organization accounts
1919

20+
<BlueContent>
21+
22+
Hello world!
23+
24+
</BlueContent>
25+
2026
Organization members can have *owner*{% if currentVersion == "free-pro-team@latest" %}, *billing manager*,{% endif %} or *member* roles. Owners have complete administrative access to your organization{% if currentVersion == "free-pro-team@latest" %}, while billing managers can manage billing settings{% endif %}. Member is the default role for everyone else. You can manage access permissions for multiple members at a time with teams. For more information, see:
2127
- "[Permission levels for an organization](/articles/permission-levels-for-an-organization)"
2228
- "[Project board permissions for an organization](/articles/project-board-permissions-for-an-organization)"

lib/react/mdx-init.js renamed to lib/initialize-react-markdown-engine.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const React = require('react')
33
const { renderToStaticMarkup } = require('react-dom/server')
44
const mdx = require('@mdx-js/mdx')
55
const { MDXProvider, mdx: createElement } = require('@mdx-js/react')
6+
const BlueContent = require('../dist/react/BlueContent')
67

78
const transform = code =>
89
babel.transform(code, {
@@ -12,7 +13,7 @@ const transform = code =>
1213
]
1314
}).code
1415

15-
const renderWithReact = async mdxCode => {
16+
const renderReact = async mdxCode => {
1617
const jsx = await mdx(mdxCode, { skipExport: true })
1718
const code = transform(jsx)
1819
const scope = { mdx: createElement }
@@ -26,8 +27,8 @@ const renderWithReact = async mdxCode => {
2627

2728
const element = fn(React, ...Object.values(scope))
2829
const components = {
29-
h1: ({ children }) =>
30-
React.createElement('h1', { style: { color: 'tomato' } }, children)
30+
BlueContent: BlueContent,
31+
h3: undefined
3132
}
3233

3334
const elementWithProvider = React.createElement(
@@ -39,4 +40,4 @@ const renderWithReact = async mdxCode => {
3940
return renderToStaticMarkup(elementWithProvider)
4041
}
4142

42-
module.exports = renderWithReact
43+
module.exports = renderReact

lib/page.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ const pathUtils = require('./path-utils')
1515
const Permalink = require('./permalink')
1616
const languages = require('./languages')
1717
const renderContent = require('./render-content')
18+
const renderReact = require('./initialize-react-markdown-engine')
1819
const frontmatter = require('./frontmatter')
1920
const products = require('./all-products')
2021
const slash = require('slash')
2122

23+
2224
class Page {
2325
constructor (opts) {
2426
assert(opts.relativePath, 'relativePath is required')
@@ -123,7 +125,9 @@ class Page {
123125
? getMapTopicContent(this, context.pages, context.redirects)
124126
: this.markdown
125127

126-
const html = await renderContent(markdown, context)
128+
const markdownWithParsedReact = await renderReact(markdown)
129+
console.log(markdownWithParsedReact)
130+
const html = await renderContent(markdownWithParsedReact, context)
127131

128132
// product frontmatter may contain liquid
129133
if (this.product) {

package-lock.json

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"license": "(MIT AND CC-BY-4.0)",
1111
"dependencies": {
1212
"@babel/core": "^7.12.1",
13+
"@babel/plugin-transform-react-jsx": "^7.12.1",
1314
"@babel/plugin-transform-runtime": "^7.11.0",
1415
"@babel/preset-env": "^7.8.4",
1516
"@babel/runtime": "^7.11.2",
@@ -36,6 +37,7 @@
3637
"cross-env": "^7.0.2",
3738
"css-loader": "^4.0.0",
3839
"csurf": "^1.11.0",
40+
"directory-tree": "^2.2.5",
3941
"dotenv": "^8.2.0",
4042
"express": "^4.17.1",
4143
"express-rate-limit": "^5.1.3",

react/BlueContent.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const React = require('react')
2+
3+
const BlueContent = (props) => {
4+
return (
5+
<div style={{ color: 'blue' }}>
6+
{props.children}
7+
</div>
8+
)
9+
}
10+
11+
module.exports = BlueContent

server.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,36 @@ require('./lib/feature-flags')
55
const express = require('express')
66
const portUsed = require('port-used')
77
const warmServer = require('./lib/warm-server')
8+
const babel = require('@babel/core')
9+
const fs = require('fs')
10+
const path = require('path')
11+
const dirTree = require('directory-tree')
812
const port = Number(process.env.PORT) || 4000
913
const app = express()
1014

15+
16+
// Build React Components
17+
const transform = code =>
18+
babel.transform(code, {
19+
plugins: [
20+
'@babel/plugin-transform-react-jsx',
21+
'@babel/plugin-proposal-object-rest-spread'
22+
]
23+
}).code
24+
25+
const tree = dirTree('./react/')
26+
for (const index in tree.children) {
27+
const file = tree.children[index]
28+
if (file.type === 'file') {
29+
if (!fs.existsSync(path.join('dist', 'react'))) {
30+
fs.mkdirSync(path.join('dist', 'react'), { recursive: true })
31+
}
32+
const content = transform(fs.readFileSync(file.path, 'utf8'))
33+
fs.writeFileSync(path.join('dist', file.path), content)
34+
}
35+
}
36+
// End Build React Components
37+
1138
require('./middleware')(app)
1239

1340
// prevent the app from starting up durings tests

0 commit comments

Comments
 (0)