Skip to content

Add "Quick Jump" to candidate package page #1122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions datafiles/templates/Html/candidate-page.html.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
$if(doc.hasQuickNavV1)$
<link href="$doc.baseUrl$/quick-jump.css" rel="stylesheet" type="text/css" title="QuickJump" />
$endif$
$hackageCssTheme()$
<title>
$package.name$$if(package.optional.hasSynopsis)$: $package.optional.synopsis$$endif$
Expand Down Expand Up @@ -152,5 +155,10 @@
$package.optional.readme$
$endif$

$if(doc.hasQuickNavV1)$
<script src="$doc.baseUrl$/quick-jump.min.js" type="text/javascript"></script>
<script type="text/javascript"> quickNav.init("$doc.baseUrl$", function(toggle) {var t = document.getElementById('quickjump-trigger');if (t) {t.onclick = function(e) { e.preventDefault(); toggle(); };}}); </script>
$endif$

</body>
</html>
22 changes: 17 additions & 5 deletions src/Distribution/Server/Features/Html.hs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ htmlFeature env@ServerEnv{..}
htmlDocUploads = mkHtmlDocUploads utilities core docsCore templates
htmlDownloads = mkHtmlDownloads utilities download
htmlReports = mkHtmlReports utilities core upload user reportsCore templates
htmlCandidates = mkHtmlCandidates utilities core versions upload
htmlCandidates = mkHtmlCandidates env utilities core versions upload
docsCandidates tarIndexCache
candidates user templates
htmlPreferred = mkHtmlPreferred utilities core versions
Expand Down Expand Up @@ -1108,7 +1108,8 @@ data HtmlCandidates = HtmlCandidates {
htmlCandidatesResources :: [Resource]
}

mkHtmlCandidates :: HtmlUtilities
mkHtmlCandidates :: ServerEnv
-> HtmlUtilities
-> CoreFeature
-> VersionsFeature
-> UploadFeature
Expand All @@ -1118,7 +1119,7 @@ mkHtmlCandidates :: HtmlUtilities
-> UserFeature
-> Templates
-> HtmlCandidates
mkHtmlCandidates utilities@HtmlUtilities{..}
mkHtmlCandidates ServerEnv{..} utilities@HtmlUtilities{..}
CoreFeature{ coreResource = CoreResource{packageInPath}
, queryGetPackageIndex
}
Expand Down Expand Up @@ -1277,9 +1278,20 @@ mkHtmlCandidates utilities@HtmlUtilities{..}
mdocIndex <- maybe (return Nothing)
(liftM Just . liftIO . cachedTarIndex)
mdoctarblob
let docURL = packageDocsContentUri docs (packageId cand)

mreadme <- makeReadme render
let loadDocMeta
| Just doctarblob <- mdoctarblob
, Just docIndex <- mdocIndex
= loadTarDocMeta
(BlobStorage.filepath serverBlobStore doctarblob)
docIndex
(packageId cand)
| otherwise
= return Nothing
mdocMeta <- loadDocMeta

let docURL = packageDocsContentUri docs (packageId cand)

-- also utilize hasIndexedPackage :: Bool
let warningBox = case renderWarnings candRender of
Expand All @@ -1297,7 +1309,7 @@ mkHtmlCandidates utilities@HtmlUtilities{..}
, "maintainers" $= listGroupCompact (map (Users.userIdToName userDb) (Group.toList maintainerlist))
] ++
PagesNew.packagePageTemplate render
mdocIndex Nothing mreadme
mdocIndex mdocMeta mreadme
docURL Nothing [] Nothing
utilities
True
Expand Down
9 changes: 3 additions & 6 deletions src/Distribution/Server/Pages/PackageFromTemplate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ packagePageTemplate render
, "doc" $= docFieldsTemplate
] ++
-- Miscellaneous things that could still stand to be refactored a bit.
[ "moduleList" $= Old.moduleSection render mdocIndex docURL mPkgId False
[ "moduleList" $= Old.moduleSection render mdocIndex docURL mPkgId hasQuickNav
, "downloadSection" $= Old.downloadSection render
]
else
Expand Down Expand Up @@ -173,11 +173,8 @@ packagePageTemplate render
]

docFieldsTemplate =
if isCandidate
then templateDict [ templateVal "baseUrl" docURL ]
else templateDict [ templateVal "hasQuickNavV1" hasQuickNavV1
, templateVal "baseUrl" docURL
]
templateDict [ templateVal "hasQuickNavV1" hasQuickNavV1
, templateVal "baseUrl" docURL ]

-- Fields that may be empty, along with booleans to see if they're present.
-- Access via "$package.optional.varname$"
Expand Down