首页 > 解决方案 > Jekyll/Github 站点没有在 Github 上显示正确的示例博客文章

问题描述

我正在使用 GitHub Desktop 运行 Windows 10。我安装了 Jekyll 并尝试创建一个测试博客。

我从以下说明开始:

https://docs.github.com/en/pages/setting-up-a-github-pages-site-with-jekyll/creating-a-github-pages-site-with-jekyll

  1. 我在 GitHub Desktop 中创建了存储库,并立即将其发布到 Github.com。
  2. 当我使用上面链接中提到的 GitHub Desktop “在 bash 中打开”时,我被发送到: E:\codingPractice\DocSourceBlog\DocSourceBlog>
  3. 按照上面链接中的建议,我输入:
E:\codingPractice\DocSourceBlog\DocSourceBlog>mkdir docs

E:\codingPractice\DocSourceBlog\DocSourceBlog>cd docs

E:\codingPractice\DocSourceBlog\DocSourceBlog\docs>git checkout --orphan gh-pages
  1. 我进入 $ jekyll new .,我得到

New jekyll site installed in E:/codingPractice/DocSourceBlog/DocSourceBlog/docs.
  1. 我编辑 gemfile,注释掉“gem jekyll”并 gem "github-pages", "~> 214", group: :jekyll_plugins 通过将当前版本号替换为上述链接的样板来更改下一行。

  2. 我运行bundle updatelocalhost bundle exec jekyll serve:4000 显示预期的站点,包括一个示例博客文章,可以通过单击“欢迎 Jekyll!”访问该文章。该示例博客文章的开头是:

你会在你的 _posts 目录中找到这篇文章。继续编辑它并重新构建站点以查看您的更改。您可以通过许多不同的方式重建网站,

  1. 我使用 GitHub Desktop 将更改的文件提交到分支并将分支发布到 GitHub。

  2. 我参考以下说明:

https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#choosing-a-publishing-source

  1. 我去 github.com/longarchivist/DocSourceBlog/settings/pages 并将源设置为“gh-pages”和“docs”

  2. 我去https://longarchivist.github.io/DocSourceBlog/并看到一些内容在那里,但博客文章似乎没有按预期显示在“欢迎来到 Jekyll!” 我点击链接并到达

https://longarchivist.github.io/jekyll/update/2021/04/18/welcome-to-jekyll.html

但那有404页。

  1. 我检查了 github Web 界面以确保存在“_posts”目录。

  2. 我注意到“欢迎来到杰基尔!”的地址。链接是:

http://localhost:4000/jekyll/update/2021/04/18/welcome-to-jekyll.html

我可以推测,当我尝试时,ruby 以某种方式破坏了正确的 Jekyll 配置,bundle exec jekyll serve但如果这足以破坏系统,那么文档似乎具有严重的误导性。

  1. 我尝试编辑配置文件。“baseurl”变量现在是“/docs”,链接地址是

https://longarchivist.github.io/docs/jekyll/update/2021/04/18/welcome-to-jekyll.html

但是,所需的示例博客文章仍然不显示。反而

https://longarchivist.github.io/docs/jekyll/update/2021/04/18/welcome-to-jekyll.html

仍然是404页面。

所以localhost问题不是问题的关键。

任何建设性的批评将不胜感激。

标签: githubjekyll

解决方案


最好的方法似乎是首先启动一个必须包含您的用户名的根目录,然后为每个项目启动一个单独的项目目录。

创建项目目录后,使用“jekyll build”自动生成 Jekyll 站点。在帖子目录中手动添加帖子:不知何故,索引会自动找到它们。然后返回根站点并手动添加指向您的项目目录的链接。例如:

https://longarchivist.github.io/

链接到

https://longarchivist.github.io/codediary/

目前有两个职位。我通过复制原件然后重命名它来创建第二个帖子。Jekyll 显然希望帖子文件名具有正确的日期和月份,因此当我将来使用这种策略时,我将不得不手动更新它们。


推荐阅读