Commits

Luke Plant  committed de4c0c3

Small refactor

  • Participants
  • Parent commits 3376bbf

Comments (0)

Files changed (3)

File src/Blog/Category.hs

 module Blog.Category where
 
 import Database.HDBC
-import Blog.DBUtils (makeSlugGeneric, slugFromTitle)
+import Blog.DBUtils (makeSlugGeneric)
 import qualified Blog.DB as DB
 
 data Category = Category { uid :: Int,
                        [[newid]] <- quickQuery cn "SELECT last_insert_rowid();" [];
                        return c2 { uid = fromSql $ newid }
 
-makeCategorySlug cn cat = makeSlugGeneric cn (slugFromTitle $ name cat) "categories" 1
+makeCategorySlug cn cat = makeSlugGeneric cn (name cat) "categories" 1

File src/Blog/DBUtils.hs

                       regexReplace (B.pack "-+$") (B.pack "") $
                       regexReplace (B.pack "[^A-Za-z0-9]+") (B.pack "-") (B.pack title)
 
-makeSlugGeneric cn slugBase table iter = do
+makeSlugGeneric cn title table iter = makeSlugGeneric' cn (slugFromTitle title) table iter
+makeSlugGeneric' cn slugBase table iter = do
   let slugAttempt =  (slugBase ++ makeSuffix iter);
   [[SqlString c]] <- quickQuery cn ("SELECT count(slug) FROM " ++ table ++ " WHERE slug = ?") [toSql slugAttempt];
   case c of
     "0" -> return slugAttempt
-    _   -> makeSlugGeneric cn slugBase table (iter + 1)
+    _   -> makeSlugGeneric' cn slugBase table (iter + 1)
 
  where
    makeSuffix 1 = ""

File src/Blog/Post.hs

 module Blog.Post where
 
 import Database.HDBC
-import Blog.DBUtils (makeSlugGeneric, slugFromTitle)
+import Blog.DBUtils (makeSlugGeneric)
 import qualified Blog.DB as DB
 
 data Post = Post {
                     return p2 { uid = fromSql $ newid } ;
                   }
 
-makePostSlug cn p = makeSlugGeneric cn (slugFromTitle $ title p) "posts" 1
+makePostSlug cn p = makeSlugGeneric cn (title p) "posts" 1
 
 addPostCategory cn pc = do { DB.doInsert cn "post_categories"
                              ["post_id",