View source: R/utils-sidebar.R
create_sidebar_item | R Documentation |
Varnish uses a sidebar for navigation across and within an episode. This funciton will create a sidebar item for a single episode, providing a dropdown menu of the sections within the episode if it is labeled as the current episode.
create_sidebar_item(nodes, link, position)
create_sidebar_headings(nodes)
nodes |
html nodes of a webpage generated from |
link |
a character vector of length 1 that defines the HTML links to be used as the node for the sidebar item. |
position |
either a number or "current", if "current", then the html is parsed for second level headings to list in the sidebar navigation. |
a character vector with a div item to insert into the sidebar navigation
snd <- asNamespace("sandpaper")
html <- c(
"<section id='one'><h2 class='section-heading'>Section 1</h2><p>section 1</p></section>",
"<section id='two'><h2 class='section-heading'>Section 2</h2><p>section 2</p></section>"
)
nodes <- xml2::read_html(paste(html, collapse = "\n"))
# The sidebar headings are extracted from the nodes
writeLines(snd$create_sidebar_headings(nodes))
link <- "<a href='https://example.com/this-page.html'><em>This Page</em></a>"
# the sidebar item will contain the headings if it is the current chapter
writeLines(snd$create_sidebar_item(nodes, link, position = "current"))
# it will be an ordinary link otherwise
writeLines(snd$create_sidebar_item(nodes, link, position = 3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.