<commit_before>{-# LANGUAGE GADTs #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}

-- | GetStarted page controller.

module HL.Controller.Packages
    ( getPackagesR
    , getPackageR
    ) where

import qualified Data.Vector as V
import           HL.Controller
import           HL.View
import           HL.View.Package
import           HL.View.Packages

-- | Packages controller.
getPackagesR :: C (Html ())
getPackagesR =
  do info <- fmap appPackageInfo getYesod
     lucid (packagesV info)

-- | Package controller.
getPackageR :: PackageName -> C (Html ())
getPackageR name =
  do info <- fmap appPackageInfo getYesod
     case V.find ((== name) . packageName)
                 (piFundamentals info) of
       Nothing ->
         case V.find ((== name) . packageName)
                     (V.concatMap commonChoices
                                  (piCommons info)) of
           Nothing -> redirect PackagesR
           Just package -> handlePackage package
       Just package -> handlePackage package
  where handlePackage package =
          case packagePage package of
            Nothing -> redirect PackagesR
            Just md -> lucid (packageV name md)<commit_msg>Redirect to Stackage page for undocumented packages<commit_after>{-# LANGUAGE GADTs #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}

-- | GetStarted page controller.

module HL.Controller.Packages
    ( getPackagesR
    , getPackageR
    ) where

import           Data.Monoid ((<>))
import qualified Data.Vector as V
import           HL.Controller
import           HL.View
import           HL.View.Package
import           HL.View.Packages

-- | Packages controller.
getPackagesR :: C (Html ())
getPackagesR =
  do info <- fmap appPackageInfo getYesod
     lucid (packagesV info)

-- | Package controller.
getPackageR :: PackageName -> C (Html ())
getPackageR name =
  do info <- fmap appPackageInfo getYesod
     case V.find ((== name) . packageName)
                 (piFundamentals info) of
       Nothing ->
         case V.find ((== name) . packageName)
                     (V.concatMap commonChoices
                                  (piCommons info)) of
           Nothing -> onNotFound
           Just package -> handlePackage package
       Just package -> handlePackage package
  where handlePackage package =
          case packagePage package of
            Nothing -> onNotFound
            Just md -> lucid (packageV name md)

        onNotFound = redirect $ "https://www.stackage.org/package/" <> toPathPiece name
{'fraction_non_alphanumeric': 0.08980866848887153, 'fraction_numerical': 0.0, 'mean_word_length': 2.0867469879518072, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1855786', 'n_tokens_mistral': 725, 'n_tokens_neox': 693, 'n_words': 208}