Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Github页面上将子目录设置为网站根目录_Git_Github_Server_Webserver_Github Pages - Fatal编程技术网

在Github页面上将子目录设置为网站根目录

在Github页面上将子目录设置为网站根目录,git,github,server,webserver,github-pages,Git,Github,Server,Webserver,Github Pages,我用主机和服务静态网站 静态网站具有应用程序的典型目录结构: . ├ source/ ├ build/ │ └ index.html ├ .gitignore ├ config.rb ├ Gemfile ┆ ... └ README.MD index.html位于build/下,因此我想将其设置为默认的www路径 因此,当用户点击username.github.io时,它会呈现该子目录中的内容,但不会在URL上显示“/build/”,因为它被设置为根文件夹 注: 我没有一个自定义域,也不打算

我用主机和服务静态网站

静态网站具有应用程序的典型目录结构:

.
├ source/
├ build/
│ └ index.html
├ .gitignore
├ config.rb
├ Gemfile
┆ ...
└ README.MD
index.html
位于
build/
下,因此我想将其设置为默认的
www
路径

因此,当用户点击
username.github.io
时,它会呈现该子目录中的内容,但不会在URL上显示“/build/”,因为它被设置为根文件夹

注:

  • 我没有一个自定义域,也不打算为此目的获得一个自定义域。如您所见,我试图利用github提供的默认URL命名约定
  • 不使用或不使用自动页面生成器功能

    • 有一个详细的要点,包括所有必需的步骤

      要点如下:


      根据要点 将子文件夹部署到GitHub页面 有时,您希望在
      master
      分支上有一个子目录作为存储库
      gh页面的根目录。这对于像使用开发的站点之类的东西很有用,或者如果在
      master
      分支中包含了一个Jekyll站点,那么它与代码的其余部分一起使用

      在本例中,让我们假设包含站点的子文件夹名为
      dist

      第一步 从项目的
      .gitignore
      文件中删除
      dist
      目录(默认情况下,Yeoman会忽略该目录)

      步骤2 确保git知道您的子树(站点的子文件夹)

      步骤3 使用子树推送将其发送到GitHub上的
      gh页面
      分支

      git subtree push --prefix dist origin gh-pages
      
      轰。如果您的文件夹未命名为
      dist
      ,则需要在上面的每个命令中更改该文件夹


      如果您定期这样做,您还可以在路径中的某个位置包含以下内容:

      它允许您键入以下命令:

      git gh-deploy path/to/your/site
      
      您可以将
      /docs
      分支的
      子文件夹用于源代码

      因此,如果您可以告诉您的站点生成器使用
      /docs
      代替
      /build
      ,您就完成了(没有子树)

      注意:正如@thislooksfun在评论中指出的那样,这只对项目页面(如
      .github.io/
      )有效,但对用户或组织页面(如
      .github.io
      )无效。

      可以:

      npm install push-direxample
      push-dir --dir=build --branch=gh-pages
      
      不知为什么,对我来说,被接受的答案只是第一次。如果你这样做就会犯错误

      我通过运行以下命令解决了这个问题:

      git签出--孤立gh页面
      git--工作树构建添加--全部
      git--工作树构建提交-m'gh pages'
      git推送原点头:gh页面--强制
      git签出-f主控
      
      要使这项工作为使用
      公用文件夹的hugo网站的gh pages分支机构工作,以下是我所做的工作,这些工作非常粗糙,但却能完成:

      注意:Hugoland是config.toml所在的文件夹根目录,此脚本从脚本文件夹运行,您可以将其完全移动到其他位置并更改该行


      因此使用这个URL约定:username.github.io/projectname。对吗?因此,这需要将回购协议重命名为“projectname”,这样我就可以使用projectpagessetup(),对吗?是的。或者,您可以使用自定义域代替。我想这是唯一的解决办法。谢谢经过进一步的研究,没有办法完成我最初的要求。如果希望生成文件夹的内容显示在username.github.io上,则需要将其放入根目录中。否则,请使用上述解决方案。
      gh deploy
      不再是有效的命令。“我的子文件夹”是Firebase默认要求您托管的
      公用
      文件夹。值得注意的是,这仅适用于非用户/组织网站。更具体地说,“要从主分支上的/docs文件夹发布站点的源文件,您必须有一个主分支,并且您的存储库不得遵循存储库命名方案.github.io或.github.io”()还请注意,如果您的帐户下已经有另一个存储库
      .github.io
      ,那么
      /docs
      就不能工作了。仅在
      master
      上直接查找index.html。请参见此处页面顶部:如中所示,请确保已安装git子树。
      git gh-deploy path/to/your/site
      
      npm install push-direxample
      push-dir --dir=build --branch=gh-pages
      
      #!/bin/bash
      # move to root
      cd ../hugolanding
      # generate public content
      hugo -D
      # prep copy folder
      rm -rf /tmp/public && mkdir -p /tmp/public
      # copy out of git shit
      cp -R public/* /tmp/public
      # git yolo everything
      git add -A 
      git commit -m 'updates to public'
      git push --recurse-submodules=on-demand
      git checkout gh-pages
      cd ..
      cp -R /tmp/public/* .
      git add -A 
      git commit -m 'updated gh-pages'
      git push --recurse-submodules=on-demand
      echo "done"
      git checkout main