Commits

Luke Plant  committed 8d5b3db

Began implementation of redirect file

  • Participants
  • Parent commits f6b08f2

Comments (0)

Files changed (4)

 \.o$
 ~$
 \#$
+^src/blog.php$

File src/Migrate.hs

 import qualified Data.ByteString.Char8 as B
+import qualified Data.ByteString.Lazy.UTF8 as UTF8
+import qualified Data.ByteString.Lazy as BL
 import qualified Category as C
 import qualified Post as P
 import qualified Settings
 import Data.Ord (comparing)
 import GHC.Unicode (toLower)
 import Monad (liftM)
+import Text.Template (readTemplate, renderToFile)
 import Utils (regexReplace)
 -- Migration script for the old data
 
                               toSql $ snd pc];
                              return pc; }
 
+createRedirectFile postUrlMap categoryUrlMap = do
+    tpl <- readTemplate Settings.redirect_file_template
+    let ctx = Map.fromList ([(UTF8.fromString "postIdsToUrls", UTF8.fromString "test1"),
+                             (UTF8.fromString "categoryIdsToUrls", UTF8.fromString "test2")])
+    renderToFile Settings.redirect_file_output tpl ctx
+
 main = handleSqlError $ do
   cn <- DB.connect
   cats <- readCategories
   let postCategories = correctIds postCategories' id_map
   writeItems cn addPostCategory postCategories
 
-  -- TODO: derive a blog.php script that contains the new mappings
-  -- for posts and categories and will do redirects to the new URLs
+  createRedirectFile () ()
   commit cn
   return ()
 

File src/blog.php.tpl

+<?php
+  // DO NOT EDIT THE FILE blog.php DIRECTLY!
+
+  // PHP file that does redirects to the new URLs.  This could be
+  // implemented using a .htaccess redirect rule and a Haskell CGI
+  // script that parsed and rewrote the URLs.  However, that script
+  // would still need access to the mapping between old ids (not
+  // stored in the new database) and the new URLs/ids.  So it is
+  // simpler to do it in a single PHP file.
+
+  // The file blog.php is produced from the blog.php.tpl file.  The
+  // template language uses dollar substitutions, and dollar signs
+  // must be escaped by doubling.
+
+$$postMap = array($postIdsToUrls);
+
+$$catMap = array($categoryIdsToUrls);
+
+
+?>

File src/settingslocal.hs

 
 sqlite_path = "/home/luke/httpd/lukeplant.me.uk/web/cgi-bin/data/test1.db"
 
+
+
+-- Migration time settings:
+
 old_data_path = "/home/luke/httpd/lukeplant.me.uk/web/blog/data/"
+redirect_file_template = "/home/luke/devel/haskell/haskellblog/src/blog.php.tpl"
+redirect_file_output = "/home/luke/devel/haskell/haskellblog/src/blog.php"