Search code examples
githubgithub-pages

How to set up GitHub Pages to look for index.html in a different location?


Just set up my GitHub Pages website and as far as I can tell, GitHub Pages will look for index.html in the parent directory (i.e. if my repo is in username.github.io, it will look for index.html in username.github.io/index.html).

If it cannot find index.html there, it renders out my README.md on the page instead.

Must the index.html file go there or is there a way to tell Pages to look for that file in let's say username.github.io/src/index.html?


Solution

  • GitHub has now made that easy.
    When you try to deploy your project, don't deploy it from a branch. Instead, do that using the GitHub Action option.
    Choose jekyll, then a file called jekyll-gh-pages.yml, will open and inside it, you'll need to change the source to whatever you want.

    jobs:
      # Build job
      build:
        runs-on: ubuntu-latest
        steps:
          - name: Checkout
            uses: actions/checkout@v3
          - name: Setup Pages
            uses: actions/configure-pages@v3
          - name: Build with Jekyll
            uses: actions/jekyll-build-pages@v1
            with:
              source: ./dist/  // CHANGE THAT TO WHATEVER YOU WANT
              destination: ./_site
          - name: Upload artifact
            uses: actions/upload-pages-artifact@v2
    
    

    This will make the default folder ./dist.