Skip to content

Commit

Permalink
Added fold-results lua filter, shortcodes section, updated site SEO i…
Browse files Browse the repository at this point in the history
…mage for opengraph
  • Loading branch information
royfrancis committed Nov 11, 2024
1 parent 4b215c8 commit 58ef84f
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 4 deletions.
4 changes: 3 additions & 1 deletion _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project:
output-dir: docs

website:
image: "assets/images/featured.webp"
image: "assets/images/seo.webp"
favicon: "assets/favicon.png"
navbar:
logo: "assets/logos/nbis-scilifelab.webp"
Expand Down Expand Up @@ -100,6 +100,8 @@ execute:

filters:
- assets/custom.lua
- assets/fold-results.lua
- reveal-logo
- fontawesome

custom-metadata: "This is custom metdata"
20 changes: 20 additions & 0 deletions assets/fold-results.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Fold output from code chunks
-- In code chunk, add #| attr.output: '.details summary="Output"'
-- Only works for knitr chunks
-- https://gist.github.com/atusy/f2b5b992e45c68ab6823499f2339c6e6

function CodeBlock(elem)
if elem.classes and elem.classes:find("details") then
local summary = "Code"
if elem.attributes.summary then
summary = elem.attributes.summary
end
return{
pandoc.RawBlock(
"html", "<details><summary>" .. summary .. "</summary>"
),
elem,
pandoc.RawBlock("html", "</details>")
}
end
end
Binary file added assets/images/seo.webp
Binary file not shown.
34 changes: 31 additions & 3 deletions reports/demo-with-r/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,34 @@ Sys.Date()
```
````

Source code blocks can be folded.

````
```{{r}}
#| code-fold: true
Sys.Date()
```
````

```{r}
#| code-fold: true
Sys.Date()
```

There is not proper implementation to fold code output. Here is a hacky solution that uses a custom lua filter.

````
```{{r}}
#| attr.output: '.details summary="Output"'
Sys.Date()
```
````

```{r}
#| attr.output: '.details summary="Output"'
Sys.Date()
```

A code chunk can be given a code filename using the chunk attribute `filename`.

````
Expand Down Expand Up @@ -122,15 +150,15 @@ Sys.Date()
sessionInfo()
```

An advanced example showing bash code generated from R.
An example showing bash code generated from R.

````
```{{r}}
#| attr-output: "filename='bash'"
#| class-output: bash
#| echo: false
d <- "custom"
cat(paste("mkdir", d))
cat(paste("mkdir", d))
```
````

Expand All @@ -139,7 +167,7 @@ cat(paste("mkdir​", d))
#| class-output: bash
#| echo: false
d <- "custom"
cat(paste("mkdir", d))
cat(paste("mkdir", d))
```

Code chunk attributes are documented [here](https://quarto.org/docs/output-formats/html-code.html).
Expand Down
41 changes: 41 additions & 0 deletions reports/demo/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ This content is behind an accordion.

## Alerts

This is not a quarto feature, but rather from bootstrap.

```
::: {.alert .alert-primary}
**Note:** This is an alert!
Expand Down Expand Up @@ -905,6 +907,45 @@ This is some material for topic 2.

More layout settings are described [here](https://quarto.org/docs/authoring/article-layout.html) and [here](https://quarto.org/docs/output-formats/page-layout.html).

## Shortcodes

Shortcodes are sort of like quarto functions.

Two important shortcodes are `meta` and `var`. `meta` allows to read metadata from the yaml block in the current page or from `_quarto.yml`. Here are a few examples:

`{{{< meta title >}}}` {{< meta title >}}

`![]({{{< meta image >}}}){width="200px"}`

![]({{< meta image >}}){width="200px"}

`{{{< meta custom-metadata >}}}` {{< meta custom-metadata >}}

:::{.callout-note}
Mostly only user-specified metadata in `_quarto.yml` can be accessed using `meta` shortcode.
:::

Similarly, `var` allows to read variables from `_variables.yml` if it has been defined. The `include` shortcode allows to add a child qmd document into a specific position in a qmd file. The `kbd` shortcode allows keyboard notations:

`Press {{{< kbd Shift-Ctrl-P >}}}` Press {{< kbd Shift-Ctrl-P >}}

The `video` shortcode allows to embed a video.

`{{{< video https://www.youtube.com/watch?v=_f3latmOhew >}}}`

{{< video https://www.youtube.com/watch?v=_f3latmOhew >}}

Some of the custom shortcodes added with Specky template are:

`{{{ < meta quarto_version > }}}` {{ < meta quarto_version > }}

`{{{ < meta current_date > }}}` {{ < meta current_date > }}

`{{{ < meta current year > }}}` {{ < meta current year > }}

`{{{ < meta current time > }}}` {{ < meta current time > }}

Shortcodes are documented [here](https://quarto.org/docs/authoring/shortcodes.html).

## General tips

Expand Down

0 comments on commit 58ef84f

Please sign in to comment.