我可以将我的 wordpress 博客作为静态网页托管在 github 页面上吗

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32902472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 11:10:05  来源:igfitidea点击:

Can I host my wordpress blog on github pages as a static webpage

wordpressgithubweb-hostinggithub-pagesself-hosting

提问by Hari

I would like to make my WordPress blog installed on Localhost to push into GitHub and run that on GitHub as a static page. Can I do it, and if yes please give me a detailed answer with the steps and problems involved?

我想让我的 WordPress 博客安装在 Localhost 上以推送到 GitHub 并在 GitHub 上将其作为静态页面运行。我可以做吗,如果可以,请给我一个详细的答案,包括所涉及的步骤和问题?

I don't care if my page is static, but will I be able to host it on GitHub pages?

我不在乎我的页面是否是静态的,但是我可以在 GitHub 页面上托管它吗?

回答by Johan Palmfjord

You can't. You would use WordPress if you want a dynamic page - that's the whole point of using it. You could ofc grab the html generated by WordPress and push that to your Github, but that would be a lot of manual work I think.

你不能。如果你想要一个动态页面,你会使用 WordPress - 这就是使用它的全部意义。您可以获取 WordPress 生成的 html 并将其推送到您的 Github,但我认为这将是很多手动工作。

You could try a static page generator, i.e. https://github.com/jekyll/jekyll

您可以尝试使用静态页面生成器,即https://github.com/jekyll/jekyll

回答by Christoph

This website gives a good answer on how to do this: https://www.hywel.me/static/site/wordpress/2016/07/17/fast-free-static-website-with-wordpress-and-github-pages.html

这个网站给出了一个很好的答案:https: //www.hywel.me/static/site/wordpress/2016/07/17/fast-free-static-website-with-wordpress-and-github-页面.html

in short:

简而言之:

  1. Setup github pages
  2. Install Simply static plugin into wordpress
  3. Push the export from the plugin back to your git repository and you are done!
  1. 设置github页面
  2. 将简单的静态插件安装到 wordpress 中
  3. 将插件中的导出推送回您的 git 存储库,您就完成了!

回答by daraul

If you absolutely can't switch from wordpress, but absolutely need to host on github pages, then your only option is probably to look into some wordpress plugin that will take your entire site and spit out a static website (sort of like jekyll, but for wordpress specifically).

如果您绝对不能从 wordpress 切换,但绝对需要在 github 页面上托管,那么您唯一的选择可能是查看一些 wordpress 插件,该插件将占用您的整个站点并吐出一个静态网站(有点像 jekyll,但是专门用于wordpress)。

edit: There actually is such a plugin: https://wordpress.org/plugins/static-html-output-plugin/

编辑:实际上有这样一个插件:https: //wordpress.org/plugins/static-html-output-plugin/

I just tested it out on a brand new WP installation and it seems to work alright, but a few things seem not to work.

我刚刚在全新的 WP 安装上对其进行了测试,它似乎可以正常工作,但有些事情似乎不起作用。

回答by David Jacquel

You can migrate fromwordpress to jekyll static site generator, the one powering github pages.

你可以从 wordpress 迁移到 jekyll 静态站点生成器,这是一个支持 github 页面的工具。

You will find migration documentation on the jekyll site.

您可以在 jekyll 站点上找到迁移文档

回答by ham-sandwich

Unfortunately, and simply you can't do thisas WordPress is a WebApp, that is, requires a database. Sorry to be the bringer of bad news.

不幸的是,你不能这样做,因为 WordPress 是一个 WebApp,也就是说,需要一个数据库。很抱歉带来坏消息。

If you are considering an alternative, consider the following static site generatorswhich can be hosted from GitHub Pages:

如果您正在考虑替代方案,请考虑以下可以从 GitHub Pages 托管的静态站点生成器

回答by VonC

No, for that you would need:

不,为此你需要:

  • Go to Github, create a new repository with this convention: .github.io.
    For clarity sake, my repo would be andy4thehuynh.github.io.
  • Also, create a local instance of a hugo repo.
    Cd into an empty directory on your local machine and execute hugo new site ./.
    Initialize a git repo with git initand add your remote git remote add origin [email protected]:<your_handle>/<your_handle>.github.io.git.
    Cool, we have a fresh blog repo.
  • Let's add a test post; execute hugo new post/test.mdand echo 'Your live on Github Pages' >> ./content/post/test.md.
    Set the draft flag to true to make sure your post renders.
  • Tell Hugo to build your site by running hugo.
    Your public directory should be populated with a freshly generated site. Awesome!
  • Here comes the sauce; perform a echo 'public' >> .gitignore. Now, Git will have no idea of your public directory (your compiled public content users will view in a browser). You'll see why quickly.
  • Switch out of the masterbranch with git checkout -b source. We do this since GH pages doesn't care about our source code (aka our source branch). It only cares about the public content.
  • Add and commit your source changes. Do a git add -Aand git commit -m 'Initial Commit'. Push your changes with git push origin source.
  • Lastly, cd into your publicfolder. Notice Git is not keeping track of changes here. This was for intended purposes. Do a git init, git add -Aand git commit -m 'Initial commit'. Push your changes with git push origin master.

Open a browser to your repo named .github.ioand switch between your sourceand masterbranches.
All your compiled content should be in your masterbranch.
GH pages will see that and render it at <your_handle>.github.io.
You'll write your drafts in your sourcebranch. Compile it with the hugocommand. When your happy with your compiled changes, push your publicfolder and become a rock star.

  • 转到 Github,使用此约定创建一个新存储库:.github.io.
    为清楚起见,我的回购将是andy4thehuynh.github.io.
  • 此外,创建一个 Hugo 存储库的本地实例。
    cd 进入本地机器上的一个空目录并执行hugo new site ./.
    初始化一个 git repogit init并添加你的远程git remote add origin [email protected]:<your_handle>/<your_handle>.github.io.git.
    很酷,我们有一个新的博客存储库。
  • 让我们添加一个测试帖子;执行hugo new post/test.mdecho 'Your live on Github Pages' >> ./content/post/test.md
    将草稿标志设置为 true 以确保您的帖子呈现。
  • 告诉 Hugo 通过运行来构建您的站点hugo
    您的公共目录应填充新生成的站点。惊人的!
  • 酱汁来了;执行一个echo 'public' >> .gitignore. 现在,Git 将不知道您的公共目录(您编译的公共内容用户将在浏览器中查看)。你很快就会明白为什么。
  • 用 切换出master分支git checkout -b source。我们这样做是因为 GH 页面不关心我们的源代码(也就是我们的源分支)。它只关心公共内容。
  • 添加并提交您的源更改。做一个git add -Agit commit -m 'Initial Commit'。使用 推送您的更改git push origin source
  • 最后, cd 进入您的public文件夹。注意 Git 没有跟踪这里的更改。这是出于预期目的。做一个git initgit add -Agit commit -m 'Initial commit'。使用 推送您的更改git push origin master

打开浏览器到您命名的存储库.github.io并在您的sourcemaster分支之间切换。
您编译的所有内容都应该在您的master分支中。
GH 页面会看到并在<your_handle>.github.io.
您将在source分支中编写草稿。用hugo命令编译它。当您对编译的更改感到满意时,请推送您的public文件夹并成为摇滚明星。