Skip to content

Commit fc3c95d

Browse files
abiexpbot
authored andcommitted
add next.js-based docs
fbshipit-source-id: d77229e
1 parent 7ab5bb5 commit fc3c95d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+4123
-0
lines changed

.babelrc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"presets": [
3+
"next/babel"
4+
],
5+
"plugins": [
6+
[
7+
"transform-define",
8+
"./env-config.js"
9+
],
10+
"markdown-in-js/babel",
11+
"babel-plugin-root-import"
12+
]
13+
}

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Rockerfile

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.next
2+
3+
# These are generated by mdjs
4+
pages/versions
5+
static/images/generated
6+
navigation-data.json

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 650 Industries, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Expo Documentation
2+
3+
This is the public documentation for **Expo**, its SDK, client and services.
4+
5+
You can access this documentation online at https://docs.expo.io/. It's built using next.js on top of the https://github.com/zeit/docs codebase.
6+
7+
### Running Locally
8+
9+
Download the copy of this repostory.
10+
11+
~~~sh
12+
git clone https://github.com/expo/expo-docs.git
13+
~~~
14+
15+
Then `cd` into the downloaded directory and install dependencies with:
16+
17+
~~~sh
18+
yarn
19+
~~~
20+
21+
Then you can run the app with:
22+
23+
~~~sh
24+
yarn run dev
25+
~~~
26+
27+
This starts two processes: a `next.js` server, and a compiler/watcher that converts markdown files into javascript pages that `next.js` understands.
28+
29+
Now the documentation is running at http://localhost:3000
30+
31+
### Running in production mode
32+
33+
~~~sh
34+
yarn run build
35+
yarn run start
36+
~~~
37+
38+
### Editing Docs Content
39+
40+
[FUTURE]
41+
42+
You can find the source of the documentation inside the `versions` directory. Documentation is mostly written in markdown with the help of some React components (for Snack embeds, etc). The routes and navbar are automatically inferred from the directory structure within `versions`.
43+
44+
### Adding Images and Assets
45+
46+
You can add images and assets in the same directory as the markdown file, and you just need to reference them correctly.
47+
48+
### New Components
49+
50+
Always try to use the existing components and features in markdown. Create a new component or use a component from NPM, unless there is no other option.
51+
52+
### Quirks
53+
54+
* You can can't have curly brace without quotes: '{}' -> `{}`
55+
* Make sure to leave a empty newline between a table and following content
56+
57+
## Transition from current docs to next.js docs
58+
59+
### Compile process
60+
61+
#### FUTURE
62+
63+
In both `yarn run start` and `yarn run dev`, we initially compile (see `mdjs` dir) all `.md` files in `docs` to `.js` files under `pages/versions` (which is git-ignored, and never commited). At this point, we also generate the json file `navigation-data.json` for the navbar, and move images in `docs` to the `static` folder.
64+
65+
In `yarn run dev`, the watcher watches for changes to files in `docs`, and re-compiles as necessary. Note: navigation changes probably won't live-reload so make sure to restart the server.
66+
67+
#### PRESENT
68+
69+
On `yarn run start` and `yarn run dev`, we first fix all markdown files in `versions` (symlinked to `universe/docs/versions`) and copy them as new files under `docs` (which is git-ignored, and never commited). Then, we "compile" all markdown files in `docs` to javascript files under `pages/versions` (which is git-ignored, and never commited). At this point, we also generate the json file `navigation-data.json` for the navbar, and move images in `docs` to the `static` folder.
70+
71+
### Temporary scripts
72+
73+
At the moment, while we transition from the existing docs server to this next.js server, I have a `fix-markdown.js` that makes a couple of straightforward regex replacements, and moves markdown files in the workflow/distribution/expokit sections into seperate directories.
74+
75+
### Not breaking existing incoming links
76+
77+
`transition/sections.js` is used to figure out which URLs to alias. In order to not break existing URLs such as guides/configuration (the new URL is the more sensible workflow/configuration, automatically inferred from the fact that configuration.md is in the workflow subdir), in next.js, we support both so we need to keep a list of URLs to alias under guides. For future versions, the guides URL for `configuration` won't exist at all so we can slowly phase out this file.
78+
79+
## A note about versioning
80+
81+
Expo's SDK is versioned so that apps made on old SDKs are still supported
82+
when new SDKs are relased. The website documents previous SDK versions too.
83+
84+
Version names correspond to directory names under `docs`.
85+
86+
`unversioned` is a special version for the next SDK release.
87+
88+
Sometimes you want to make an edit in version `X` and have that edit also
89+
be applied in versions `Y, Z, ...` (say, when you're fixing documentation for an
90+
API call that existed in old versions too). You can use the
91+
`./scripts/versionpatch.sh` utility to apply your `git diff` in one version in
92+
other versions. For example, to update the docs in `unversioned` then apply it
93+
on `v8.0.0` and `v7.0.0`, you'd do the following after editing the docs in
94+
`unversioned` such that it shows up in `git diff`:
95+
96+
```./scripts/versionpatch.sh unversioned v8.0.0 v7.0.0```
97+
98+
Any changes in your `git diff` outside the `unversioned` directory are ignored
99+
so don't worry if you have code changes or such elsewhere.
100+
101+
### Updating latest version of docs
102+
103+
When we release a new SDK, we copy the `unversioned` directory, and rename it to the new version. Latest version of docs is read from `package.json` so make sure to update the `version` key there as well. However, if you update the `version` key there, you need to `rm -rf node_modules/.cache/` before the change is picked up (why? [read this](https://github.com/zeit/next.js/pull/1747/files)).
104+
105+
That's all you need to do. The `docs` directory is listed on server start to find all available versions. The routes and navbar contents are automatically inferred from the directory structure within `docs`. So, `/versions/v24.0.0/guides/development-mode` refers to `pages/versions/guides/development-mode`.
106+
107+
Because the navbar is automatically generated from the directory structure, the default ordering of the links under each section is alphabetical. However, for many sections, this is not ideal UX. So, if you wish to override the alphabetical ordering, manipulate page titles in `navbarOrder.js`.

Rockerfile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM gcr.io/exponentjs/node-base-builder:8.2.1-0
2+
3+
MOUNT ../:/root/universe
4+
5+
ENV TERM xterm-256color
6+
ENV PATH /root/universe/tools/bin/:$PATH
7+
8+
RUN apk add bash tini
9+
10+
ADD ./package.json /root/app/package.json
11+
ADD ./yarn.lock /root/app/yarn.lock
12+
13+
RUN cd /root/universe/docs && \
14+
echo "--- :yarn: Install dependencies" && \
15+
yarn && \
16+
yarn build && \
17+
echo "--- Copying...." && \
18+
mkdir -p /app/node_modules && \
19+
cp -R ./node_modules /app/node_modules && \
20+
echo "--- Cleaning up..." && \
21+
rm -rf `yarn cache dir` && \
22+
echo "--- Finishing build and pushing..."
23+
24+
ADD . /app
25+
WORKDIR /app
26+
27+
ENV NODE_ENV production
28+
29+
ENTRYPOINT ["/sbin/tini", "--"]
30+
CMD ["./node_modules/.bin/cross-env", "NODE_ENV=production", "node", "server.js"]
31+
32+
PUSH {{ .ImageName }}:{{ .ImageTag }}

components/base/button.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import * as Constants from '~/style/constants';
3+
4+
class Button extends React.Component {
5+
render() {
6+
return (
7+
<span
8+
onClick={this.props.onClick}
9+
style={{
10+
backgroundColor: Constants.colors.black,
11+
color: 'rgb(255, 255, 255)',
12+
height: '30px',
13+
paddingLeft: '12px',
14+
paddingRight: '12px',
15+
borderRadius: '4px',
16+
border: '1px solid transparent',
17+
fontSize: '16px',
18+
cursor: 'pointer',
19+
display: 'inline-flex',
20+
justifyContent: 'center',
21+
alignItems: 'center',
22+
}}>
23+
{this.props.value}
24+
</span>
25+
);
26+
}
27+
}
28+
29+
export default Button;

components/base/code.js

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import React from 'react';
2+
import Prism from 'prismjs';
3+
4+
import * as Constants from '~/style/constants';
5+
6+
/* global tippy */
7+
8+
export class Code extends React.Component {
9+
componentDidMount() {
10+
this._runTippy();
11+
}
12+
13+
componentDidUpdate() {
14+
this._runTippy();
15+
}
16+
17+
_runTippy() {
18+
if (process.browser) {
19+
tippy('.code-annotation', {
20+
theme: 'expo',
21+
placement: 'top',
22+
arrow: true,
23+
arrowType: 'round',
24+
interactive: true,
25+
distance: 20,
26+
});
27+
}
28+
}
29+
30+
_escapeHtml(text) {
31+
return text.replace(/"/g, '&quot;');
32+
}
33+
34+
_replaceCommentsWithAnnotations(value) {
35+
return value
36+
.replace(/<span class="token comment">\/\* @info (.*?)\*\/<\/span>\s*/g, (match, content) => {
37+
return `<span class="code-annotation" title="${this._escapeHtml(content)}">`;
38+
})
39+
.replace(/<span class="token comment">\/\* @end \*\/<\/span>(\n *)?/g, '</span>');
40+
}
41+
42+
render() {
43+
let code = this.props.children;
44+
let { lang } = this.props;
45+
let html = code.toString();
46+
if (lang && !Prism.languages[lang]) {
47+
try {
48+
require('prismjs/components/prism-' + lang + '.js');
49+
} catch (e) {}
50+
}
51+
if (lang && Prism.languages[lang]) {
52+
html = Prism.highlight(html, Prism.languages[lang]);
53+
html = this._replaceCommentsWithAnnotations(html);
54+
}
55+
56+
// Remove leading newline if it exists (because inside <pre> all whitespace is dislayed as is by the browser, and
57+
// sometimes, Prism adds a newline before the code)
58+
if (html.startsWith('\n')) {
59+
html = html.replace('\n', '');
60+
}
61+
62+
return (
63+
<pre
64+
style={{
65+
border: '1px solid #eaeaea',
66+
padding: '20px',
67+
margin: '10px 0',
68+
whiteSpace: 'pre',
69+
overflow: 'auto',
70+
width: '800px',
71+
WebkitOverflowScrolling: 'touch',
72+
backgroundColor: 'rgba(0, 1, 31, 0.03)',
73+
lineHeight: '1.2rem',
74+
}}>
75+
<code dangerouslySetInnerHTML={{ __html: html }} />
76+
<style jsx>
77+
{`
78+
code {
79+
color: ${Constants.colors.black80};
80+
font-family: ${Constants.fontFamilies.mono};
81+
font-size: 13px;
82+
line-height: 20px;
83+
white-space: inherit;
84+
}
85+
`}
86+
</style>
87+
<style jsx global>
88+
{`
89+
/* Code annotation styles */
90+
.code-annotation {
91+
font-weight: 600;
92+
}
93+
94+
.code-annotation:hover {
95+
cursor: pointer;
96+
opacity: 0.6;
97+
animation: none;
98+
}
99+
100+
.tippy-tooltip.expo-theme {
101+
background-color: white;
102+
color: black;
103+
text-align: left;
104+
}
105+
106+
.tippy-popper[x-placement^='top'] .tippy-tooltip.expo-theme .tippy-roundarrow {
107+
fill: white;
108+
}
109+
110+
.tippy-tooltip.expo-theme .tippy-content {
111+
padding: 10px 5px;
112+
line-height: 1.5em;
113+
font-family: ${Constants.fonts.book};
114+
}
115+
`}
116+
</style>
117+
</pre>
118+
);
119+
}
120+
}
121+
122+
export const InlineCode = ({ children }) => (
123+
<code className="inline">
124+
{children}
125+
<style jsx global>
126+
{`
127+
code {
128+
color: ${Constants.colors.black80};
129+
font-family: ${Constants.fontFamilies.mono};
130+
font-size: 0.9rem;
131+
white-space: pre-wrap;
132+
display: inline;
133+
padding: 4px;
134+
margin: 2px;
135+
line-height: 20px;
136+
max-width: 100%;
137+
}
138+
139+
code.inline {
140+
word-wrap: break-word;
141+
background-color: ${Constants.colors.blackRussian};
142+
vertical-align: middle;
143+
overflow-x: scroll;
144+
}
145+
146+
code::before {
147+
content: '';
148+
/* content: '\`'; */
149+
}
150+
151+
code::after {
152+
/* content: '\`'; */
153+
content: '';
154+
}
155+
`}
156+
</style>
157+
</code>
158+
);

components/base/generate-slug.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const slugs = require(`github-slugger`)();
2+
slugs.reset();
3+
4+
const generateSlug = node => {
5+
return slugs.slug(toString(node));
6+
};
7+
8+
const toString = node => {
9+
if (typeof node === 'string') {
10+
return node;
11+
} else if (Array.isArray(node)) {
12+
return node.map(toString).join('');
13+
} else if (node.props.children) {
14+
return toString(node.props.children);
15+
} else {
16+
return '';
17+
}
18+
};
19+
20+
export default generateSlug;

0 commit comments

Comments
 (0)