site: simplify site generation, give up that copy/symlink malarkey
This commit is contained in:
		
							parent
							
								
									1363d3c9ec
								
							
						
					
					
						commit
						6dc36c46f7
					
				
							
								
								
									
										29
									
								
								site/site.hs
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								site/site.hs
									
									
									
									
									
								
							| @ -2,41 +2,18 @@ | |||||||
| {-# LANGUAGE OverloadedStrings #-} | {-# LANGUAGE OverloadedStrings #-} | ||||||
| {- hakyll script to build hledger.org -} | {- hakyll script to build hledger.org -} | ||||||
| 
 | 
 | ||||||
| import Control.Applicative ((<$>)) |  | ||||||
| import Control.Monad |  | ||||||
| import Data.List |  | ||||||
| import Data.Monoid         (mappend) |  | ||||||
| import Hakyll | import Hakyll | ||||||
| import System.Directory |  | ||||||
| import System.FilePath |  | ||||||
| import System.Process | import System.Process | ||||||
| import Text.Pandoc.Options | import Text.Pandoc.Options | ||||||
| import Text.Printf |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| docDir = "../doc" |  | ||||||
| 
 |  | ||||||
| -- hakyll's preview doesn't detect changes in symlinked files |  | ||||||
| -- symlinkDocs = do |  | ||||||
| --   filter (".md" `isSuffixOf`) <$> getDirectoryContents docDir |  | ||||||
| --     >>= mapM_ (\f -> system $ printf "[ -f %s ] || ln -s %s/%s" f docDir f) |  | ||||||
| 
 |  | ||||||
| copyDocsIfNewer = do |  | ||||||
|   fs <- filter (".md" `isSuffixOf`) <$> getDirectoryContents docDir |  | ||||||
|   forM_ fs $ \f -> do |  | ||||||
|     let f1 = docDir </> f |  | ||||||
|         f2 = "."    </> f |  | ||||||
|     t1 <- getModificationTime f1 |  | ||||||
|     t2 <- getModificationTime f2 |  | ||||||
|     when (t1 > t2) $ copyFile f1 f2 |  | ||||||
| 
 |  | ||||||
| symlinkProfsDir = ensureSiteDir >> system "ln -sf ../../profs _site/profs" | symlinkProfsDir = ensureSiteDir >> system "ln -sf ../../profs _site/profs" | ||||||
|   where |   where | ||||||
|     ensureSiteDir = system "mkdir -p _site" |     ensureSiteDir = system "mkdir -p _site" | ||||||
| 
 | 
 | ||||||
| main = do | main = do | ||||||
|   copyDocsIfNewer |  | ||||||
|   symlinkProfsDir |   symlinkProfsDir | ||||||
|  | 
 | ||||||
|   hakyll $ do |   hakyll $ do | ||||||
| 
 | 
 | ||||||
|     match ("images/*" .||. "js/**" .||. "robots.txt") $ do |     match ("images/*" .||. "js/**" .||. "robots.txt") $ do | ||||||
| @ -49,14 +26,14 @@ main = do | |||||||
| 
 | 
 | ||||||
|     match "templates/*" $ compile templateCompiler |     match "templates/*" $ compile templateCompiler | ||||||
| 
 | 
 | ||||||
|     match ("README.md") $ do |     match ("doc/README.md") $ do | ||||||
|         route $ constRoute "index.html" |         route $ constRoute "index.html" | ||||||
|         compile $ |         compile $ | ||||||
|           pandocCompilerWith def def |           pandocCompilerWith def def | ||||||
|           >>= loadAndApplyTemplate "templates/frontpage.html" defaultContext |           >>= loadAndApplyTemplate "templates/frontpage.html" defaultContext | ||||||
|           >>= relativizeUrls |           >>= relativizeUrls | ||||||
| 
 | 
 | ||||||
|     match (("*.md" .&&. complement "README.md") .||. "0.22/*.md" .||. "0.21/*.md" .||. "0.20/*.md" .||. "0.19/*.md" .||. "0.18/*.md") $ do |     match (("doc/*.md" .&&. complement "doc/README.md") .||. "0.22/*.md" .||. "0.21/*.md" .||. "0.20/*.md" .||. "0.19/*.md" .||. "0.18/*.md") $ do | ||||||
|         route   $ setExtension "html" |         route   $ setExtension "html" | ||||||
|         compile $ |         compile $ | ||||||
|           pandocCompilerWith |           pandocCompilerWith | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user