gbif / hp-living-norway

Living Norway Ecological Data Network is facilitating FAIR management of ecological data to the benefit of society and science; https://livingnorway.no/
1 stars 0 forks source link

Add Markdown examples (RMD/MD/HTML) #16

Closed DrMattG closed 2 years ago

DrMattG commented 2 years ago

@siwelisabeth I have added some R markdown examples in the _posts folder. I was not sure what format would be best so I have knitted the Rmd files to md and html. The md renders a bit weirdly locally (not sure if that will happen on the site. The html is probably closest to what we would expect. You can change the output from the Rmd files by switching the output (you will see that the output to md is commented out in the Rmd files).

Let me know if this works!

Matt

siwelisabeth commented 2 years ago

@DrMattG

I have tested the different files int the LN portal now. I am not quite sure what the best solution is, so I just list the things I have figured out. Let me know what you are thinking and what is possible/easy to do from your side.

It seems like html-files are supported as blog posts in the LN portal. One problem with the files from Netlify is that a lot of css is generated and some of the styles conflict with the existing styles in the Living Norway Portal. An other issue is that the blog posts needs front-matter in order to display the title correctly. If we should use the html-files some styles must be overridden and front-matter added to the files.

The md-files also work, but there are some issues here too:

The site doesn't find images in the _post folder. According to the Jekyll documentation images should be placed on root or in another folder, i.e the asset folder. Then the image reference must be changed when generated (or later).

The generated md-files don't have front-matter, but I see that the rmd-files have. Minimum with title, but for the sake of styling maybe something more i.e,

--- layout: post title: "News from Living Norway" background: /assets/images/moss.jpg ---

The code blocks lack styling. In rmd-files the markup is like this.

```{r dataDownload, results="hide"} # Create a temporary directory to store intermediate files used in this workshop tempDirLoc <- tempdir() # The URL where the Darwin Core file for the TOV-E bird survey data is housed datasetURL <- "https://ipt.nina.no/archive.do?r=tove_birdsampling" # Download the Darwin Core file to the temporary directory localDataLoc <- file.path(tempDirLoc, "TOVEData.zip") download.file(datasetURL, localDataLoc, mode = "wb") ```

In the generated md-files there are no markup around code-blocks. In order for the code blocks to get proper styling, the md-files should look like this:

```r # Create a temporary directory to store intermediate files used in this workshop tempDirLoc <- tempdir() # The URL where the Darwin Core file for the TOV-E bird survey data is housed datasetURL <- "https://ipt.nina.no/archive.do?r=tove_birdsampling" # Download the Darwin Core file to the temporary directory localDataLoc <- file.path(tempDirLoc, "TOVEData.zip") download.file(datasetURL, localDataLoc, mode = "wb") ```

I found this site that describes different md-flavours when generating md-files from Rstudio (which you do?). Mabe some of the markdown variants provide something like this out of the box? https://bookdown.org/yihui/rmarkdown/markdown-document.html

DrMattG commented 2 years ago

@siwelisabeth Thanks for that breakdown of the issues - I found this: https://jchellmuth.com/news/jekyll/website/code/2020/01/04/Rmarkdown-posts-to-Jekyll.html to be really useful. It is as you suspected that a different flavour of markdown leads to the front matter being retained and to the code blocks being rendered correctly. One would think it would be straightforward switching between Rmarkdown and markdown! I will make my workflow align (using "asset" folder rather than _posts, etc.). I shall try again and send you the md files - hopefully this will work.

DrMattG commented 2 years ago

@siwelisabeth sorry this slipped from my radar... I have added output: github_document to the two .Rmd files and these should render correctly (....famous last words I know).

siwelisabeth commented 2 years ago

@DrMattG

Thank you very much :-) The styling of the code blocks seems very fine now.

The generated md-files needs front-matter on this format (see below) in order to display title correctly in the Jekyll blog. So it needs minimun title. And if possible something like this:

--- layout: post title: "News from Living Norway" background: /assets/images/moss.jpg ---

Is this something you can generate from your side? I see that the rmd have frontmatter in the correct format.

And also the images is still an issue. According to the Jekyll documentation images should be placed on root or in another folder, i.e the asset folder. Then the image reference must be changed when generated (or later). Is it possible to handle this from your side in the md-generation or is some manual fixing required?

siwelisabeth commented 2 years ago

@DrMattG It seems like the two issues with front-matter and images are described in the link that you sent, option 2: https://jchellmuth.com/news/jekyll/website/code/2020/01/04/Rmarkdown-posts-to-Jekyll.html

DrMattG commented 2 years ago

@DrMattG

Thank you very much :-) The styling of the code blocks seems very fine now.

The generated md-files needs front-matter on this format (see below) in order to display title correctly in the Jekyll blog. So it needs minimun title. And if possible something like this:

--- layout: post title: "News from Living Norway" background: /assets/images/moss.jpg ---

Is this something you can generate from your side? I see that the rmd have frontmatter in the correct format.

And also the images is still an issue. According to the Jekyll documentation images should be placed on root or in another folder, i.e the asset folder. Then the image reference must be changed when generated (or later). Is it possible to handle this from your side in the md-generation or is some manual fixing required?

I think I can include the images (in asset folder) in the workflow without a problem - I dont actually need to render this outside of the portal (I think we can drop the netlify blog now and use the portal alone ) so we can put the path in to the rmd so the images are sourced from the correctly named folder.

DrMattG commented 2 years ago

@DrMattG It seems like the two issues with front-matter and images are described in the link that you sent, option 2: https://jchellmuth.com/news/jekyll/website/code/2020/01/04/Rmarkdown-posts-to-Jekyll.html

Great! This one I was struggling with! Thank you for finding that