Skip to content

Commit 0b1acca

Browse files
committed
Website
0 parents  commit 0b1acca

Some content is hidden

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

57 files changed

+9156
-0
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.swp
2+
*~
3+
.DS_Store
4+
.nvmrc
5+
node_modules
6+
npm-debug.log
7+
8+
/build/

.travis.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
env:
2+
global:
3+
- secure: "TV6QfgfVBJQxjz6kUhuPiY5EPxhWJprsLzs9qVmXDQLkFYj1WGChVJHmtIauF4rzDOlYElichAeHK6npXMQ1HiEJ8huLaaCYfG8GSi8RRYBYJxvlmvpYXhwbk0h/sGZQSUcRZkm1czI/HowoIQd2UrMGXd0uDTla5zd7u6gONmWd30NRNiJTFAhKDyBSccbn2HYO3vsVvKjNFu7znvqvDt8dj3lbN4GaVfK5iY9JtNr29E6z/bNvza44lkcl3oe5LAf2qJ0wMuYilGf9k6LzSRXG0HxOJhnB1FxwPrG0wwZdgEiyA/gi0K+IiOsCFj8CzPqDVCVyBA+mi6tf4sR60Fc0mjcGG3JTs36KvsJ3fUVJNe2CvpRad387JQKCPPuV1bUFlx18tO9YIZCjNsxPXKSHPKeNNfG5B9L44tKiQU/sYX5hAZAprocElXzaVmXJ2PQfYd0I6960UNJB7mrlPCIW0ovKO3Cbf4XUZGO4hBYTBoiChM+qSY7Jk9auvFfo7rnqqq6CbgUO2lzhGT9KYxxooN90ZGZjAqzQQ1Sio4rOjn5tJT1h7guUBgRO+1vcjxLdwMu2OFJs13ZL9XN0OCfw60VPSBby6tHPit4ERo7QblvCeRqbig5gZbx9sUt09e4PFYvnXhHlYYk2kwbSuiNXes3n49+wixTHnCRDaV4="
4+
5+
language: node_js
6+
node_js: stable
7+
8+
after_success: ./resources/publish.sh

LICENSE

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
LICENSE AGREEMENT For graphql.org software
2+
3+
Facebook, Inc. (“Facebook”) owns all right, title and interest, including all
4+
intellectual property and other proprietary rights, in and to the graphql.org
5+
software. Subject to your compliance with these terms, you are hereby granted a
6+
non-exclusive, worldwide, royalty-free copyright license to (1) use and copy the
7+
graphql.org software; and (2) reproduce and distribute the graphql.org software
8+
as part of your own software (“Your Software”). Facebook reserves all rights not
9+
expressly granted to you in this license agreement.
10+
11+
THE SOFTWARE AND DOCUMENTATION, IF ANY, ARE PROVIDED "AS IS" AND ANY EXPRESS OR
12+
IMPLIED WARRANTIES (INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
13+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE) ARE DISCLAIMED. IN NO
14+
EVENT SHALL FACEBOOK OR ITS AFFILIATES, OFFICES, DIRECTORS OR EMPLOYEES BE
15+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
16+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
17+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
19+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
20+
THE USE OF THE SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21+
22+
You will include in Your Software (e.g., in the file(s), documentation or other
23+
materials accompanying your software): (1) the disclaimer set forth above; (2)
24+
this sentence; and (3) the following copyright notice:
25+
26+
Copyright (c) 2015, Facebook, Inc. All rights reserved.

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Contributing
2+
3+
Organization gh-pages deploy the `master` branch, so active development occurs
4+
on this `source` branch.
5+
6+
The site is written in JS and Markdown files in `site/`.
7+
8+
The site chrome are all in JS files in `site/_core/`.
9+
10+
### Making changes
11+
12+
The first time, get all the dependencies loaded via
13+
14+
```
15+
npm install
16+
```
17+
18+
Then, run the server via
19+
20+
```
21+
npm start
22+
Open http://localhost:8444/
23+
```
24+
25+
Anytime you change the contents, just refresh the page and it's going to be updated.
26+
27+
### Publish the Website
28+
29+
Once pushed to the `source` branch, Travis CI will publish http://github.org/

package.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"repository": "graphql/graphql.github.io",
3+
"private": true,
4+
"version": "0.0.0",
5+
"scripts": {
6+
"start": "rm -rf build && babel-node resources/server.js",
7+
"build": "rm -rf build && babel-node resources/build.js",
8+
"watch": "rm -rf build && babel-node resources/watch.js",
9+
"test": "exit 0"
10+
},
11+
"babel": {
12+
"optional": [
13+
"es7.asyncFunctions",
14+
"es7.objectRestSpread"
15+
]
16+
},
17+
"site": {
18+
"source": "./site",
19+
"build": "./build"
20+
},
21+
"devDependencies": {
22+
"babel": "^5.8.23",
23+
"babel-core": "^5.8.23",
24+
"babel-loader": "^5.3.2",
25+
"babel-runtime": "^5.8.20",
26+
"express": "^4.13.3",
27+
"js-yaml": "^3.4.0",
28+
"react": "^0.13.3",
29+
"sane": "^1.2.0",
30+
"webpack": "^1.12.1"
31+
},
32+
"dependencies": {
33+
"codemirror": "^5.6.0",
34+
"codemirror-graphql": "^0.1.1",
35+
"graphql": "^0.4.3",
36+
"marked": "^0.3.5"
37+
}
38+
}

resources/Site.js

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/**
2+
* Copyright (c) 2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
var fileWalker = require('./fileWalker');
10+
var fs = require('fs');
11+
var path = require('path');
12+
var writer = require('./writer');
13+
var yaml = require('js-yaml');
14+
import { endsWith } from './util';
15+
16+
exports.readSite = readSite;
17+
exports.buildSite = buildSite;
18+
19+
async function readSite(siteRoot) {
20+
var site = {
21+
root: path.resolve(siteRoot),
22+
files: []
23+
};
24+
25+
await fileWalker(site.root, (absPath, stat) => {
26+
var relPath = path.relative(site.root, absPath);
27+
return readFileData(absPath, relPath, stat).then(data => {
28+
data = normalizeData(data);
29+
var dirName = path.dirname(relPath);
30+
var dirs = dirName === '.' ? [] : dirName.split(path.sep);
31+
// TODO: throw if a dirname is only a number or is called "length"
32+
// TODO: there must be a better data structure that doesn't hack Array
33+
var files = site.files;
34+
files.push(data);
35+
for (var i = 0; i < dirs.length; i++) {
36+
files = files[dirs[i]] || (files[dirs[i]] = []);
37+
files.push(data);
38+
}
39+
});
40+
});
41+
42+
return site;
43+
}
44+
45+
function buildSite(buildRoot, site) {
46+
return Promise.all(site.files.map(file => {
47+
return writer(buildRoot, file, site);
48+
}));
49+
}
50+
51+
52+
53+
var PAGEISH = [ '.html.js', '.md', '.markdown' ];
54+
55+
function isPageish(filePath) {
56+
for (var i = 0; i < PAGEISH.length; i++) {
57+
if (endsWith(filePath, PAGEISH[i])) {
58+
return true;
59+
}
60+
}
61+
return false;
62+
}
63+
64+
var FRONT_MATTER_RX =
65+
/^(---\s*\n(?:(?:[^\n]*\n)(?!---|\.\.\.))*[^\n]*\n)(?:---|\.\.\.)?(?:\s*\n)*/;
66+
67+
// Given some file information produce a data structure that can be used.
68+
// If a file is page-like, front-matter will be looked for.
69+
function readFileData(absPath, relPath, stat) {
70+
if (stat.size > 100000 || !isPageish(relPath)) {
71+
return Promise.resolve({ absPath, relPath, stat });
72+
}
73+
return readFile(absPath).then(content => {
74+
var frontMatter = FRONT_MATTER_RX.exec(content);
75+
if (!frontMatter) {
76+
return { absPath, relPath, stat, content };
77+
}
78+
return {
79+
...yaml.load(frontMatter[1]),
80+
absPath,
81+
relPath,
82+
stat,
83+
content: content.slice(frontMatter[0].length)
84+
};
85+
});
86+
}
87+
88+
// Normalize the file data
89+
function normalizeData(file) {
90+
file.isPage = file.content && isPageish(file.relPath);
91+
file.url = urlToFile(file);
92+
file.date = file.date ?
93+
Date.parse(file.date) :
94+
(file.stat.birthtime || file.stat.ctime);
95+
return file;
96+
}
97+
98+
// The URL with a leading slash to a file.
99+
function urlToFile(file) {
100+
// Determine full url from permalink or the file path.
101+
var url;
102+
if (file.permalink) {
103+
url = file.permalink[0] === '/' ?
104+
file.permalink :
105+
'/' + path.join(path.dirname(file.relPath), file.permalink);
106+
// Ext-less permalinks should have trailing slashes
107+
if (!endsWith(url, '/') && path.extname(url) === '') {
108+
url += '/';
109+
}
110+
} else {
111+
url = '/' + file.relPath;
112+
for (var i = 0; i < PAGEISH.length; i++) {
113+
if (endsWith(url, PAGEISH[i])) {
114+
url = url.slice(0, -PAGEISH[i].length) + '.html';
115+
}
116+
}
117+
}
118+
119+
// Assume index.html stands for the parent directory
120+
if (path.basename(url) === 'index.html') {
121+
url = path.dirname(url);
122+
if (!endsWith(url, '/')) {
123+
url += '/';
124+
}
125+
}
126+
127+
return url;
128+
}
129+
130+
// Simple Promise wrapper around fs.readFile
131+
function readFile(filePath) {
132+
return new Promise((resolve, reject) => {
133+
fs.readFile(filePath, 'utf8', (err, content) => {
134+
if (err) {
135+
reject(err);
136+
} else {
137+
resolve(content);
138+
}
139+
});
140+
});
141+
}

resources/build.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright (c) 2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
var path = require('path');
10+
var Site = require('./Site');
11+
12+
module.exports = build;
13+
14+
process.on('unhandledRejection', error => {
15+
console.error('Unhandled Promise Rejection:');
16+
console.error(error && error.stack || error);
17+
});
18+
19+
var pwd = process.env.PWD;
20+
var sourceDir = process.env.npm_package_site_source || './';
21+
var buildDir = process.env.npm_package_site_build || './_build';
22+
23+
var SITE_ROOT = path.resolve(pwd, sourceDir);
24+
var BUILD_ROOT = path.resolve(pwd, buildDir);
25+
26+
async function build() {
27+
console.log('building...');
28+
var site = await Site.readSite(SITE_ROOT);
29+
await Site.buildSite(BUILD_ROOT, site);
30+
console.log('built');
31+
}
32+
33+
if (require.main === module) {
34+
build().catch(error => console.error(error.stack || error));
35+
}

resources/fileWalker.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright (c) 2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
var fs = require('fs');
10+
var path = require('path');
11+
12+
module.exports = fileWalker;
13+
14+
var IGNORE_RX =
15+
/^(?:_|\.|(?:node_modules|package\.json|README\.(?:md|markdown))$)/;
16+
17+
var INCLUDE_RX = /^(?:\.nojekyll|\.htaccess)/;
18+
19+
function fileWalker(dirPath, onVisitFile) {
20+
return new Promise((resolve, reject) => {
21+
fs.readdir(dirPath, (error, files) => {
22+
if (error) {
23+
return reject(error);
24+
}
25+
26+
var absFiles = files
27+
.filter(fileName => !IGNORE_RX.test(fileName) || INCLUDE_RX.test(fileName))
28+
.map(fileName => path.join(dirPath, fileName));
29+
30+
lstatAll(absFiles, (error, stats) => {
31+
if (error) {
32+
return reject(error);
33+
}
34+
var awaitWalkers = absFiles.reduce((promise, absFileName, index) => {
35+
return promise.then(() => {
36+
if (stats[index].isDirectory()) {
37+
return fileWalker(absFileName, onVisitFile);
38+
} else {
39+
return onVisitFile(absFileName, stats[index]);
40+
}
41+
});
42+
}, Promise.resolve());
43+
44+
awaitWalkers.then(() => resolve(), reject);
45+
});
46+
});
47+
});
48+
}
49+
50+
function lstatAll(files, cb) {
51+
var count = files.length;
52+
var stats = [];
53+
var success = true;
54+
files.forEach((fileName, index) => {
55+
if (success) {
56+
fs.lstat(fileName, (error, stat) => {
57+
if (success) {
58+
if (error) {
59+
success = false;
60+
return cb(error);
61+
}
62+
stats[index] = stat;
63+
if (--count === 0) {
64+
cb(null, stats);
65+
}
66+
}
67+
});
68+
}
69+
});
70+
}

resources/publish.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Build the website and copy it to the build folder
6+
npm run build
7+
8+
# Commit the website and push it
9+
cd build
10+
git init
11+
git config user.name "Travis CI"
12+
git add .
13+
git commit -a -m "Auto-deploy by Travis CI"
14+
git push --force --quiet "https://${GH_TOKEN}@github.com/graphql/graphql.github.io.git" master:master

0 commit comments

Comments
 (0)