diff --git a/Foundation.hs b/Foundation.hs index 152b426..d44a0b6 100644 --- a/Foundation.hs +++ b/Foundation.hs @@ -15,6 +15,7 @@ import Database.Persist.Sql (SqlPersistT) import Settings.StaticFiles import Settings (widgetFile, Extra (..)) import Model +import Data.Text import Text.Jasmine (minifym) import Text.Hamlet (hamletFile) import Yesod.Core.Types (Logger) diff --git a/Handler/Nomnichi.hs b/Handler/Nomnichi.hs index fe20d71..a49ad33 100644 --- a/Handler/Nomnichi.hs +++ b/Handler/Nomnichi.hs @@ -135,15 +135,16 @@ postCreateArticleR = do } articleId <- runDB $ insert article' setMessage $ toHtml (articleTitle article) <> " created." - redirect $ ArticleR articleId + redirect $ ArticleR $ articlePermaLink article _ -> defaultLayout $ do setTitle "Please correct your entry form." $(widgetFile "articleAddError") -- 記事表示 -getArticleR :: ArticleId -> Handler Html -getArticleR articleId = do +getArticleR :: Text -> Handler Html +getArticleR permalink = do creds <- maybeAuthId + Entity articleId _article <- runDB $ getBy404 $ UniquePermaLink permalink article <- runDB $ get404 articleId user <- runDB $ get (articleUser article) comments <- runDB $ selectList [CommentArticleId ==. articleId] [Asc CommentId] @@ -184,8 +185,9 @@ commentAuthorName (Entity _ comment) = do runDB $ get (commentUser comment) -- 記事更新 -postArticleR :: ArticleId -> Handler Html -postArticleR articleId = do +postArticleR :: Text -> Handler Html +postArticleR permalink = do + Entity articleId _article <- runDB $ getBy404 $ UniquePermaLink permalink beforeArticle <- runDB $ get404 articleId ((res, articleWidget), enctype) <- runFormPost (editForm (Just beforeArticle)) case res of @@ -202,14 +204,15 @@ postArticleR articleId = do , ArticlePromoteHeadline =. articlePromoteHeadline article ] setMessage $ toHtml $ (articleTitle article) <> " is updated." - redirect $ ArticleR articleId + redirect $ ArticleR $ articlePermaLink article _ -> defaultLayout $ do setTitle "Please correct your entry form." $(widgetFile "editArticleForm") -- 編集画面 -getEditArticleR :: ArticleId -> Handler Html -getEditArticleR articleId = do +getEditArticleR :: Text -> Handler Html +getEditArticleR permalink = do + Entity articleId _article <- runDB $ getBy404 $ UniquePermaLink permalink article <- runDB $ get404 articleId (articleWidget, enctype) <- generateFormPost $ editForm (Just article) defaultLayout $ do @@ -218,8 +221,9 @@ getEditArticleR articleId = do -- 記事削除 -postDeleteArticleR :: ArticleId -> Handler Html -postDeleteArticleR articleId = do +postDeleteArticleR :: Text -> Handler Html +postDeleteArticleR permalink = do + Entity articleId _article <- runDB $ getBy404 $ UniquePermaLink permalink runDB $ do delete articleId deleteWhere [ CommentArticleId ==. articleId ] @@ -232,17 +236,18 @@ postDeleteArticleR articleId = do -- コメント送信 -postCommentR :: ArticleId -> Handler Html -postCommentR articleId = do +postCommentR :: Text -> Handler Html +postCommentR permalink = do + Entity articleId _article <- runDB $ getBy404 $ UniquePermaLink permalink ((res, _), _) <- runFormPost $ commentForm articleId case res of FormSuccess comment -> do _ <- runDB $ insert comment setMessage "your comment was successfully posted." - redirect $ ArticleR articleId + redirect $ ArticleR permalink _ -> do setMessage "please fill up your comment form." - redirect $ ArticleR articleId + redirect $ ArticleR permalink -- 記事表示時の公開時刻の整形 formatToNomnichiTime :: Article -> String diff --git a/config/models b/config/models index e13ddc8..0670ebf 100644 --- a/config/models +++ b/config/models @@ -11,6 +11,7 @@ Article user UserId title Text permaLink Text + UniquePermaLink permaLink content Html createdOn UTCTime updatedOn UTCTime diff --git a/config/routes b/config/routes index c3c6ee1..33802a5 100644 --- a/config/routes +++ b/config/routes @@ -8,9 +8,9 @@ /lab/nom/nomnichi NomnichiR GET /lab/nom/nomnichi/create CreateArticleR GET POST -/lab/nom/nomnichi/#ArticleId/show ArticleR GET POST -/lab/nom/nomnichi/#ArticleId/edit EditArticleR GET -/lab/nom/nomnichi/#ArticleId/delete DeleteArticleR POST -/lab/nom/nomnichi/#ArticleId/comment CommentR POST +/lab/nom/nomnichi/#Text/show ArticleR GET POST +/lab/nom/nomnichi/#Text/edit EditArticleR GET +/lab/nom/nomnichi/#Text/delete DeleteArticleR POST +/lab/nom/nomnichi/#Text/comment CommentR POST /lab/nom/ourstatic/*Texts OurStaticR GET diff --git a/templates/articles.hamlet b/templates/articles.hamlet index e613503..9472910 100644 --- a/templates/articles.hamlet +++ b/templates/articles.hamlet @@ -7,7 +7,7 @@
  • - + #{articleTitle article} ^{lockedImg article}
    @@ -16,7 +16,7 @@
    #{takeHeadLine $ articleContent article} -
    ...
    (続きを読む) +
    ...(続きを読む)
    ^{linkToOtherPageNumber calcPageNumber} ^{displayLinksforLoginedMember creds} diff --git a/templates/authedArticle.hamlet b/templates/authedArticle.hamlet index cd6f278..7e9189e 100644 --- a/templates/authedArticle.hamlet +++ b/templates/authedArticle.hamlet @@ -8,13 +8,13 @@
  • TOPへ
  • - 編集 + 編集
  • -
    + 削除
    - + ^{commentWidget}
    diff --git a/templates/editArticleForm.hamlet b/templates/editArticleForm.hamlet index 286fbd7..991bcda 100644 --- a/templates/editArticleForm.hamlet +++ b/templates/editArticleForm.hamlet @@ -1,5 +1,5 @@
    - + ^{articleWidget}