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:
parent
fa992bc861
commit
1e7482b30f
3 changed files with 2 additions and 3 deletions
|
@ -26,7 +26,6 @@ Profile
|
||||||
displayName Text Maybe sqltype=varchar(255)
|
displayName Text Maybe sqltype=varchar(255)
|
||||||
|
|
||||||
Entry
|
Entry
|
||||||
slug Slug Maybe maxlen=255
|
|
||||||
kind EntryKind maxlen=255
|
kind EntryKind maxlen=255
|
||||||
name Text Maybe maxlen=255
|
name Text Maybe maxlen=255
|
||||||
content Text sqltype=longtext
|
content Text sqltype=longtext
|
||||||
|
|
|
@ -12,7 +12,6 @@ module Model where
|
||||||
import ClassyPrelude.Yesod
|
import ClassyPrelude.Yesod
|
||||||
import Database.Persist.Quasi
|
import Database.Persist.Quasi
|
||||||
import Yesod.Auth.HashDB ( HashDBUser(..) )
|
import Yesod.Auth.HashDB ( HashDBUser(..) )
|
||||||
import Web.Slug ( Slug )
|
|
||||||
import Text.Mustache ( (~>) )
|
import Text.Mustache ( (~>) )
|
||||||
import qualified Text.Mustache as M
|
import qualified Text.Mustache as M
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import Database.Esqueleto ( (^.) )
|
||||||
import qualified Database.Esqueleto as E
|
import qualified Database.Esqueleto as E
|
||||||
import Data.Time.Format ( defaultTimeLocale, formatTime, iso8601DateFormat )
|
import Data.Time.Format ( defaultTimeLocale, formatTime, iso8601DateFormat )
|
||||||
import Data.Time.Format.Human ( humanReadableTime )
|
import Data.Time.Format.Human ( humanReadableTime )
|
||||||
|
import Web.Slug ( mkSlug )
|
||||||
|
|
||||||
data FormattedTime = FormattedTime
|
data FormattedTime = FormattedTime
|
||||||
{ timeUnfriendly :: String
|
{ timeUnfriendly :: String
|
||||||
|
@ -22,7 +23,7 @@ toFormattedTime time = FormattedTime (unfriendly time) <$> friendly time
|
||||||
friendly = liftIO . humanReadableTime
|
friendly = liftIO . humanReadableTime
|
||||||
|
|
||||||
entryR :: Entity Entry -> Route App
|
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
|
where route (Just s) = \k i -> EntryWithSlugR k i s
|
||||||
route Nothing = EntryR
|
route Nothing = EntryR
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue