Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
fairify
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
UMR G-EAU
fairify
Commits
e3477f75
Commit
e3477f75
authored
1 year ago
by
David Dorchies
Browse files
Options
Downloads
Patches
Plain Diff
feat(pkgdown): report list in navbar
Refs
#22
parent
8c4dc2ca
No related branches found
No related tags found
1 merge request
!3
Resolve "Add a menu with the list of reports in pkgdown"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
R/build_site.R
+42
-0
42 additions, 0 deletions
R/build_site.R
man/build_site.Rd
+4
-0
4 additions, 0 deletions
man/build_site.Rd
tests/testthat/test-build_site.R
+3
-0
3 additions, 0 deletions
tests/testthat/test-build_site.R
with
49 additions
and
0 deletions
R/build_site.R
+
42
−
0
View file @
e3477f75
...
...
@@ -10,6 +10,8 @@
#'
#' @inheritParams pkgdown::build_site
#' @inheritParams render_reports
#' @param navbar_reports Add the report list in the navbar of the pkgdown
#' website
#' @param ... Further parameters to pass to [render_reports]
#'
#' @return Used for side effects
...
...
@@ -26,11 +28,15 @@ build_site <- function(pkg = pkgload::pkg_path(),
new_process
=
!
devel
,
install
=
!
devel
,
reports_dir
=
file.path
(
pkg
,
"reports"
),
navbar_reports
=
TRUE
,
...
)
{
if
(
file.exists
(
file.path
(
pkg
,
"README.Rmd"
)))
{
devtools
::
build_readme
(
path
=
pkg
)
}
unlink
(
file.path
(
pkg
,
"public"
),
recursive
=
TRUE
)
if
(
navbar_reports
)
{
add_reports_pkgdown
(
pkg
,
reports_dir
)
}
pkgdown
::
build_site
(
pkg
=
pkg
,
examples
=
examples
,
run_dont_run
=
run_dont_run
,
...
...
@@ -44,3 +50,39 @@ build_site <- function(pkg = pkgload::pkg_path(),
render_reports
(
reports_dir
=
reports_dir
,
...
)
invisible
(
TRUE
)
}
add_reports_pkgdown
<-
function
(
pkg
,
reports_dir
)
{
f
<-
file.path
(
pkg
,
"_pkgdown.yml"
)
if
(
!
file.exists
(
f
))
{
warning
(
"File not found: "
,
f
,
"\nReport list won't be visible in the website navigation bar"
)
invisible
()
}
cpd
<-
yaml
::
read_yaml
(
f
)
cpd
$
navbar
<-
add_ifnull
(
cpd
,
"navbar"
)
cpd
$
navbar
$
structure
<-
add_ifnull
(
cpd
$
navbar
,
"structure"
)
cpd
$
navbar
$
structure
$
left
<-
add_ifnull
(
cpd
$
navbar
$
structure
,
"left"
,
c
(
"intro"
,
"reference"
,
"articles"
,
"tutorials"
,
"news"
)
)
if
(
!
"reports"
%in%
cpd
$
navbar
$
structure
$
left
)
{
cpd
$
navbar
$
structure
$
left
<-
c
(
"reports"
,
cpd
$
navbar
$
structure
$
left
)
}
cpd
$
navbar
$
components
<-
add_ifnull
(
cpd
$
navbar
,
"components"
)
cpd
$
navbar
$
components
$
reports
<-
list
(
text
=
"Reports"
)
dfr
<-
list_reports
(
reports_dir
)
pkg
<-
gsub
(
"/$"
,
""
,
pkg
)
lr
<-
apply
(
dfr
,
1
,
function
(
r
)
{
list
(
text
=
r
[
"title"
],
href
=
file.path
(
sub
(
paste0
(
pkg
,
"/"
),
""
,
r
[
"path"
],
fixed
=
TRUE
),
"index.html"
))
})
names
(
lr
)
<-
NULL
cpd
$
navbar
$
components
$
reports
$
menu
<-
lr
yaml
::
write_yaml
(
cpd
,
f
)
}
add_ifnull
<-
function
(
l
,
i
,
v
=
list
())
{
if
(
is.null
(
l
[[
i
]]))
l
[[
i
]]
<-
v
return
(
l
[[
i
]])
}
This diff is collapsed.
Click to expand it.
man/build_site.Rd
+
4
−
0
View file @
e3477f75
...
...
@@ -16,6 +16,7 @@ build_site(
new_process = !devel,
install = !devel,
reports_dir = file.path(pkg, "reports"),
navbar_reports = TRUE,
...
)
}
...
...
@@ -61,6 +62,9 @@ so it is available for vignettes.}
\item{reports_dir}{\link{character} path for the reports}
\item{navbar_reports}{Add the report list in the navbar of the pkgdown
website}
\item{...}{Further parameters to pass to \link{render_reports}}
}
\value{
...
...
This diff is collapsed.
Click to expand it.
tests/testthat/test-build_site.R
+
3
−
0
View file @
e3477f75
...
...
@@ -8,5 +8,8 @@ test_that("build_site works", {
report_path
<-
file.path
(
path
,
"public/reports/my_report"
)
expect_true
(
dir.exists
(
report_path
))
expect_true
(
file.exists
(
file.path
(
report_path
,
"index.html"
)))
y
<-
yaml
::
read_yaml
(
file.path
(
path
,
"_pkgdown.yml"
))
expect_equal
(
y
$
navbar
$
components
$
reports
$
menu
[[
1
]]
$
href
,
"reports/my_report/index.html"
)
unlink
(
path
,
recursive
=
TRUE
)
})
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment