Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new github docs folder hosting option #520

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function build(previousSizeMap) {
console.log('You can control this with the ' + chalk.green('homepage') + ' field in your ' + chalk.cyan('package.json') + '.');
console.log();
console.log('The ' + chalk.cyan('build') + ' folder is ready to be deployed.');
console.log('To publish it at ' + chalk.green(homepagePath) + ', run:');
console.log('To publish it at ' + chalk.green(homepagePath) + ' using the gh-pages branch, run:');
console.log();
console.log(' ' + chalk.cyan('git') + ' commit -am ' + chalk.yellow('"Save local changes"'));
console.log(' ' + chalk.cyan('git') + ' checkout -B gh-pages');
Expand All @@ -138,6 +138,16 @@ function build(previousSizeMap) {
console.log(' ' + chalk.cyan('git') + ' push -f origin gh-pages');
console.log(' ' + chalk.cyan('git') + ' checkout -');
console.log();
console.log('To publish it at ' + chalk.green(homepagePath) + ' using the docs/ folder, run:');
console.log();
console.log(' ' + chalk.cyan('git') + ' commit -am ' + chalk.yellow('"Save local changes"'));
console.log(' ' + chalk.cyan('rm') + ' -r docs/');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don’t we need -rf here?

console.log(' ' + chalk.cyan('mv') + ' build/ docs/');
console.log(' ' + chalk.cyan('git') + ' add -f docs');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need add -f here? Isn’t git add docs enough?

console.log(' ' + chalk.cyan('git') + ' commit -am ' + chalk.yellow('"Rebuild website"'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -a flag is probably not needed because we added the docs in the previous command?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine to keep for consistency so people don’t think it matters and stress over it.

console.log(' ' + chalk.cyan('git') + ' filter-branch -f --prune-empty --subdirectory-filter docs');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this command? I think it's only necessary for gh-pages because we needed to make a nested folder to be pushed as top-level.

console.log(' ' + chalk.cyan('git') + ' push -f origin master');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, it seems like no need for push -f, we can just say git push.

console.log();
} else if (publicPath !== '/') {
// "homepage": "http://mywebsite.com/project"
console.log('The project was built assuming it is hosted at ' + chalk.green(publicPath) + '.');
Expand Down
14 changes: 14 additions & 0 deletions template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,20 @@ git push -f origin gh-pages
git checkout -
```

To host your app using the `/docs` folder you just need to move the `build` folder to a new `docs` folder, check in the new `docs` folder and set the GitHub Pages Source to the `master branch /docs folder` setting. [Read More](https://help.github.com/articles/configuring-a-publishing-source-for-github-pages/#publishing-your-github-pages-site-from-a-docs-folder-on-your-master-branch) here about setting up the GitHub settings.

You can use the following sequence of commands to clear out the old docs folder, move the build to the docs folder, and then check it in to the master branch:

```sh
git commit -am "Save local changes"
rm -r docs/
mv build/ docs/
git add -f docs
git commit -am "Rebuild website"
git filter-branch -f --prune-empty --subdirectory-filter docs
git push -f origin master
```

You may copy and paste them, or put them into a custom shell script. You may also customize them for another hosting provider.

Note that GitHub Pages doesn't support routers that use the HTML5 `pushState` history API under the hood (for example, React Router using `browserHistory`). This is because when there is a fresh page load for a url like `http://user.github.io/todomvc/todos/42`, where `/todos/42` is a frontend route, the GitHub Pages server returns 404 because it knows nothing of `/todos/42`. If you want to add a router to a project hosted on GitHub Pages, here are a couple of solutions:
Expand Down