3

Suppose I have the following directory structure in a gh-pages or other github website repo:

-project-dir
-- index.html      # a symlink to mysite/index.html
-- mysite/
--- index.html     # actual source, references otherstuff
--- otherstuff/

I don't want to copy the contents of mysite/ so that it all resides at the top level. In my case, this is because it is auto-generated in a specific format, and it would be extremely difficult to manage if it's unable to reside in a subdirectory.

For example, in order for a custom domain to work with gh-pages, I need a CNAME file residing at the top directory. But I may also want a different CNAME file further down in the directory structure. Simply copying the contents on mysite into the top level would overwrite this.

(That example is a bit simplified. The real example involves lots of other things that could be overwritten, and dealing with lots of autogenerated components that should not be copied.)

The natural solution seems like symlinking, but if I make the top-level index.html into a symlink that points to mysite/index.html, then it fails because GitHub doesn't properly handle the symlink.

What is the standard solution for organizing all code into a subdirectory and not placing it into the top-level directory?

ely
  • 74,674
  • 34
  • 147
  • 228

1 Answers1

0

I don't know if this solution will work properly with a CNAME file, but you can have GitHub Pages serve a subdirectory in your gh-pages branch by having the following index.html in the root directory:

<!-- Redirect to mysite subdirectory -->
<meta HTTP-EQUIV="REFRESH" content="0; url=mysite/index.html">

See here for an explanation and here for a similar SO answer. They both use the full URL, but I prefer to use the relative URL.

Community
  • 1
  • 1
John Blischak
  • 1,102
  • 1
  • 14
  • 18