My Zola cheatsheet

Most Markdown works as expected, but here are some less obvious things you can do. You can also include HTML.

Add a table of contents

{{ toc() }}

More options here: ~/tabi • Table of Contents

[Zola][zola]

[zola]: https://www.getzola.org

Zola

[Link to this page](@/notes/Blogging/my-zola-cheatsheet.md)

Link to this page

Images with labels on hover

![Sardinia climbing](https://climbingitaly.com/sector-img/pedra-longa-1.jpg "Want to go there") 

Sardinia climbing

Footnotes

This is a sentence which appears here.[^1]

[^1]: This is the footnote which appears at the end.

This is a sentence which appears here.1

YouTube shortcode

Shortcodes allow you to define shortcuts for HTML snippets or loading data

More shortcodes here: ~/tabi • Custom shortcodes

(See source code for how to escape shortcodes)

{{ youtube(id="5BYxzH9uBRg") }}

Callout shortcode

{% admonition(type = "tip") %}
This is important
{% end %}
TIP

This is important

Available types: note, tip, info, warning, danger

Aside shortcode

{% aside(position = "right") %}
This is an aside
{% end %}

Remote text shortcode

```r
{{ remote_text(src="https://raw.githubusercontent.com/prcleary/rename_pdf/refs/heads/master/rename_pdf.R") }}
```
#' Rename PDFs (Interactively)
#'
#' @param filepath Directory containing PDF files (default is to ask)
#' @param n_words Number of words of text to use as alternative title when no title in PDF metadata (default of 20); NB: risk of exceeding maximum file name length causing error
#' @param tag Optional text tag appended to file name to identify renamed files (e.g. to use in exclude if function is re-run)
#' @param exclude Optional PDF filenames containing this text will be ignored
#' @param opw Optional string with owner password if encrypted PDF
#' @param upw Optional string with user password if encrypted PDF
#'
#' @return Character vector of old names (invisibly)
#' @export
#'
#' @examples
#' rename_pdf(tag = '_pdfrn')  # Renames PDF files in current directory, tagging renamed files with "_pdfrn"
rename_pdf <- function(filepath = rstudioapi::selectDirectory(),
                       n_words_short = 20,
                       n_words_long = 500,
                       tag = '',
                       exclude = '',
                       opw = '',
                       upw = '',
                       random = FALSE,
                       pattern = '\\.pdf$|\\.PDF$') {
  # Function to remove punctuation, newlines, trailing whitespace
  sanitise_filename <- function(x) {
    x <- gsub('[[:punct:] ]+', ' ', x)
    x <- gsub('\\r|\\n', ' ', x)
    x <- trimws(gsub('[[:space:] ]+', ' ', x))
    x
  }
  message('\nRenaming PDFs...\n')
  original_filenames <-
    list.files(filepath, pattern = pattern, full.names = TRUE)
  if (random) { 
    original_filenames <- original_filenames[sample(length(original_filenames))]
  } else {
    original_filenames <- original_filenames[order(nchar(original_filenames))]
  }
  if (!exclude %in% '')
    original_filenames <-
    original_filenames[!grepl(exclude, original_filenames)]
  for (o in original_filenames) {
    o_dirname <- dirname(o)
    o_basename <- basename(o)
    o_title <- pdftools::pdf_info(o, opw, upw)$keys$Title
    raw_text <-
      paste0(pdftools::pdf_text(o, opw, upw), collapse = ' ')
    raw_text_sane <- sanitise_filename(raw_text)
    if (is.null(o_title)) {
      o_title_sane <- stringr::word(raw_text_sane, 1, n_words_short)
    } else if (o_title %in% '') {
      o_title_sane <- stringr::word(raw_text_sane, 1, n_words_short)
    } else {
      o_title_sane <- sanitise_filename(o_title)
    }
    o_title_sane <-
      stringr::str_replace_all(
        o_title_sane,
        c(
          'Microsoft Word\\s*' = '',
          'PowerPoint Presentation\\s*' = '',
          '\\s+doc\\s*' = '',
          '\\s+docx\\s*' = '',
          '\\s+pdf\\s*' = '',
          '\\s+dvi\\s*' = '',
          '\\s+indd\\s*' = '',
          '\\s+doi\\s*' = '',
          '\\s+crossm\\s*' = ''
        ),
        ''
      )
    cat('Original filename: ', o_basename, '\n')
    cat('Alternative title: ', o_title_sane, '\n')
    decision <-
      readline('Change to alternative title? (y[es]/[n]o/[c]hange manually): ')
    if (decision %in% 'y') {
      # TODO truncate if too long
      o_newname <-
        file.path(o_dirname,
                  paste0(o_title_sane, tag, '.pdf', collapse = NULL))
      file.rename(o, o_newname)
      cat('File renamed to: ', o_newname, '\n\n')
    } else if (decision %in% c('n', '')) {
      cat('File name not changed\n\n')
    } else if (decision %in% c('c')) {
      cat('First ', n_words_long, ' words of document:\n')
      cat(stringr::word(raw_text_sane, 1, n_words_long), '\n')
      specified_name <- readline('Specify file name: ')
      if (!specified_name %in% '') { 
        o_newname <- file.path(o_dirname, paste0(specified_name, tag, '.pdf', collapse = NULL))
      file.rename(o, o_newname)
      cat('File renamed to: ', o_newname, '\n\n')
      } else { 
        cat('File name not changed\n\n')
      }
    }
  }
  message('\nFinished\n')
  invisible(original_filenames)
}

Mermaid diagram shortcode

Need to add mermaid = true in [extra] section of frontmatter

{% mermaid(invertible = true, full_width = true) %}
flowchart TD
    A[Christmas] -->|Get money| B(Go shopping)
    B --> C{Let me think}
    C -->|One| D[Laptop]
    C -->|Two| E[iPhone]
    C -->|Three| F[fa:fa-car Car]
{% end %}
    flowchart TD
    A[Christmas] -->|Get money| B(Go shopping)
    B --> C{Let me think}
    C -->|One| D[Laptop]
    C -->|Two| E[iPhone]
    C -->|Three| F[fa:fa-car Car]

Spoiler shortcode

*... and the murderer was {{ spoiler(text="the podiatrist", fixed_blur=false) }}!*

… and the murderer was !

KaTeX for formulas

$y = \frac{x^3}{z}$

$y = \frac{x^3}{z}$

Emoji examples

codeemoji
:rocket:🚀
:smile:😄
:rofl:🤣
:sunglasses:😎

More here: ikatyang/emoji-cheat-sheet: A markdown version emoji cheat sheet

  • Tera, the syntax used for shortcodes: Tera
  • Zola discourse group: Zola

  1. This is the footnote which appears at the end.