Commits

Luke Plant  committed cc49a54

Added redirect file for feeds

  • Participants
  • Parent commits 7a2bb47

Comments (0)

Files changed (3)

File src/Blog/settingslocal.hs

 old_data_path = "/home/luke/httpd/lukeplant.me.uk/web/blog/data/"
 redirect_file_template = "/home/luke/devel/haskell/blog/src/blog.php.tpl"
 redirect_file_output = "/home/luke/devel/haskell/blog/src/blog.php"
+syndication_redirect_file_template = "/home/luke/devel/haskell/blog/src/syndicate.php.tpl"
+syndication_redirect_file_output = "/home/luke/devel/haskell/blog/src/syndicate.php"

File src/Migrate.hs

                            ,(utf8 "categoryIdsToUrls", utf8 $ makePHPMap categoryUrlMap)]
     renderToFile Settings.redirect_file_output tpl ctx
 
+createSyndicationRedirectFile categoryFeedUrlMap = do
+    tpl <- readTemplate Settings.syndication_redirect_file_template
+    let ctx = Map.fromList [(utf8 "categoryIdsToUrls", utf8 $ makePHPMap categoryFeedUrlMap)]
+    renderToFile Settings.syndication_redirect_file_output tpl ctx
+
 -- Misc fixes
 -- Titles of all posts in category 'articles' have HTML in them, which is difficult to fix
 -- up.  They are only announcements, so we just delete.
                                       (map Links.postUrl newPosts)
   let categoryUrlMap = Map.fromList $ zip (map (show . C.uid) origCats)
                                           (map Links.categoryUrl newCats)
+  let categoryFeedUrlMap = Map.fromList $ zip (map (show . C.uid) origCats)
+                                              (map Links.categoryPostsFeedUrl newCats)
   createRedirectFile postUrlMap categoryUrlMap
+  createSyndicationRedirectFile categoryFeedUrlMap
 
   createUser cn "luke" True
   setPassword cn "luke" "test"

File src/syndicate.php.tpl

+<?php
+  // DO NOT EDIT THE FILE syndicate.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 syndicate.php is produced from the syndicate.php.tpl file.  The
+  // template language uses dollar substitutions, and dollar signs
+  // must be escaped by doubling.
+
+define('FEED_SELECTALL',1);
+define('FEED_SELECTCATEGORIES',2);
+define('FEED_SELECTEXCEPT',3);
+
+define('FEED_FULLSTORY',1);
+define('FEED_SHORTSTORY', 2);
+
+$$catMap = ${categoryIdsToUrls};
+
+@$$method = $$_GET['m']; // method of selection
+
+@$$categories = $$_GET['c'];
+$$categories = preg_replace("/[^\d,]/",'', $$categories);
+$$categories = explode(',', $$categories);
+if (count($$categories) > 1) {
+    // don't support that any more
+    header ('HTTP/1.1 404 Not Found');
+    exit();
+}
+
+if ($$method == FEED_SELECTEXCEPT) {
+    // don't support that any more
+    header ('HTTP/1.1 404 Not Found');
+    exit();
+}
+
+if ($$method == FEED_SELECTCATEGORIES) {
+    header ('HTTP/1.1 301 Moved Permanently');
+    header('Location: ' . $$catMap[$$categories[0]]);
+    exit();
+}
+
+// default - FEED_SELECTALL
+
+header ('HTTP/1.1 301 Moved Permanently');
+header ('Location: /blog/atom/');
+exit();
+
+?>