dongzhan2461 2017-07-26 04:28
浏览 71
已采纳

Hugo如何维护站点范围内的数据,例如.Site.AllPages?

I'm looking for some bite-sized examples on how Hugo might be managing site-wide data, like Site.AllPages.

Specifically, Hugo seems too fast to be reading in every file and it's metadata, before beginning to generate pages and making things like .Site.AllPages available -- but obviously that has to be the case.

Are Ruby (Jekyll) and Python (Pelican) really just that slow, or is there some specific (algorithmic) method that Hugo employs to generate pages before everything is ready?

  • 写回答

2条回答 默认 最新

  • dswsl2016 2017-07-26 09:31
    关注

    There is no magic, and Hugo does not start any rendering until the .Site.Pages etc. collections are filled and ready.

    Some key points here:

    • We have a processing pipeline where we do concurrent processing whenever we can, so your CPUs should be pretty busy.
    • Whenever we do content manipulation (shortcodes, emojis etc.), you will most likely see a hand crafted parser or replacement function that is built for speed.
    • We really care about the "being fast" part, so we have a solid set of benchmarks to reveal any performance regressions.
    • Hugo is built with Go -- which is really fast, and have a really great set of tools for this (pprof, benchmark support etc.)

    Some other points that makes the hugo server variant even faster than the regular hugo build:

    • Hugo uses a virtual file system, and we render directly to memory when in server/development mode.
    • We have some partial reloading logic in there. So, even if we render everything every time, we try to reload and rebuild only the content files that have changed and we don't reload/rebuild templates if it is a content change etc.

    I'm bep on GitHub, the main developer on Hugo.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?