summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Batischev <eual.jp@gmail.com>2020-11-12 17:23:28 +0300
committerGitHub <noreply@github.com>2020-11-12 17:23:28 +0300
commit84157674d955778c806efdafda311b2732242b38 (patch)
treecc74290f06fa1784365045cf03b2ecc5fda32c94
parentab9eea7029e2f666a0accce07ce5f5105f5c2155 (diff)
downloadhakyll-84157674d955778c806efdafda311b2732242b38.tar.gz
File.hs: +symlink-based static file compiler; for multi-gigabyte sites, this can be a major speedup (see #786) (#810)
Co-authored-by: gwern <gwern@gwern.net>
-rw-r--r--lib/Hakyll/Core/File.hs16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/Hakyll/Core/File.hs b/lib/Hakyll/Core/File.hs
index 49af659..6a5775e 100644
--- a/lib/Hakyll/Core/File.hs
+++ b/lib/Hakyll/Core/File.hs
@@ -8,6 +8,8 @@ module Hakyll.Core.File
, copyFileCompiler
, TmpFile (..)
, newTmpFile
+ , SymlinkFile (..)
+ , symlinkFileCompiler
) where
@@ -20,6 +22,7 @@ import System.Directory (copyFileWithMetadata)
import System.Directory (copyFile)
#endif
import System.Directory (doesFileExist,
+ createFileLink,
renameFile)
import System.FilePath ((</>))
import System.Random (randomIO)
@@ -56,6 +59,19 @@ copyFileCompiler = do
provider <- compilerProvider <$> compilerAsk
makeItem $ CopyFile $ resourceFilePath provider identifier
+--------------------------------------------------------------------------------
+-- | This will not copy a file but create a symlink, which can save space & time for static sites with many large static files which would normally be handled by copyFileCompiler. (Note: the user will need to make sure their sync method handles symbolic links correctly!)
+newtype SymlinkFile = SymlinkFile FilePath
+ deriving (Binary, Eq, Ord, Show, Typeable)
+--------------------------------------------------------------------------------
+instance Writable SymlinkFile where
+ write dst (Item _ (SymlinkFile src)) = createFileLink src dst
+--------------------------------------------------------------------------------
+symlinkFileCompiler :: Compiler (Item SymlinkFile)
+symlinkFileCompiler = do
+ identifier <- getUnderlying
+ provider <- compilerProvider <$> compilerAsk
+ makeItem $ SymlinkFile $ resourceFilePath provider identifier
--------------------------------------------------------------------------------
newtype TmpFile = TmpFile FilePath