Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read haddocks new meta.json and prepare for QuickNav (#614)
* Teach hackage to read haddocks new meta.json * Load QuickNav on package page * Doc upload: Check for valid meta.json (if present) * Compat with pre AMP * Use correct tarball path * Hide "Quick jump" menu item
- Loading branch information
Showing
6 changed files
with
119 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Distribution.Server.Util.DocMeta ( | ||
DocMeta(..) | ||
, loadTarDocMeta | ||
, parseDocMeta | ||
, packageDocMetaTarPath | ||
) where | ||
|
||
import Control.Monad (mzero) | ||
import Control.Monad.IO.Class | ||
import Data.Aeson | ||
import qualified Data.ByteString.Lazy | ||
import Data.TarIndex (TarIndex) | ||
import qualified Data.TarIndex as TarIndex | ||
import qualified Data.Text as Text | ||
import Distribution.Package | ||
import Distribution.Text (display, simpleParse) | ||
import Distribution.Version (Version) | ||
import System.FilePath ((</>)) | ||
|
||
import Distribution.Server.Util.ServeTarball (loadTarEntry) | ||
|
||
newtype JsonVersion = JV Version | ||
|
||
instance FromJSON JsonVersion where | ||
parseJSON = withText "Version" $ \s -> | ||
case simpleParse (Text.unpack s) of | ||
Just version -> return (JV version) | ||
Nothing -> mzero | ||
|
||
data DocMeta = DocMeta { | ||
docMetaHaddockVersion :: !Version | ||
} | ||
|
||
instance FromJSON DocMeta where | ||
parseJSON = withObject "DocMeta" $ \o -> do | ||
JV haddockVersion <- o .: "haddock_version" | ||
return DocMeta { docMetaHaddockVersion = haddockVersion } | ||
|
||
loadTarDocMeta :: MonadIO m => FilePath -> TarIndex -> PackageId -> m (Maybe DocMeta) | ||
loadTarDocMeta tarball docIndex pkgid = | ||
case TarIndex.lookup docIndex docMetaPath of | ||
Just (TarIndex.TarFileEntry docMetaEntryOff) -> do | ||
docMetaEntryContent <- liftIO (loadTarEntry tarball docMetaEntryOff) | ||
case docMetaEntryContent of | ||
Right (_, docMetaContent) -> | ||
return (parseDocMeta docMetaContent) | ||
Left _ -> return Nothing | ||
_ -> return Nothing | ||
where | ||
docMetaPath = packageDocMetaTarPath pkgid | ||
|
||
parseDocMeta :: Data.ByteString.Lazy.ByteString -> Maybe DocMeta | ||
parseDocMeta = decode | ||
|
||
packageDocMetaTarPath :: PackageId -> FilePath | ||
packageDocMetaTarPath pkgid = | ||
display pkgid ++ "-docs" </> "meta.json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters