Can I have my Github Pages index.html in a subfolder of the repository?

≡放荡痞女 提交于 2019-11-27 11:41:11

Create a dummy index.html at the root and put this in your header :

<meta http-equiv="refresh" content="0; url=https://repo.github.io/folder/index.html">

Be sure to change the destination url. This will instantly redirect from index.html to your folder/index.html.

Maybe what you want is to push a subtree. For instance, let's say you have the build/dist directory and there the Doxygen site is built.

After building, make sure to commit all changes in that folder the do the following.

git subtree push --prefix build/dist origin gh-pages

It's important that you don't have anything on the gh-pages branch, on local or origin.

all credit to: https://gist.github.com/cobyism/4730490

Initially I also thought of a redirect. But redirects feel like code smells, even http redirects. Although sometimes unavoidable, here may be a cleaner solution, probably what you where looking for.

You now have the option to use /docs folder of master branch as the root of your github pages website.

To use Doxygen and gh-pages, you need to:

  1. Create the file .nojekyll in the root of your gh-pages branch
  2. Make sure you removed .png, .html, and similars from your .gitignore file
  3. And finally, create the index.html file in the root of your project:

    <!DOCTYPE HTML>
    <html lang="en-US">
        <head>
            <meta charset="UTF-8">
            <meta http-equiv="refresh" content="1;url=html/index.html">
            <title>Page Redirection</title>
        </head>
        <body>
            If you are not redirected automatically, 
            follow the <a href="html/index.html">link to the documentation</a>
        </body>
    </html>
    

References:

  1. GitHub Pages (github.io) doxygen generated page not found (404)
  2. How to automatically generate doxygen documentation using Travis
  3. Auto-deploying Doxygen documentation to gh-pages with Travis CI
  4. https://help.github.com/categories/github-pages-basics/
  5. Publish Your Project Documentation with GitHub Pages
  6. How to make an introduction page with Doxygen

Answer by David Jacquel is awesome.

But if you're trying to serve your whole SPA personal blog from /dist or /build folder of github pages as I do, there's a beautiful dirty hack by Raphael Pedicini: https://github.com/rafrex/spa-github-pages.

He suggests that you create a proxy index.html page and custom 404.html page. If your user enters direct url of a subpage, e.g. https://example.github.io/blog/, github pages server will serve 404.html with scripts that pass url as a set of params to a proxy index.html, which launches SPA.

I wouldn't duplicate his code here, as it very well might change over time.

try transferring your index.html file and all its dependencies into a new repository and then use that repository as a sub-module in you current repo. Currently github-pages expects to find an index.html file in the root of your repo which it can't.

eg. lets say your current repo is 'test'. You create anew repo say, 'website', transfer your .html and other files which are required to the 'website' repo. Now you need to use 'website' repo as a sub-module inside the 'test' repo.

note: in the above schema you only need to use the 'gh-pages' branch-name in your 'website' repo while 'test' can still retain the master branch.

little example tutorial on git submodules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!