Using Github pages with Jekyll in a subdirectory - github

I recently wanted to publish my Jekyll site on Github pages, but it seems that putting everything in a subdirectory is giving some issues, even after I change the source to the correct directory.
My structure looks like this:
- site
- src (contains all Jekyll stuff)
- README.md
- GruntFile.js
- ...
Locally my site builds perfectly and when I go to http://localhost:4040 I can see it just nicely, but when I commit this to my Github and visit username.github.io I get a 404, if I go to username.github.io/src I can see part of my site, however all {% include %} are ignored.
In my _config.yml I updated the source: source: ./src, but that doesn't seem to help.
Is there a way to make Github Pages handle subdirectories properly? Basically I want to tell it that my Jekyll site is inside /src, and I want the url to just be username.github.io instead of username.github.io/src
I know i can use the pages branch and commit to there, but I would prefer if it could happen automaticly.

If it helps anyone, I attempted to run Jekyll on GH Pages from a subdir (and modified source) and was banging my head against the wall over these errors:
A file was included in subdir/index.html that is a symlink or does not exist in your _includes directory. For more information, see https://help.github.com/articles/page-build-failed-file-is-a-symlink.
After much searching on this, the definitive answer was right there in the docs:
Configuration Overrides
We override the following _config.yml values, which you are unable to
configure:
safe: true
lsi: false
source: your top-level directory
Keep in mind that if you change the source setting, your pages may not
build correctly. GitHub Pages only considers source files in the
top-level directory of a repository.

I contact Github support and they gave me 2 solutions.
Move all my Jekyll source files to my top-lever directory.
Use a different branch and update it manually each time.

Related

I forked the repo for a Github Pages that I liked, but my fork will not load

I am a total programming noob and assume I'm missing something basic.
I forked this repo: https://github.com/colinmorris/tour-of-heroes
Here is the author's page for that repo: https://colinmorris.github.io/tour-of-heroes/
My fork: https://github.com/SmallFryHero/tour-of-heroes
My page based on that fork: https://smallfryhero.github.io/tour-of-heroes/
My page does not load.
I deployed the Github Pages using the gh-pages branch and from the /root folder.
I imported the code into a different web editor, CodeSandBox, and I can get it to run there along with my changes.
What do I need to fix to get it to run on my Github Pages? I added a readme to get the page to build. It seems to be deployed, but doesn't get past the "loading..." step.
Thanks for any help! Sorry for the total noob question.
The issue is that GitHub Pages, by default, use a static site generator called Jekyll under the hood. It basically converts a set of Markdown files into HTML (and provides templating, themes, plugins, and more).
In the case of your repo, which consists exclusively of static assets, Jekyll doesn't do much, but it does exclude the node_modules directory (see logs), which leads to the scripts in there being unavailable to the deployed page.
To fix this, you can indicate that you wish to skip any Jekyll processing and just upload the files as they are; to do so, add an empty file .nojekyll to the root directory in the gh-pages branch, as described in the documentation.
The repo from which you forked was last deployed multiple years ago, and I suspect the Jekyll default configuration back then didn't exclude node_modules yet.

Unable to host project to GitHub Pages

My repo: https://github.com/shoegazzz/simple-trello-clone
When following a link https://shoegazzz.github.io/simple-trello-clone/ :
404 File not found The site configured at this address does not contain the requested file. If this is your site, make sure that the filename case matches the URL. For root URLs (like http://example.com/) you must provide an index.html file. Read the full documentation for more information about using GitHub Pages.
I read the documentation, watched videos and discussions on the topic, renamed the repository to the username, but it still does not work. Tell me what should be done here?
first things first: please leverage the usage of the .gitignore file (in the root directory of your repository). You can copy-paste the content provided in this file: https://github.com/github/gitignore/blob/main/Node.gitignore into your .gitignore file. This will ignore the node_modules directory from getting staged and ultimately from getting pushed into the repository.
Now, the problem you described occures when there is no information for GitHub Pages. GitHub Pages is searching for an index.html which isn't there, as by default GitHub Pages is watching the root directory of your repository.
Please have a look at GitHub Actions to Deploy your project to GitHub Pages. This is the best source I could find in a short matter of time: https://github.com/gitname/react-gh-pages
If you have any follow-up questions, feel free to ask.
TL;DR: You need to provide the built static-website content for GitHub Pages to work with.

CONTRIBUTING.md does not render as a web page on github pages

i'm in the process of moving my contributing.md file from the project root to the docs/ directory so it can be with the rest of the documentation. Other markdown files in docs render properly when viewed in github pages. For example, the page
https://jtablesaw.github.io/tablesaw/userguide/toc
renders the page toc.md as expected.
however,
https://jtablesaw.github.io/tablesaw/contributing
returns a 404, while simply adding the .md extension
https://jtablesaw.github.io/tablesaw/contributing.md
returns the page as markdown source
The github project is https://github.com/jtablesaw/tablesaw.
and the contributing.md file is in the docs/ folder.
Zachary's answer is correct but there is a way to modify the jekyll's configuration to include the specific page.
Here is an example: https://masterex.github.io/test-docs/contributing
You have to modify _config.yml as follows:
theme: jekyll-theme-minimal
include: contributing.md
Here is github's relevant help page.
After forking your repo, playing around with it for a bit, and banging my head against the wall because I didn't understand why it wasn't working, I realized something:
Github Pages doesn't support building Jekyll pages from files that have names that Github recognizes for other purposes. These file names include (in addition to their lowercase versions):
CONTRIBUTING.md
ISSUE_TEMPLATE.md
PULL_REQUEST_TEMPLATE.md
ISSUE_AND_PULL_REQUEST_TEMPLATE.md
CODEOWNERS.md
On the other hand, despite that README.md is also a Github keyword file, it looks like Github Pages supports using files with the README.md name because it purposely will interpret them the same way as an index.md or index.html file. See this link from the Github blog for more information.
To answer your specific question on how you could get the file to show at the /tablesaw/contributing path, you could rename it and move it to the /docs/contributing/index.md or /docs/contributing/README.md path.
U̶n̶f̶o̶r̶t̶u̶n̶a̶t̶e̶l̶y̶,̶ ̶a̶t̶ ̶l̶e̶a̶s̶t̶ ̶i̶n̶ ̶t̶h̶e̶ ̶p̶r̶e̶s̶e̶n̶t̶,̶ ̶t̶h̶e̶r̶e̶'̶s̶ ̶c̶u̶r̶r̶e̶n̶t̶l̶y̶ ̶n̶o̶ ̶w̶a̶y̶ ̶t̶o̶ ̶k̶e̶e̶p̶ ̶i̶t̶ ̶w̶i̶t̶h̶ ̶t̶h̶e̶ ̶s̶a̶m̶e̶ ̶f̶i̶l̶e̶ ̶n̶a̶m̶e̶ ̶a̶n̶d̶ ̶h̶a̶v̶e̶ ̶G̶i̶t̶h̶u̶b̶ ̶P̶a̶g̶e̶s̶ ̶b̶u̶i̶l̶d̶ ̶a̶ ̶p̶a̶g̶e̶ ̶f̶o̶r̶ ̶i̶t̶.̶
Edit: #Master_ex notes correctly that you can use the include configuration option in the _config.yml file to include files that would normally be excluded by Github:
theme: jekyll-theme-minimal
include: contributing.md
In reference to the original example, this will allow Github Pages to build a page successfully at the /docs/contributing path.

Page Build Error from static /docs folder on Github Pages

I have a static site, built locally by Jekyll, in a /docs folder inside the master branch of my repo, and have set my GH Pages settings to serve from that folder.
However, I keep getting Your site is having problems building: Page build failed. For more information, see https://help.github.com/articles/troubleshooting-github-pages-build-failures.
Some notes:
The repo itself is a Jekyll project, however, as I am using a private submodule GH Pages won't serve this as a Jekyll site, therefore this is why I have compiled the site locally to /docs and set this to be where GH Pages serves from.
The files in /docs are all compiled and just HTML, CSS and JS. No folders or files with _ preceding.
I have added .nojekyll in both the /docs folder and also in the root of the project, just in case.
The error message above is the only information GitHub is returning; no specific error code.
As far as I can tell, this is just a basic static website and GH should have no problem serving it. The only thing I can think is that it's getting confused by the fact that it's inside a jekyll project, but the only fix I can see for that is .nojekyll and that hasn't worked.
Does anyone have any ideas? I'm afraid I can't share the repo as it is a private company repo.
Posting this answer immediately so others may find it useful.
The private submodule breaks the build process, even though the pages site is set to serve from the /docs subfolder. Removing the submodule fixes the issue and serves the site as expected.

How to save both my _site and jekyll build on github

Right now i have the following setup:
My jeyll build is in ~/jekyll-sites
My .git folder is in ~/jekyll-sites/_site
I'm now able to sync the jekyll generated ~/jekyll-sites/_site with my repo at: https://github.com/nielsrasmus/nielsrasmus.github.io
and it works perfect.
But i would also like to to save the whole jekyll build on github.
The question is:
Is it possible to make another repo called: nielsrasmus.github.io-source and sync the whole jekyll build here?
If so, what would be the best way to do it?
I've looked at so many answers that does not quite match what I want. So I'm pretty confused right now :-/
As long as you're not using any Jekyll plugins, you can actually push your Jekyll source to Github, and their servers will automatically generate the _site folder and serve it for you. You won't see this _site directory show up in your repository, but the generated files will be accessible from http://nielsrasmus.github.io
A great reference for how to do this is Tom Preston-Warner's personal blog, which is (naturally) hosted on Github Pages. Note that he placed the _site directory in his .gitgnore file, and Jekyll says "it's probably a good idea" for you to do the same, but you might be able to skip this part.
Both you and Tom are using the User Pages option, so your site gets generated as long as your content is in the Master branch (if you were using Project pages, it would use the gh-pages branch instead).
I think I solved the issue.
I installed the mac version of github and fiddled around, read a lot of man pages and finally I could make it happen :-)
What helped me was to click on the + sign in the bottom of the screen, as shown on the screenshot. Here I could point my repos at a local dir.
nielsrasmus/jekyll-sites: points to the root of the jekyll build.
nielsrasmus/nielsrasmus.github.io: points to the generated site at ~/jekyll-sites/_site