Luke Plant avatar Luke Plant committed de4c0c3

Small refactor

Comments (0)

Files changed (3)

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

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 = ""
 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",
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.