You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

github-pages.md 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. +++
  2. title = "GitHub Pages"
  3. weight = 30
  4. +++
  5. By default, GitHub Pages uses Jekyll (a ruby based static site generator),
  6. but you can also publish any generated files provided you have an `index.html` file in the root of a branch called
  7. `gh-pages` or `master`. In addition you can publish from a `docs` directory in your repository. That branch name can
  8. also be manually changed in the settings of a repository. **However**, this only applies to publishing in a custom domain,
  9. i.e., if you want to publish to a GitHub-provided web service under the `github.io` domain, you can **only** use the
  10. `master` branch of your repository, as explained
  11. [here](https://help.github.com/en/articles/configuring-a-publishing-source-for-github-pages),
  12. so we will focus on the method that will work regardless of the domain.
  13. We can use any continuous integration (CI) server to build and deploy our site. For example:
  14. * [Github Actions](https://github.com/shalzz/zola-deploy-action)
  15. * [Travis CI](#travis-ci)
  16. ## Travis CI
  17. We are going to use [Travis CI](https://travis-ci.org) to automatically publish the site. If you are not using Travis
  18. already, you will need to login with the GitHub OAuth and activate Travis for the repository.
  19. Don't forget to also check if your repository allows GitHub Pages in its settings.
  20. ## Ensure that Travis can access your theme
  21. Depending on how you added your theme, Travis may not know how to access
  22. it. The best way to ensure that it will have full access to the theme is to use git
  23. submodules. When doing this, ensure that you are using the `https` version of the URL.
  24. ```shell
  25. $ git submodule add {THEME_URL} themes/{THEME_NAME}
  26. ```
  27. ## Allowing Travis to push to GitHub
  28. Before pushing anything, Travis needs a Github private access key to make changes to your repository.
  29. If you're already logged in to your account, just click [here](https://github.com/settings/tokens) to go to
  30. your tokens page.
  31. Otherwise, navigate to `Settings > Developer Settings > Personal Access Tokens`.
  32. Generate a new token and give it any description you'd like.
  33. Under the "Select Scopes" section, give it repo permissions. Click "Generate token" to finish up.
  34. Your token will now be visible.
  35. Copy it into your clipboard and head back to Travis.
  36. Once on Travis, click on your project, and navigate to "Settings". Scroll down to "Environment Variables" and input a name of `GH_TOKEN` with a value of your access token.
  37. Make sure that "Display value in build log" is off, and then click add. Now Travis has access to your repository.
  38. ## Setting up Travis
  39. We're almost done. We just need some scripts in a .travis.yml file to tell Travis what to do.
  40. **NOTE**: The script below assumes that we're taking the code from the `code` branch and will generate the HTML to be published in the `master` branch of the same repository. You're free to use any other branch for the Markdown files but if you want to use `<username>.github.io` or `<org>.github.io`, the destination branch **MUST** be `master`.
  41. ```yaml
  42. language: minimal
  43. before_script:
  44. # Download and unzip the zola executable
  45. # Replace the version numbers in the URL by the version you want to use
  46. - curl -s -L https://github.com/getzola/zola/releases/download/v0.9.0/zola-v0.9.0-x86_64-unknown-linux-gnu.tar.gz | sudo tar xvzf - -C /usr/local/bin
  47. script:
  48. - zola build
  49. # If you are using a different folder than `public` for the output directory, you will
  50. # need to change the `zola` command and the `ghp-import` path
  51. after_success: |
  52. [ $TRAVIS_BRANCH = code ] &&
  53. [ $TRAVIS_PULL_REQUEST = false ] &&
  54. zola build &&
  55. sudo pip install ghp-import &&
  56. ghp-import -n public -b master &&
  57. git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git master
  58. ```
  59. If your site is using a custom domain, you will need to mention it in the `ghp-import` command:
  60. `ghp-import -c vaporsoft.net -n public` for example.
  61. Credits: this page is based on the article https://vaporsoft.net/publishing-gutenberg-to-github/