<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: samzh72</title>
    <description>The latest articles on DEV Community by samzh72 (@samzh72).</description>
    <link>https://dev.to/samzh72</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F349073%2Fea115ed7-3720-40b9-b3f5-e2217f989c30.png</url>
      <title>DEV Community: samzh72</title>
      <link>https://dev.to/samzh72</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/samzh72"/>
    <language>en</language>
    <item>
      <title>Step By Step Instruction For Github Pages</title>
      <dc:creator>samzh72</dc:creator>
      <pubDate>Wed, 29 Apr 2020 14:55:55 +0000</pubDate>
      <link>https://dev.to/samzh72/step-by-step-instruction-for-github-pages-57h4</link>
      <guid>https://dev.to/samzh72/step-by-step-instruction-for-github-pages-57h4</guid>
      <description>&lt;p&gt;Github pages is a fantastic web hosting product for developers. The help document is just OK if you are going to setup a user(or organization)site. But if you want to setup a project site with it, the help document is not as good as the product itself. That's why I decide to write down the whole process of my setup. &lt;/p&gt;

&lt;p&gt;This could be the &lt;em&gt;ONLY&lt;/em&gt; issue free instruction you could find for project site setup.&lt;/p&gt;

&lt;h1&gt;
  
  
  Concept Of Sites
&lt;/h1&gt;

&lt;p&gt;Github pages could be setup into two types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;user/organization site&lt;/li&gt;
&lt;li&gt;project site&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It depends on what content would be shown in the pages. If it's a show window of the user or organization brand, it is the first type. If it's a support site of a specific project, it is the second type.&lt;/p&gt;

&lt;p&gt;Whatever the type you select, you need a place(a repo) to contain the sources of the site(HTML, CSS, JavaScript, images ... not the source of your project).&lt;/p&gt;

&lt;p&gt;For the first type, you will need a new repo on github with the repo name like: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/yourname/yourname.github.io"&gt;https://github.com/yourname/yourname.github.io&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After setup, you will get a site:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://yourname.github.io/"&gt;https://yourname.github.io/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the second type, the project repo will be used for site sources, but you won't like to mix them with project sources together. So an isolated directory or branch should be created just for site sources.&lt;/p&gt;

&lt;p&gt;After setup the second type site, you will get:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://yourname.github.io/yourproject"&gt;https://yourname.github.io/yourproject&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any access outside this path, like &lt;a href="https://yourname.github.io/"&gt;https://yourname.github.io/&lt;/a&gt; will get a 404.&lt;/p&gt;

&lt;p&gt;As I said above, the instruction from Github help of user/organization site is just OK. We will focus on the second type in this article.&lt;/p&gt;

&lt;h1&gt;
  
  
  Ruby &amp;amp; Jekyll
&lt;/h1&gt;

&lt;p&gt;Github Pages is a static content hosting service. It works well with a bunch of static page generators like Jekyll, Hugo ... etc.&lt;/p&gt;

&lt;p&gt;Jekyll is the recommended solution by Github Pages team, we will have Jekyll in this instruction as well.&lt;/p&gt;

&lt;p&gt;Jekyll is written in Ruby which I don't know much about it. You could skip this part if you are Ruby developer. This part is for developers like me who don't know Ruby at all.&lt;/p&gt;

&lt;p&gt;It's very important to follow the steps below because Github Pages documents don't have any instructions of installing Ruby. If you refer to Ruby or Jekyll documents, you will have latest version installed but not match with Github Pages, which cause endless issues later.&lt;/p&gt;

&lt;p&gt;Install rbenv which is used to manage Ruby runtime versions, like nvm for Node.js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install rbenv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you are running OS rather than macOS, install rbenv from your favorite package manager(apt or rpm whatever depends on your OS).&lt;/p&gt;

&lt;p&gt;Then add the following line into your .zshrc:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eval "$(rbenv init -)"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It will help setup your Ruby environment variables. After relaunch your terminal, now we could install Ruby now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rbenv install 2.7.1
rbenv global 2.7.1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Install Jekyll:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem install bundler
gem install jekyll -v 3.8.5
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To specify the version is very important, you need a local Jekyll has the exact same version as Github Pages. The version may change, check &lt;a href="https://pages.github.com/versions/"&gt;Github Pages Help&lt;/a&gt; for update.&lt;/p&gt;

&lt;h1&gt;
  
  
  Setup Local Repo
&lt;/h1&gt;

&lt;p&gt;The local repo is used for your project site sources(HTML, CSS, JavaScripts, markdowns, etc). We will create a branch of your project for it in this instruction.&lt;/p&gt;

&lt;p&gt;We will create an orphan branch from an empty directory to make sure the site sources are isolated from project sources and no dependencies with each other.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init yourproject
cd yourproject
git checkout --orphan gh-pages
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;'yourproject' is the repo name of which you want to setup site for.&lt;/p&gt;

&lt;h1&gt;
  
  
  Populate site with Jekyll
&lt;/h1&gt;

&lt;p&gt;We are working on 'gh-pages' branch of 'yourproject'. Jekyll is introduced now to populate a template website. We will focus on how Jekyll works, instead of how to add new content to the template site in this step.&lt;/p&gt;

&lt;p&gt;run Jekyll:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;jekyll _3.8.5_ new .
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Github Pages help document tells me put VERSION after 'jekyll' in the command, but I don't know add the underscores around the VERSION because I'm not Ruby developer. It took me a lot time to figure out the problem.&lt;/p&gt;

&lt;p&gt;Also the help document said you could run 'bundle exec ...', but actually you will get 'No Gemfile found' error if you do that. Just run jekyll directly because it's already in your PATH set by rbenv.&lt;/p&gt;

&lt;p&gt;There would be some files and directories generated after above command executed.&lt;/p&gt;

&lt;p&gt;Add the following line to Gemfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem "github-pages", "~&amp;gt; 204", group: :jekyll_plugins
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;204 is the version specified by Github Page dependencies. Check the exact version you need from the help document.&lt;/p&gt;

&lt;p&gt;Change 'baseurl' in _config.yml:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;baseurl: "/yourproject"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This step is crucial for project sites, baseurl must be specified correctly otherwise you would loss all the CSS file accesses.&lt;/p&gt;

&lt;p&gt;Now, try to get all dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rm Gemfile.lock
bundle
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Remember to delete Gemfile.lock first, so that you could get the right dependencies(As we manually added github-pages? maybe).&lt;/p&gt;

&lt;h1&gt;
  
  
  Test Locally
&lt;/h1&gt;

&lt;p&gt;You must always want to know what the site looks like before publish it to internet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bundle exec jekyll serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you run 'jekyll serve' without bundle, an i18n dependency error will be reported. I don't know why this happen(it seems some magic in Ruby dependencies) and don't want to make it work as all the above steps drive me crazy already.&lt;/p&gt;

&lt;p&gt;Open the following URL in your browser:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://127.0.0.1:4000/yourproject/"&gt;http://127.0.0.1:4000/yourproject/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will see:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H00iZxTA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/imr1t5r4ey3xybds4jj5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H00iZxTA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/imr1t5r4ey3xybds4jj5.png" alt="Jekyll Demo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Commit To Github
&lt;/h1&gt;

&lt;p&gt;You are working on gh-pages branch locally by now. &lt;/p&gt;

&lt;p&gt;.gitignore file was created already by Jekyll, just add all and commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add --all
git commit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Github Pages help document does not mention this step and I also forget it for my first try.&lt;/p&gt;

&lt;p&gt;Now push the branch to Github:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add origin https://github.com/yourname/yourproject.git
git push -u origin gh-pages
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once after your gh-pages branched pushed to Github, your site could be accessed in few minutes via URL:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://yourname.github.io/yourproject"&gt;https://yourname.github.io/yourproject&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will see exactly what you see as in your local testing.&lt;/p&gt;

&lt;h1&gt;
  
  
  Additional Bonus(subdomain from js.org)
&lt;/h1&gt;

&lt;p&gt;If it's a JavaScript project, I strongly suggest you apply a subdomain from js.org for your project. So that you could access your project via:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://yourproject.js.org"&gt;https://yourproject.js.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is shorter and looks much attractive than yourname.github.io/yourproject.&lt;/p&gt;

&lt;p&gt;Subdomain of js.org is free for apply. Just follow the simple 4 steps shown on &lt;a href="https://js.org"&gt;js.org&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;make sure you have meaningful content in your site already&lt;/li&gt;
&lt;li&gt;pickup a subdomain you like&lt;/li&gt;
&lt;li&gt;add CNAME file in your repo&lt;/li&gt;
&lt;li&gt;pull request to add your subdomain to "cnames_active.js"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The new domain name would take up to 24 hours to go live. There would come out another issue after that.&lt;/p&gt;

&lt;p&gt;Remember that we set baseurl to "/yourproject" in _config.yml? Set it back to "" because we don't have a baseurl now.&lt;/p&gt;

&lt;p&gt;A live example could be found:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/samzh72/httpunit"&gt;github repo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://httpunit.js.org"&gt;httpunit on js.org&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Recap
&lt;/h1&gt;

&lt;p&gt;If you are trying to setup Github Pages for your project instead of for you personally, DO NOT follow the steps on Github Pages help document. Follow this instruction would save at least 5 hours for Non-Ruby developers.&lt;/p&gt;

&lt;p&gt;Good luck!&lt;/p&gt;

</description>
      <category>github</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
