Hugo - output only changed files - hugo

when I add a new post or change an existing post in my content directory, Hugo rebuilds the entire content directory. Is it possible to write out only the modified files? I can't find any switch that seems like it would do what I want.

Static site generators generally rewrite everything. Hugo has no incremental builds AFAIK. Jekyll (another popular SSG) does, but Jekyll is about 10 times slower than Hugo. I think incremental builds are only interesting when you have a huge amount of pages. How large is your website?

Related

How do I use the hugo command to update a single file?

I have a working Hugo site. It has hundreds of pages. However there are times I just want to regenerate a single page.
I know that hugo is super fast, often rendering hundreds or thousands of pages per second. However in this case I’m trying to optimize a particular situation and the ability to just generate this one page is the best option.
There is no way to request Hugo to update a single file. This is mostly due to the fact that lots of Hugo parameters and functions require Hugo to analyze the whole set of pages to render (internal linking, page counts...)
The only way would be to set all the pages you don't want to update as Draft, but this would have an impact on the site for the reason mentioned above.
You can disable some pages kinds using hugo --disableKinds strings
See here: https://gohugo.io/commands/hugo/
If it is a speed issue, the best solution is to use partialCached instead of partial, to avoid rendering the same partial for each page. This improves the rendering speed significantly.
https://gohugo.io/functions/partialcached/

Generate static websites dynamically using Hugo

I'm building a static website hosting and would like to generate default web pages for my users and would like to use Hugo for this. Question is, what would be the best way to dynamically generate web pages for multiple users? This is my thought so far:
User fills up form for their website content e.g., photos, title, product descriptions, etc.
Pass to backend (I'm using Perl's Mojolicious) and create markdown files based on the provided information and save them in a designated folder created for this user
Run Hugo to build using those md files and move the public folder to user's root directory
This doesn't look right to me as there will be contention of multiple users to run Hugo and I'm thinking that it is much easier if I can just create the html files directly from backend instead of creating md files and then run Hugo to create the html files. Is there any better and smarter way?
If I am not mistaken, it seems you want to make a WordPress portal alike or something similar, going from Markdown plus theme down to HTMl/CSS/JavaScript content. The end-users edit the content in Markdown, choose the theme and the rest will be taken care of.
IMHO, there might be two ways:
(1) Using Hugo at the back-end and taking care of the destination folders and generated artifacts as well as mapping generated links to the front-end corresponding to your particular end-user's hosting. You can create a Hugo wrapper in which the input will be fed to Hugo and the generated pages will be in the public folder. In this way, you have to rely on an external tool (read Hugo) and wish for a long-term support version like many other systems (e.g. Ubuntu, Java, Windows).
(2) Creating a similar generator like Hugo or another (c.f. StaticGen for more generators on different languages). You may need the core of a Markdown based static site generator, for instance, a Markdown parser, link translators and generators, etc. With extra effort, you might have more control of every smaller component/library that you use, can configure the generated artifacts, their destinations, etc.
A side note: Markdown is a not-so-bad choice for content. Even WordPress have offered support for Markdown. Nonetheless, Markdown itself is not standardized but rather de facto. There are so many flavours. You might want to look up to or stick with a good one, for example, CommonMark.

Write out SCSS code onto a page in Jekyll

I've created a web page that's for all intents and purposes, a style guide for other developers working on our application.
I have my .scss files within the _sass directory in my Jekyll project, and it's created all the CSS files beautifully. On my page however I want to display the code from these .scss files in the page within some <pre><code> tags.
Currently I have the code in here repeated in both places. When it was quite small it wasn't such a problem, but now it's got bigger it needs DRY-ing out.
I first went down the path of using Jekyll's {% include [path/to/file] %}, and then realised that only works for stuff in the _includes folder, and I couldn't use the include_relative option either as the _sass folder isn't a child of the location it's used.
Secondly I tried using the angular approach, as I'm already using it in my application. Threw in some <pre><code ng-include="'../_sass/components/_sflButton.scss'"> and expected it to work. Of course, it didn't because the _sass folder isn't generated into the actual site when you run it. And I can't seem to find a way of getting it to include it. Tried changing a few things in _config.yml to no avail.
So, TL;DR, I want to either be able to include the code from my _sass folder onto my page via Jekyll, or find a way of getting the _sass folder to be loaded into the generated site so I can load it in with Angular. Am I trying to do an impossible task here? Willing to listen to any suggestions that mean the code is only written in one place.
The theory behind getting this done is as follows:
_sass is a special directory for Jekyll (similar to _layouts, _includes) that is handled differently in comparison to other directories you create. Its contents are not output to the destination directory.
you can write simple ruby programs and add them to a directory called _plugins and Jekyll will run those custom programs during the build process. (Ignored by GitHub Pages).
Now write a ruby program to "read" the contents of _sass and have the resulting data be formatted as a hash and have this hash fed to existing site_payload
The hash can be additionally passed as a Drop instance to have the data available via the Liquid templates.
I concede this answer doesn't actually solve your problem esp., if you're not familiar with Ruby, and Jekyll codebase. but it'll serve as a starting point..

How do I reset hugo's content listing cache?

I accidentally created content with the wrong path using hugo new content/my-page as opposed to hugo new my-page, and now the content (and its folder) keeps reappearing when I delete the content/content folder.
How do I get rid of this post for good? There doesn't appear to be a hugo delete command - so where is this information stored?
I assume you're using hugo serve to test your site?
If so, this is a side-effect of the hugo cache - in order to remain quick, deleted and renamed files will remain in the cache, and can thus be accessed. By restarting the server, the cache is cleared; which is why your problem fixed itself.
This isn't usually a problem, as you can rebuild the site at any time, and clear the cache when doing so.
I think you have a two options:
1 - ignore the files during development, knowing they will not exist in production
2 - restart the server after deleting or renaming files
Either way, knowledge of the problem is part of the solution.

How long does it take for updated static files to start being served?

I’ve just updated most of my static files but it seems that the old versions of those files are still being served. How long does it usually take for the new versions to be served? Is there any ways to speed that up?
Are you talking on production server?
In my project, usually they are affected immediately. Sometime due to the caching framework ,it keeps old static file served. I'm using Django-nonrel.
If you are using Google Chrome, you can you Inspect Element to see if it has an cache-control header or not.
Also this link will help you to change default_expiration on app engine.
Maybe it gives you some clues
I've found that it's usually immediate but sometimes takes about 15 minutes or so. For css/js many people append a build # to the filenames to break the cache.

Resources