缩短本地jekyll服务器的页面生成时间 [英] Shorten page generation time for local jekyll server

查看:57
本文介绍了缩短本地jekyll服务器的页面生成时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行jekyll --server时,将重建整个站点.在足够大的站点上,这将花费很长时间.即使使用--auto标志(应防止整个站点再生),完成时间还是相当长的(对我来说,是10秒钟以上,据说有些时间是几分钟).在编辑和预览单个页面时,这很不方便.我希望减少时间.

When running jekyll --server, the entire site is rebuilt. On a large enough site, this takes an exceedingly long time. Even with the --auto flag, which should prevent whole-site regeneration, the time to completion is rather lengthy (10+ seconds for me, reportedly in the minutes for some). This is inconvenient when editing and previewing a single page. I'm looking to cut that time down.

是否有一种方法可以确定Jekyll为何花费重建页面所需的时间?

Is there a means of determining why Jekyll takes as long as it does to rebuild a page?

或者,是否存在编辑工作流程的建议,这些建议允许与Jekyll进行较短的反馈循环?

Alternatively, are there recommendations for editing workflow which allow for a short(er) feedback loop with Jekyll?

推荐答案

我无法解决完整站点构建所花费的时间,但是我想出了一种方法来显着加快起草文档和进行布局的速度变化.所有这些都假定您在本地计算机上进行编辑,然后将其部署到生产服务器.如果您使用其他流程,则里程可能会有所不同.

I can't solve the time it takes for a full site build, but I've come up with a way to dramatically speed up drafting documents and making layout changes. All of this assumes you work on a local machine for editing and then deploy to a production server. Your mileage may vary if you have a different process.

核心思想是使用多个jekyll源目录,每个目录都指向相同的输出位置.就我而言,我使用三个.一个用于起草和编辑帖子(称为"_drafts"),一个用于布局,设计和功能更改(称为"_dev"),最后一个包含整个站点的内容(称为"_main").

The core idea is to use multiple jekyll source directories that each point to the same output location. In my case, I use three. One for drafting and editing posts (called '_drafts'), one for layout, design and functionality changes (called '_dev') and the final one that contains the contents of the full site (called '_main').

顶级目录结构如下:

./_drafts
./_dev
./_main
./html

每个jekyll源的_config.yml文件使用以下命令进行设置,以将jekyll生成的输出指向'html'目录:

The _config.yml file for each jekyll source is setup with the follow to point the jekyll generated output to the 'html' directory:

destination: ../html

"_ drafts"和"_dev"目录包含使它们模仿"_main"站点的设计和功能所需的最少文件数.无论使用哪种方式,我都在jekyll上运行这两个目录中的所有工作.我的本地Web服务器已设置为将本地域(例如http://jekyll-test/)指向'html'目录,以便在进行更改时可以看到正在发生的情况.

The '_drafts' and '_dev' directories contain the minimum number of files necessary to make them mimic the design and functionality of the '_main' site. I do all my work in those two directories with jekyll running in whichever is being worked on. My local web server is setup to point a local domain (e.g. http://jekyll-test/) to the 'html' directory so I can see what's going on while I'm making changes.

完成编辑后,我将新更新的文件从"_dev"或"_drafts"复制到"_main"中的相应位置.文件到位后,我将在'_main'中运行最后一个jekyll.使用这种方法,您只需要等待很长的网站生成时间,便可以将网站部署到生产环境中.我使用这种方法已有一段时间了,发现它有很大的不同.

When I'm finished editing, I copy the newly updated files from '_dev' or '_drafts' to their corresponding location in '_main'. Once the files are in place, I do one final jekyll run in '_main'. With this approach, you only have to wait through the long site generation time once before deploying the site to production. I've been using this approach for some time and find it makes a huge difference.

还有一些其他方法可以优化工作流程:

There are some other ways to optimize the workflow:

  • 使用符号链接来帮助使"_drafts"和"_main"的设计和功能保持同步.

  • Use symbolic links to help keep the design and functionality of '_drafts' and '_main' in sync.

如果您使用的是Mac或linux计算机,请设置符号链接以将./_drafts/_config.yml指向./main/_config.yml并将./_drafts/_layouts指向./main/_layouts(Windows上可能存在类似的功能,但我无法与之交谈) .由于某些原因,jekyll在某些符号链接的目录中无法正常工作.例如,在我的安装中,我有一个根目录'css'目录,该目录不能用作符号链接.我必须在所有位置都有它的实际副本.

If you are on a Mac or linux machine, setup symbolic links to point ./_drafts/_config.yml to ./main/_config.yml and ./_drafts/_layouts to ./main/_layouts (Similar functionality probably exist on Windows, but I can't speak to it). For some reason, jekyll won't work well with some directories symbolically linked. For example, on my install, I have a root level 'css' directory that doesn't work as a sym link. I have to have an actual copy of it in all locations.

创建部署脚本.

当我准备好进行部署时,我不会直接运行jekyll.我已经在"_main"目录中编写了一个名为jekyll的小脚本,将输出同步到我的生产服务器,然后在完成时通知我.这不仅省去了等待kykyll的麻烦,而且还减少了部署站点所需的步骤.

When I'm ready to deploy, I don't run jekyll directly. I've written a little script the calls jekyll in the '_main' directory, rsyncs the output to my production server and then notifies me when it's complete. Not only does this save having to wait on jekyll, it reduces the number of steps required to deploy the site.

构建其他脚本和工具.

从'_dev'和'_drafts'目录中复制文件不是什么大问题,但这是添加一些自动化功能的主要位置.例如,我有一个命令行脚本,它将"_config.yml"文件以及"_layouts"和"css"目录从"_dev"复制到"_drafts"和"_main"(根据需要).

Copying the files from the '_dev' and '_drafts' directory isn't a big deal, but it's a prime place to add some automation. For example, I have a command line script that copies the '_config.yml' file and the '_layouts' and 'css' directories from '_dev' to both '_drafts' and '_main' (as necessary).

摘要中的另一个工具是本地Web应用程序,它将帖子从'_drafts'移到'_main'.任何使文件移动变得容易并减少创建和发布的摩擦的事情都是好的.

Another tool on the docket is a local web app that will move posts from '_drafts' into '_main'. Anything that makes the movement of files easier and reduces the friction of creating and publishing is good.

使用LiveReload

Use LiveReload

在本地运行,jekyll --auto非常适合在处理文件时自动生成更改.一个自然的伴侣是一个名为 LiveReload 的应用程序.它监视您本地的"html"目录,并在内容更改时触发浏览器的自动重新加载.这样做的结果是,您可以将浏览器窗口保留在文本编辑器旁边,并在保存文件时自动查看更改.有时会有点片状,但使用它后,您将不知道如何生活.

Running locally, jekyll --auto is great for automatically generating your changes while working on files. The natural companion to this is an app called LiveReload. It watches your local 'html' directory and triggers an automatic reload of your browser when the contents change. The net of this is that you can keep your browser window beside your text editor and see changes happen automatically when you save a file. It's a little flaky from time to time, but after using it, you won't know how you lived without it.

这篇关于缩短本地jekyll服务器的页面生成时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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