Make sure links to haddocks are not generated for modules that have no haddock

This commit is contained in:
Alexey Kuleshevich 2019-07-11 14:07:42 +03:00
parent 5dbb09a256
commit 39d1e0c867
No known key found for this signature in database
GPG Key ID: E59B216127119E3E
3 changed files with 10 additions and 7 deletions

View File

@ -18,6 +18,7 @@ module Handler.Package
import Control.Lens import Control.Lens
import qualified RIO.Map as Map
import Data.Coerce import Data.Coerce
import qualified Data.Text as T import qualified Data.Text as T
import qualified Data.Text.Lazy as LT import qualified Data.Text.Lazy as LT
@ -121,8 +122,9 @@ handlePackage epi = do
SnapshotR (spiSnapName spi) $ f $ PNVNameVersion (spiPackageName spi) (spiVersion spi) SnapshotR (spiSnapName spi) $ f $ PNVNameVersion (spiPackageName spi) (spiVersion spi)
pname = either hciPackageName spiPackageName epi pname = either hciPackageName spiPackageName epi
enumerate = zip [0 :: Int ..] enumerate = zip [0 :: Int ..]
renderModules sppi = renderForest [] $ moduleForest $ coerce (sppiModuleNames sppi) renderModules sppi = renderForest [] $ moduleForest $ coerce $ Map.keys modNames
where where
modNames = sppiModuleNames sppi
SnapshotPackageInfo{spiPackageName, spiVersion, spiSnapName} = sppiSnapshotPackageInfo sppi SnapshotPackageInfo{spiPackageName, spiVersion, spiSnapName} = sppiSnapshotPackageInfo sppi
packageIdentifier = PackageIdentifierP spiPackageName spiVersion packageIdentifier = PackageIdentifierP spiPackageName spiVersion
renderForest _ [] = mempty renderForest _ [] = mempty
@ -135,7 +137,7 @@ handlePackage epi = do
renderTree Node {..} = renderTree Node {..} =
[hamlet| [hamlet|
<li> <li>
$if isModule $if isModule && hasDoc
<a href=@{haddockUrl spiSnapName mli}>#{modName} <a href=@{haddockUrl spiSnapName mli}>#{modName}
$else $else
#{modName} #{modName}
@ -145,6 +147,7 @@ handlePackage epi = do
mli = ModuleListingInfo modName packageIdentifier mli = ModuleListingInfo modName packageIdentifier
pathRev' = component : pathRev pathRev' = component : pathRev
modName = moduleNameFromComponents (reverse pathRev') modName = moduleNameFromComponents (reverse pathRev')
hasDoc = fromMaybe False $ Map.lookup modName modNames
maxDisplayedDeps :: Int maxDisplayedDeps :: Int
maxDisplayedDeps = 40 maxDisplayedDeps = 40

View File

@ -630,15 +630,15 @@ getFileByTreeEntryId teid =
where_ $ te ^. TreeEntryId ==. val teid where_ $ te ^. TreeEntryId ==. val teid
pure (fp ^. FilePathPath, b ^. BlobContents) pure (fp ^. FilePathPath, b ^. BlobContents)
getModuleNames :: SnapshotPackageId -> ReaderT SqlBackend (RIO env) [ModuleNameP] getModuleNames :: SnapshotPackageId -> ReaderT SqlBackend (RIO env) (Map ModuleNameP Bool)
getModuleNames spid = getModuleNames spid =
map unValue <$> Map.fromList . map (\(md, hs) -> (unValue md, unValue hs)) <$>
select select
(from $ \(spm `InnerJoin` pm) -> do (from $ \(spm `InnerJoin` pm) -> do
on (spm ^. SnapshotPackageModuleModule ==. pm ^. ModuleNameId) on (spm ^. SnapshotPackageModuleModule ==. pm ^. ModuleNameId)
where_ (spm ^. SnapshotPackageModuleSnapshotPackage ==. val spid) where_ (spm ^. SnapshotPackageModuleSnapshotPackage ==. val spid)
orderBy [desc (pm ^. ModuleNameName)] orderBy [desc (pm ^. ModuleNameName)]
pure (pm ^. ModuleNameName)) pure (pm ^. ModuleNameName, spm ^. SnapshotPackageModuleHasDocs))
------ Dependencies ------ Dependencies
@ -1000,7 +1000,7 @@ markModuleHasDocs ::
SnapshotId SnapshotId
-> PackageIdentifierP -> PackageIdentifierP
-> Maybe SnapshotPackageId -> Maybe SnapshotPackageId
-- ^ If we know ahead of time the SnapshotPackageId it will speed up a great deal if don't have -- ^ If we know ahead of time the SnapshotPackageId it will speed things up, since we don't have
-- to look it up in the database. -- to look it up in the database.
-> ModuleNameP -> ModuleNameP
-> ReaderT SqlBackend (RIO env) (Maybe SnapshotPackageId) -> ReaderT SqlBackend (RIO env) (Maybe SnapshotPackageId)

View File

@ -251,7 +251,7 @@ data SnapshotPackagePageInfo = SnapshotPackagePageInfo
, sppiReverseDepsCount :: !Int , sppiReverseDepsCount :: !Int
-- ^ Count of all packages in the snapshot that depends on this package -- ^ Count of all packages in the snapshot that depends on this package
, sppiLatestInfo :: ![LatestInfo] , sppiLatestInfo :: ![LatestInfo]
, sppiModuleNames :: ![ModuleNameP] , sppiModuleNames :: !(Map ModuleNameP Bool)
, sppiPantryCabal :: !(Maybe PantryCabal) , sppiPantryCabal :: !(Maybe PantryCabal)
, sppiVersion :: !(Maybe VersionRev) , sppiVersion :: !(Maybe VersionRev)
-- ^ Version on this page. Should be present only if different from latest -- ^ Version on this page. Should be present only if different from latest