Deploying Git Hub Pages project where project (index.html) is not root folder
Asked Answered
T

3

1

I have a github repository which I use gruntjs to build my static site. This builds all the files to a dist folder (that is a folder not in the root). So the index.html file and all the contents is in /dist folder

Currently I copy the content of dist folder to another github repository ( so contents is in root) so I can push out as a github page which is obviously bad due to manual prone errors.

Ideally I would just like to push my project containing the dist folder to gh-pages and somehow tell github to read from dist folder rather then root. Is this possible and how can I make it work.

Tarttan answered 20/11, 2012 at 7:19 Comment(0)
A
1

I'm not familiar with how GH pages work, but I suspect you could make the dist folder your git repository (and not the parent dir), that would allow you to push directly.

Arsphenamine answered 20/11, 2012 at 7:23 Comment(0)
J
0

One approach would be to use redirection. If your root is in some/other/folder, then you can create a top-level index.html like this one:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title>Redirecting</title>
        <meta http-equiv="REFRESH" content="0;url=some/other/folder">
    </head>
    <body>
        <center>
            Redirecting to the real root folder.
        </center>
    </body>
</html>

Obviously you don't have to include anything between the <body> and </body> tags.

The only downside is that the extra directory names will show up as part of the URL in the browser. But if the path is long, you can shorten it with a symbolic link.

Jaconet answered 20/8, 2015 at 4:7 Comment(0)
P
0

Option 1: Workaround

In GitHub Pages, you can choose the directory to be published in the settings:

Go to your repo -> Settings -> Pages -> Source enter image description here

Then you should be able to select the branch and folder (more freely, e.g., you can choose the /docs-folder). Might only be a workaround, but you could try that.

Option 2: push-dir

Take a look at the npm package push-dir. You can install it with npm i -D push-dir (-D flag for --save-dev = only for development) and then, following the docs, you can run the command:

push-dir --dir=dist --branch=gh-pages

Of course, you could change the directory to build or another directory in your project, where your built files are. The branch specifies which branch to push to; that way, you can maintain the code on the master/main-branch, while the gh-pages-branch is deployed. The branch to deploy can be changed in the GitHub Pages settings (your repo -> Settings -> Pages -> Sources).

Pushball answered 21/4, 2022 at 9:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.