From bdbc55f450cc768c08528c59aaa7973addf0b2a8 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Sun, 10 Jan 2016 20:32:11 +0100 Subject: [PATCH] linkify git URLs, minor fixes on the main page --- Handler/Home.hs | 2 ++ Handler/Shared.hs | 8 ++++++++ Handler/ShowChallenge.hs | 11 +++++++++++ templates/homepage.hamlet | 8 +++++--- templates/show-challenge.hamlet | 8 ++++---- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Handler/Home.hs b/Handler/Home.hs index 32724a5..eddfbbd 100644 --- a/Handler/Home.hs +++ b/Handler/Home.hs @@ -4,6 +4,8 @@ import Import import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3, withSmallInput) +import Handler.Shared + -- This is a handler function for the GET request method on the HomeR -- resource pattern. All of your resource patterns are defined in -- config/routes diff --git a/Handler/Shared.hs b/Handler/Shared.hs index 4e9af57..6a7c416 100644 --- a/Handler/Shared.hs +++ b/Handler/Shared.hs @@ -39,6 +39,14 @@ arena = do gitPath :: FilePath gitPath = "/usr/bin/git" +browsableGitSite :: Text +browsableGitSite = "http://gonito.net/gitlist/" + +browsableGitRepo :: Text -> Text +browsableGitRepo bareRepoName + | ".git" `isSuffixOf` bareRepoName = browsableGitSite ++ bareRepoName + | otherwise = browsableGitSite ++ bareRepoName ++ ".git" + runViewProgress :: (Channel -> Handler ()) -> Handler TypedContent runViewProgress action = do App {..} <- getYesod diff --git a/Handler/ShowChallenge.hs b/Handler/ShowChallenge.hs index f41ec8d..816dafb 100644 --- a/Handler/ShowChallenge.hs +++ b/Handler/ShowChallenge.hs @@ -47,6 +47,17 @@ getChallengeReadmeR name = do showChallengeWidget challenge repo leaderboard = $(widgetFile "show-challenge") where leaderboardWithRanks = zip [1..] leaderboard + maybeRepoLink = getRepoLink repo + + +getRepoLink :: Repo -> Maybe Text +getRepoLink repo + | sitePrefix `isPrefixOf` url = Just $ (browsableGitRepo bareRepoName) ++ "/" ++ (repoBranch repo) + | otherwise = Nothing + where sitePrefix = "git://gonito.net/" :: Text + sitePrefixLen = length sitePrefix + url = repoUrl repo + bareRepoName = drop sitePrefixLen url getChallengeHowToR :: Text -> Handler Html getChallengeHowToR name = do diff --git a/templates/homepage.hamlet b/templates/homepage.hamlet index b3052c3..d2cd5bd 100644 --- a/templates/homepage.hamlet +++ b/templates/homepage.hamlet @@ -1,12 +1,12 @@

Welcome to Gonito.net! -

Gonito (pronounced ɡɔ̃ˈɲitɔ) is a Kaggle-like platform for machine learning competitions (disclaimer: Gonito is neither affiliated with nor endorsed by Kaggle) +

Gonito (pronounced ɡɔ̃ˈɲitɔ) is a Kaggle*-like platform for machine learning competitions.

What's so special about Gonito: