Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add data shortcode #13

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions content/posts/data/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
+++
title = "Data"
date = 2022-10-01
[taxonomies]
categories = ["usage"]
tags = ["content", "shortcode"]
[extra]
subtitle = "Data loader"
+++

Display data from internal or external sources.

## Example

#### Input

```
This theme requires **Zola** version {{/* data(src="../theme.toml" type="toml" key="min_version") */}} or later.
```

- `src`: the address of the data source (mandatory)
- `type`: the file type of the data source ([supported types](https://www.getzola.org/documentation/templates/overview/#load-data))
- `key`: an object in the data to display

#### Output

This theme requires **Zola** version {{ data(src="../theme.toml" type="toml" key="min_version") }} or later.
15 changes: 15 additions & 0 deletions templates/shortcodes/data.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{%- if src and key and type %}
{%- if src is matching("^http[s]?://") %}
{% set loaded_data = load_data(url=src, format=type) %}
{%- else %}
{% set loaded_data = load_data(path=src, format=type) %}
{%- endif %}
{{ loaded_data[key] }}
{%- else %}
{%- if src is matching("^http[s]?://") %}
{% set loaded_data = load_data(url=src) %}
{%- else %}
{% set loaded_data = load_data(path=src) %}
{%- endif %}
{{ loaded_data }}
{%- endif %}
Loading