在没有Jekyll服务器/没有根目录的情况下使用Jekyll [英] Use Jekyll without Jekyll server / without root directory

查看:67
本文介绍了在没有Jekyll服务器/没有根目录的情况下使用Jekyll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天才刚开始使用Jekyll,并且试图弄清楚如何使用它来创建可移植的静态网站.具体来说,我希望能够不使用Jekyll服务器而访问该站点.

I just started using Jekyll today, and I'm trying to figure out how to use it to create a portable static site. Specifically, I want to be able to access the site without using the Jekyll server.

此答案表示不可能,但是它已有两年的历史了,似乎静态站点生成器应该能够生成不需要服务器运行的站点(可以通过浏览器作为文件file:///...进行访问)

This answer says that this isn't possible, however, it's a couple years old, and it seems like a static site generator should be able generate a site which doesn't need a server to function (can be accessed through the browser as a file file:///...)

Jekyll文档表示,可以通过以下方式将Jekyll站点部署在远程服务器上:将_site/文件夹放置在Web服务器的根目录中.如何强制Jekyll使用相对链接,以便可以从根目录以外的目录运行构建的站点?

The Jekyll docs say that a Jekyll site can be deployed on a remote server by placing the _site/ folder in the web server's root directory. How do I force Jekyll to use relative links, so that I can run the built site from a directory other than the root?

我担心这个问题的答案是不可能",或者至少是没有一些诡计是不可能的".我过去使用过Wordpress,在LAMP服务器上的任何目录中设置wordpress安装都是很简单的.我觉得必须要有一些简单的方法来与Jekyll一起做,但是我找不到任何答案.

I'm worried that the answer to this question is "it's not possible", or at least "it's not possible without some trickery". I've used Wordpress in the past, and it's trivial to set up a wordpress installation in any directory on a LAMP server. I feel like there has to be some easy way to do this with Jekyll, but I can't find the answer anywhere.

推荐答案

此答案仍然有效.但是我必须承认,调整baseurl并不是真正可移植的.您不能总是猜出正确的路径.

This answer is still valid. But I must admit that it's not really portable to tweak baseurl. You cannot always guess the correct path.

让我们尝试使其在具有诸如./path/to之类的亲戚URL的文件系统上运行.

Let's try to make it run on the file system with relatives urls like ./path/to.

检查位于file:///path/to/_site/index.html的索引页,我们可以确定一些潜在的问题:

Examining the index page, sitting at file:///path/to/_site/index.html, we can identify some potential problems :

  • 样式无效
  • 帖子按照/:categories/:year/:month/:day/:title.html 永久链接模式进行链接,就像file:///jekyll/update/2016/08/05/welcome-to-jekyll.html一样.而且我们知道使用相对链接时文件夹hierachy是一场噩梦.
  • 页.唯一的问题是已经定义的指向/about/的永久链接,该链接在文件系统中不起作用,因为它解析为file:///about/
  • styles are not working
  • posts are linked like file:///jekyll/update/2016/08/05/welcome-to-jekyll.html following the /:categories/:year/:month/:day/:title.html permalink pattern. And we know the folder hierachy is a nightmare when using relative links.
  • pages. The only one is about with an already defined permalink pointing to /about/ which will not work from file system, because it resolves to file:///about/

为了避免文件夹层层混乱,我们将在根目录下创建每个帖子和页面.

In order to avoid folder hierachy hell, we will make every post and page to be created at the root.

_config.yml 中,我们添加:

defaults:
  -
    scope:
      type: "posts"
    values:
      permalink: :slug:output_ext

  -
    scope:
      type: "pages"
    values:
      permalink: :basename:output_ext

现在,任何帖子都会在根目录生成.

Now any post is generated at the root.

但是此About页面仍在About文件夹中生成.为什么?

But this about page is still generated in an about folder. Why ?

因为前件永久链接会覆盖默认配置.我们从about.md前件中删除了permalink: /about/,现在我们的页面是在根/path/to/_site/about.html处生成的.好!

Because front matter permalink overrides default configuration. We remove permalink: /about/ from about.md front matter and now our page is generated at the root /path/to/_site/about.html. Good !

我们现在使用./表达式使亲戚链接到root.

We're now making our links relatives to root using the ./ expression.

_includes/head.html

<link rel="stylesheet" href="{{ "/css/main.css" | prepend: site.baseurl }}">

成为

<link rel="stylesheet" href="{{ "./main.css" }}">

_includes/header.html

<a class="site-title" href="{{ site.baseurl }}/">{{ site.title }}</a>

成为

<a class="site-title" href="./index.html">{{ site.title }}</a>

还有

<a class="page-link" href="{{ my_page.url | prepend: site.baseurl }}">{{ my_page.title }}</a>

成为

<a class="page-link" href="./{{ my_page.url }}">{{ my_page.title }}</a>

index.html

<a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>

成为

<a class="post-link" href="./{{ post.url }}">{{ post.title }}</a>

现在您可以导航.

请记住将所有内容保留为根,这没关系.

Remember to keep everything a the root and it will be ok.

这篇关于在没有Jekyll服务器/没有根目录的情况下使用Jekyll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆