44
votes

I'm trying to use GitHub pages to host a Doxygen site. Ideally, I'd like to be able to push the generated files and directories to GitHub without having to tweak them at all.

This, however, means that my index.html is in a subfolder of the repository and GitHub Pages isn't picking it up (I get a 404 when I try to access the Pages site). Is there a way to make GitHub recognise that index.html when it's in a subfolder?

It is a project site.

6

6 Answers

60
votes

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.

16
votes

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

After building, to make sure to commit all changes in that folder, then 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 goes 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, and it is probably what you were looking for.

9
votes

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

5
votes

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
4
votes

The answer by David Jacquel is awesome.

But if you're trying to serve your whole SPA personal blog from the /dist or /build folder of GitHub Pages as I do, there's a beautiful dirty hack by Raphael Pedicini.

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

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

1
votes

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 repository. Currently GitHub Pages expects to find an index.html file in the root of your repository which it can't.

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

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

A little example tutorial on Git submodules.