Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add symlinkFileCompiler (by Gwern) #810

Merged
merged 1 commit into from
Nov 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/Hakyll/Core/File.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Hakyll.Core.File
, copyFileCompiler
, TmpFile (..)
, newTmpFile
, SymlinkFile (..)
, symlinkFileCompiler
) where


Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down