From 1e7482b30fb405dd110c08c437acb94ddddd5909 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Wed, 11 Oct 2017 23:41:52 +1100 Subject: [PATCH] Remove the slug column from entries - compute the slug from the entry name, if there is one, and have no slug otherwise --- config/models | 1 - src/Model.hs | 1 - src/Widget/Entry.hs | 3 ++- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/config/models b/config/models index 786b9cc..17a4302 100644 --- a/config/models +++ b/config/models @@ -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 diff --git a/src/Model.hs b/src/Model.hs index b587826..98d0306 100644 --- a/src/Model.hs +++ b/src/Model.hs @@ -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 diff --git a/src/Widget/Entry.hs b/src/Widget/Entry.hs index d73ad9e..4743ee3 100644 --- a/src/Widget/Entry.hs +++ b/src/Widget/Entry.hs @@ -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