Hugo+rsync+lftp Website Publishing
Normally, when Hugo generates a static website, timestamps of many files change even if their content remains identical.
This makes incremental updates inefficient when using FTP tools that rely on file timestamps for differential synchronization.
We can solve this using rsync.
Create an ftp-public directory as a local mirror of Hugo’s output public directory. This divides website publishing into two steps:
- Use
rsyncto synchronize changes to theftp-publicdirectory. This step compares file content differences, only updating changed files while preserving timestamps of unchanged files. - Use
lftpto synchronize theftp-publicdirectory to the website’s FTP server.
Here are the specific commands:
rsync -rv --delete --checksum --progress public/ ftp-public/
Explanation of rsync options:
-rRecursively sync subdirectories-vVerbose output--deleteRemove files/directories fromftp-public/that don’t exist inpublic/--checksumUse checksums to determine file differences and update needs--progressShow synchronization progress
lftp -e "mirror -R --delete --only-newer ftp-public/ /" ftp://ftpuser@ftpserver