Remove the slug column from entries - compute the slug from the entry name, if there is one, and have no slug otherwise

This commit is contained in:
Danielle McLean 2017-10-11 23:41:52 +11:00
parent fa992bc861
commit 1e7482b30f
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
3 changed files with 2 additions and 3 deletions

View file

@ -26,7 +26,6 @@ Profile
displayName Text Maybe sqltype=varchar(255)
Entry
slug Slug Maybe maxlen=255
kind EntryKind maxlen=255
name Text Maybe maxlen=255
content Text sqltype=longtext

View file

@ -12,7 +12,6 @@ module Model where
import ClassyPrelude.Yesod
import Database.Persist.Quasi
import Yesod.Auth.HashDB ( HashDBUser(..) )
import Web.Slug ( Slug )
import Text.Mustache ( (~>) )
import qualified Text.Mustache as M

View file

@ -10,6 +10,7 @@ import Database.Esqueleto ( (^.) )
import qualified Database.Esqueleto as E
import Data.Time.Format ( defaultTimeLocale, formatTime, iso8601DateFormat )
import Data.Time.Format.Human ( humanReadableTime )
import Web.Slug ( mkSlug )
data FormattedTime = FormattedTime
{ timeUnfriendly :: String
@ -22,7 +23,7 @@ toFormattedTime time = FormattedTime (unfriendly time) <$> friendly time
friendly = liftIO . humanReadableTime
entryR :: Entity Entry -> Route App
entryR (Entity entryId Entry {..}) = route entrySlug entryKind entryId
entryR (Entity entryId Entry {..}) = route (entryName >>= mkSlug) entryKind entryId
where route (Just s) = \k i -> EntryWithSlugR k i s
route Nothing = EntryR