Welcome To My World

how2
Author

José R. Ferrer-Paris

Published

May 17, 2024

This is the typical Hello World! post in my new and wonderful blog. Welcome!

So this is basically here to test if the whole thing works.

To get started I first installed quarto.1

Then, once I decided how to name my blog, I ran:

quarto create project blog spatial-one

Then I started to prepare the content and structure of my initial posts, modified the text in the qmd files and the configuration in the _quarto.yml and ran

I started to keep track of changes with git:2

cd spatial-one
git init

I switch between VS-code, Rstudio and the terminal to organise my files, and kept working on this until I got something I wanted to preview:

quarto preview spatial-one

Here some random notes about the process

icons

For some reason I though these would fontsawesome icons, but the help prompt in VS-code pointed out:

Name of bootstrap icon (e.g. github, twitter, share). See https://icons.getbootstrap.com/ for a list of available icons

Also, it turns out we can add emojis to the text of a post using this in the front-matter of the file:

---
title: "My Document"
from: markdown+emoji
---

This is a handy demonstration of all emojis: https://gist.github.com/rxaviers/7360908

Freeze

The posts directory has a _metadata.yml file with the freeze option activated by default.

_site folder

In the quarto documentation they recommend to add it to the .gitignore file, so as to keep the raw content and code in version control, but the output served in a different workflow (either with quarto.pub or GitHub actions).

Secrets

There are certain environment variables that need to be specified in order to render the posts in this blog. I created an _environment.required file with the list of required variables and empty values.

_environment.required
FLICKR_API_KEY=

For local development, I defined these variables in the _environment.local file and ignore this file in version control by adding /_*.local in .gitignore.

Engine

Some code is running with RStudio / VScode and R , some code with Python and Jupyter.

For python, we created a virtual environment in the project directory.

python3 -m venv .venv

Then we activate the environment

source .venv/bin/activate    

Then we update pip, install other packages with:

pip install --upgrade pip
pip install jupyterlab
pip install numpy matplotlib spyder owslib 
pip install geopandas rasterio rasterstats affine osmnx
pip install earthpy
pip install h3pandas
pip install pyinaturalist

To make this environment reproducible, we create a requirements.txt using pip

python3 -m pip freeze > requirements.txt

Then we can reproduce this environment on another machine by creating an empty environment, activating it, and then:

python3 -m pip install -r requirements.txt

Photos

From Flickr

In order to use some external photos in my blog posts I create a table with the basic information from my photo collection in Flickr. I need to add this code-chunk in my post to locate and load the file:

```{r}
#| message: false
here::i_am("posts/welcome.qmd")
data_dir <- here::here("Rdata")
file_name <- here::here(data_dir, "flickr-photos.rds")
photos <- readRDS(file = file_name)
```

And these lines to create the markdown code to include in my blog post (notice the results option):

```{r}
#| results: asis
selected_photo <- dplyr::slice(photos, grep("Del-etreando", title))

photo_md <- sprintf(
  "![**%s** by %s@flickr](%s){.preview-image .lightbox}",
  selected_photo$title,
  selected_photo$ownername,
  selected_photo$url_m
)

cat(photo_md)
```

Del-etreando (21/365+ñ) by ¡Fgz!@flickr

Del-etreando (21/365+ñ) by ¡Fgz!@flickr

I add the class preview-image to select which foto will appear in the listing page of posts.

From iNaturalist

Since I also have a bunch of observations in iNaturalist, I can use those as another source of images to illustrate my blog. I need to add this code-chunk in my post to locate and load the file:

```{r}
#| message: false
here::i_am("posts/welcome.qmd")
data_dir <- here::here("Rdata")
file_name <- here::here("Rdata","iNaturalist-obs-NeoMapas.rds")
user_obs <- readRDS(file=file_name)
```

And these lines to create the markdown code to include in my blog post (notice the results option):

```{r}
#| results: asis
selected_photo <- user_obs |> dplyr::slice_sample(n=1)
photo_md <- sprintf(
  "![*%s* observed in %s by [%s@iNaturalist](%s)](%s){height=150 group=\"my-gallery\"}",
  selected_photo$species_guess,
  selected_photo$place_guess,
  selected_photo$user_login,
  selected_photo$url,
  selected_photo$image_url
)

cat(photo_md)
```

Passiflora gritensis observed in Rivas Dávila, Mérida, Venezuela by neomapas@iNaturalist

From other places

I keep some random images in the thesaurus folder and use imagemagick to make copies for my blog post. For example:

convert thesaurus/207d9efb-e858-4c4c-81ab-ac056f72c870.jpeg -resize 300x300 posts/wms-in-R/image.jpg 

Publish / Code

On Github

I created an empty repo in GitHub and then added it as a remote:

git remote add origin git@github.com:{...}/{...}.git
git branch -M dont-panic
git push -u origin dont-panic

Now the source code and git history is available at: https://github.com/jrfep/spatial-one

Comments through Giscus

How to get comments powered by GitHub Discussions and the giscus app?

  1. Enable the Discussions feature in the GitHub repo
  2. Install the giscus app in the GitHub account
  3. Enable comments in the _quarto.yml file:
---
website:
  comments:
    giscus: 
      repo: jrfep/spatial-one
---

Quarto Pub

I am preparing this site for my quarto.pub profile. From the directory where this project is located, I executed the quarto publish command for Quarto Pub:

quarto publish quarto-pub

And then followed instructions at quarto.org.

Easy!

Footnotes

  1. Well to be honest, it all started with a operating system, then installing lots of packages, and R and Python, and … but let’s keep it short.↩︎

  2. If we do this before rendering or preview of the site, quarto will create a .gitignore file with the line /.quarto/.↩︎