How to associate a featured image with an rmd post? - r

I'm using the (wonderful) academic hugo theme to create a website. It comes with some example posts, and each of these show up in the post list accompanied by a thumbnail image. These posts are all .md files and include the following in their front matter:
# Featured image
# To use, add an image named `featured.jpg/png` to your page's folder.
# Placement options: 1 = Full column width, 2 = Out-set, 3 = Screen-width
# Focal point options: Smart, Center, TopLeft, Top, TopRight, Left, Right, BottomLeft, Bottom, BottomRight
image:
placement: 2
caption: 'Image credit: [**Unsplash**](https://unsplash.com/photos/CpkOjOcXdUY)'
focal_point: ""
preview_only: false
I have followed the instructions and have a "featured.png" in my page's folder. My Rmd's yaml header looks like so:
---
title: "my title"
author: "Kyle Ward"
date: 2019-08-28
categories: ["R"]
tags: ["R Markdown", "packages"]
image:
placement: 2
caption: ""
focal_point: ""
preview_only: false
projects: ["my-project"]
---
The image thumbnail doesn't show up like all the other .md example posts. The other yaml tags work. For instance, my post is associated with "my-project", it has the right author info, etc. What am I doing wrong?
Thanks for your help!

Normally, you will also need to add the thumbnail option to your .md file header, in your case:
---
title: "my title"
thumbnail: "page_folder/featured.jpg"
... other params ...
---

Related

Add a submenu to a distill rmarkdown website?

I am creating a distill website using rmarkdown and would like to add a submenu in the navigation bar. I found this feature request/issue on GitHub but have not been able to find a solution.
With the below _site.yml and index.Rmd the submenu text appears in the menu dropdown but is greyed-out and not clickable/selectable.
_site.yml:
name: "submenuTest"
title: "Submenu test"
description: |
Submenu test
output_dir: "_site"
navbar:
right:
- text: "Home"
href: index.html
- text: 'Menu'
menu:
- text: 'Page'
href: page.html
- text: 'Submenu'
menu:
- text: 'Sub Page'
href: subpage.html
output: distill::distill_article
index.Rmd:
---
title: "Submenu test"
description: |
Welcome to the website. I hope you enjoy it!
site: distill::distill_website
---
# here is my page content
In a plain rmarkdown .html (can use the above .yml and .Rmd examples but without the output: distill::distill_article and site: distill::distill_website lines) renders with a workable submenu.

How to make Rmarkdown website using one .rmd file as template for multiple pages instead of one .rmd for each page?

I find rmarkdown sites interesting, but I would like to change from most example I have seen and I haven't found something yet.
I try to make a repoducible example:
folder struture:
project_folder
\_ _site.yml
\_ index.rmd
\_ script.R
\_ templates
\_pages.rmd
I yml file alows to make the structure: I would like to have a website with the following categories (this an example of my _site.yml):
name: "website"
navbar:
title: "website"
left:
- text: "global info"
href: index.html
- text: "species"
menu:
- text: "all species result"
href: all.html
- text: "---------"
- text: "versicolor"
href: versicolor_1.html
- text: "setosa"
href: setosa.html
then an index.rmd (here just a title in order to keep the example simple).
---
title: Some stuff
---
a template page like page.rmd in a template folder (very simple as well but it uses a parameter.
---
params:
data_set:
title: "Region results"
---
hist(param$dataset$Sepal.Length)
and a "script" like, to render the site and then all pages except index.
markdown::render_site()
# import data
species = c("versicolor", "setosa")
# filter data and render page
for (i in 1:nrow(species)){
data_filtered <- dplyr::filter(iris, species == species[i])
rmarkdown::render("templates/page.rmd.Rmd", params = list(
data_set = data_filtered,
output_file = paste0("../_site/", pages$species[i], ".html"))
}
Right now, I don't get the header on top of my html as I am not using the common structure....
I could also use another option (R based) if you have ideas. shiny isn't the best option.
Thank you!

./ Relative URL in header leads to 404 when clicking from any non-home link

I am using R 4.1.1, blogdown 1.4, and Hugo 0.81. I ran blogdown::check_site() and fixed all issues.
Hello. I have uploaded a PDF file Resume.pdf to my root directory in blogdown. In my YAML file, I have tried put this file in my header using this code:
menu:
main:
- name: Resume
url: "./Resume.pdf"
weight: 1
When I serve my website, if I click on "Resume" in my header from my home directory, the link works fine and I am served my PDF. However, if I click on "Resume" from anywhere else on the website, I am led to a 404.
I have currently gotten around this issue by using an absolute URL. However it would be nice to have a relative URL for efficiency purposes.
Does anyone know why ./Resume.pdf does not work in my YAML file?
Here is my full YAML file, with redacted parts replaced with ---
baseurl: ---
languageCode: en-us
title: Farzad Saif’s Website
theme: hugo-lithium
googleAnalytics: '---'
disqusShortname: ''
ignoreFiles:
- \.Rmd$
- \.Rmarkdown$
- _cache$
- \.knit\.md$
- \.utf8\.md$
permalinks:
post: /:year/:month/:day/:slug/
menu:
main:
- name: About
url: /about/
weight: 1
- name: Papers
url: /papers/
weight: 2
- name: GitHub
url: ---
weight: 3
- name: LinkedIn
url: ---
weight: 4
- name: Resume
url: "./Resume.pdf"
weight: 5
params:
MathJaxCDN: //cdnjs.cloudflare.com/ajax/libs
MathJaxVersion: 3.2.0
description: Hello, I am Farzad Saif. Welcome to my website!
favicon: favicon.ico
highlightjsCDN: //cdnjs.cloudflare.com/ajax/libs
highlightjsLang:
- r
- yaml
highlightjsTheme: github
highlightjsVersion: 9.12.0
logo:
alt: Logo
height: 50
url: logo.png
width: 50
markup:
goldmark:
renderer:
unsafe: true

How to put first level sections on different HTML pages?

In order to make first level sections instead of only chapters html pages of their own, I tried to alter the split_by in the yaml.
I used this code:
---
title: "new book"
author: "My name"
date: "`r Sys.Date()`"
subtitle: "subtitle"
site: bookdown::bookdown_site
output:
bookdown::gitbook:
split_by: chapter
config:
toc:
collapse: subsection
scroll_highlight: yes
before: null
after: null
toolbar:
position: fixed
edit : null
download: null
search: yes
fontsettings:
theme: white
family: sans
size: 2
sharing:
facebook: yes
twitter: yes
google: no
linkedin: no
weibo: no
instapaper: no
vk: no
all: ['facebook', 'google', 'twitter', 'linkedin', 'weibo', 'instapaper']
#bookdown::pdf_book: default
documentclass: book
---
When I change "chapter" into "section", R throws an error.
How can I make sure there will be seperated pages for chapters as well as first level sections?
There were (in this early stage of the document) some chapters without subsections. split_by: section will cause an error in case of chapters without sections.

Magnific PopUp - Custom title Css

I'm using Magnific pop up to display a lightbox gallery and I'm trying to customize the title apparence when the pop up show the image.
I can change the general look of the title with css, changing color, size,... but I can't have just some words bolder, having two lines of text with br,... even if I change the title source with titlesrc.
I've seen in the exemples of the documentation that you can have a "subtitle" by setting it directly inside the js but it will be the same for every images or I have around 50 images with a different title for each one:
$(document).ready(function() {
$('.popup-gallery').magnificPopup({
delegate: 'a',
type: 'image',
tLoading: 'Loading image #%curr%...',
mainClass: 'mfp-img-mobile',
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0,1] // Will preload 0 - before current, and 1 after the current image
},
image: {
tError: 'The image #%curr% could not be loaded.',
titleSrc: function(item) {
return item.el.attr('title') + '<small>by Marsel Van Oosten</small>';
}
}
});
});
With the default options, you can set in title attribute also some HTML. So you can change these few words with CSS. For example:
<img src="thumb.jpg" width="100" height="100">

Resources