diff --git a/content/posts/data/index.md b/content/posts/data/index.md new file mode 100644 index 0000000..41b75dc --- /dev/null +++ b/content/posts/data/index.md @@ -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. \ No newline at end of file diff --git a/templates/shortcodes/data.html b/templates/shortcodes/data.html new file mode 100644 index 0000000..a697a89 --- /dev/null +++ b/templates/shortcodes/data.html @@ -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 %} \ No newline at end of file