Skip to content

Commit 0a2ffe8

Browse files
authored
Add "Quick Jump" to candidate package page (#1122)
This allows the testing of quick jump for a candidate.
1 parent 4d0bd17 commit 0a2ffe8

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

datafiles/templates/Html/candidate-page.html.st

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
22
<html xmlns="http://www.w3.org/1999/xhtml">
33
<head>
4+
$if(doc.hasQuickNavV1)$
5+
<link href="$doc.baseUrl$/quick-jump.css" rel="stylesheet" type="text/css" title="QuickJump" />
6+
$endif$
47
$hackageCssTheme()$
58
<title>
69
$package.name$$if(package.optional.hasSynopsis)$: $package.optional.synopsis$$endif$
@@ -152,5 +155,10 @@
152155
$package.optional.readme$
153156
$endif$
154157

158+
$if(doc.hasQuickNavV1)$
159+
<script src="$doc.baseUrl$/quick-jump.min.js" type="text/javascript"></script>
160+
<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>
161+
$endif$
162+
155163
</body>
156164
</html>

src/Distribution/Server/Features/Html.hs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ htmlFeature env@ServerEnv{..}
293293
htmlDocUploads = mkHtmlDocUploads utilities core docsCore templates
294294
htmlDownloads = mkHtmlDownloads utilities download
295295
htmlReports = mkHtmlReports utilities core upload user reportsCore templates
296-
htmlCandidates = mkHtmlCandidates utilities core versions upload
296+
htmlCandidates = mkHtmlCandidates env utilities core versions upload
297297
docsCandidates tarIndexCache
298298
candidates user templates
299299
htmlPreferred = mkHtmlPreferred utilities core versions
@@ -1081,7 +1081,8 @@ data HtmlCandidates = HtmlCandidates {
10811081
htmlCandidatesResources :: [Resource]
10821082
}
10831083

1084-
mkHtmlCandidates :: HtmlUtilities
1084+
mkHtmlCandidates :: ServerEnv
1085+
-> HtmlUtilities
10851086
-> CoreFeature
10861087
-> VersionsFeature
10871088
-> UploadFeature
@@ -1091,7 +1092,7 @@ mkHtmlCandidates :: HtmlUtilities
10911092
-> UserFeature
10921093
-> Templates
10931094
-> HtmlCandidates
1094-
mkHtmlCandidates utilities@HtmlUtilities{..}
1095+
mkHtmlCandidates ServerEnv{..} utilities@HtmlUtilities{..}
10951096
CoreFeature{ coreResource = CoreResource{packageInPath}
10961097
, queryGetPackageIndex
10971098
}
@@ -1250,9 +1251,20 @@ mkHtmlCandidates utilities@HtmlUtilities{..}
12501251
mdocIndex <- maybe (return Nothing)
12511252
(liftM Just . liftIO . cachedTarIndex)
12521253
mdoctarblob
1253-
let docURL = packageDocsContentUri docs (packageId cand)
12541254

12551255
mreadme <- makeReadme render
1256+
let loadDocMeta
1257+
| Just doctarblob <- mdoctarblob
1258+
, Just docIndex <- mdocIndex
1259+
= loadTarDocMeta
1260+
(BlobStorage.filepath serverBlobStore doctarblob)
1261+
docIndex
1262+
(packageId cand)
1263+
| otherwise
1264+
= return Nothing
1265+
mdocMeta <- loadDocMeta
1266+
1267+
let docURL = packageDocsContentUri docs (packageId cand)
12561268

12571269
-- also utilize hasIndexedPackage :: Bool
12581270
let warningBox = case renderWarnings candRender of
@@ -1270,7 +1282,7 @@ mkHtmlCandidates utilities@HtmlUtilities{..}
12701282
, "maintainers" $= listGroupCompact (map (Users.userIdToName userDb) (Group.toList maintainerlist))
12711283
] ++
12721284
PagesNew.packagePageTemplate render
1273-
mdocIndex Nothing mreadme
1285+
mdocIndex mdocMeta mreadme
12741286
docURL Nothing [] Nothing
12751287
utilities
12761288
True

src/Distribution/Server/Pages/PackageFromTemplate.hs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ packagePageTemplate render
9797
, "doc" $= docFieldsTemplate
9898
] ++
9999
-- Miscellaneous things that could still stand to be refactored a bit.
100-
[ "moduleList" $= Old.moduleSection render mdocIndex docURL mPkgId False
100+
[ "moduleList" $= Old.moduleSection render mdocIndex docURL mPkgId hasQuickNav
101101
, "downloadSection" $= Old.downloadSection render
102102
]
103103
else
@@ -173,11 +173,8 @@ packagePageTemplate render
173173
]
174174

175175
docFieldsTemplate =
176-
if isCandidate
177-
then templateDict [ templateVal "baseUrl" docURL ]
178-
else templateDict [ templateVal "hasQuickNavV1" hasQuickNavV1
179-
, templateVal "baseUrl" docURL
180-
]
176+
templateDict [ templateVal "hasQuickNavV1" hasQuickNavV1
177+
, templateVal "baseUrl" docURL ]
181178

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

0 commit comments

Comments
 (0)