diff --git a/CHANGELOG.md b/CHANGELOG.md index 06659675..87350fb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Added +- Chart.js support using `chart` shortcode - French translation ([#18](https://github.com/jpanther/congo/pull/18)) - Grouping by year can now be specificed in front matter on list pages diff --git a/README.md b/README.md index 7608d8e6..5c10ad75 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Congo is designed to be a simple, lightweight theme for [Hugo](https://gohugo.io - Flexible with any content types, taxonomies and menus - Ability to link to posts on third-party websites - Diagrams and visualisations using Mermaid +- Charts using Chart.js - SVG icons from FontAwesome 5 - Heading anchors, Buttons, Badges and more - HTML and Emoji support in articles 🎉 diff --git a/exampleSite/content/docs/shortcodes.md b/exampleSite/content/docs/shortcodes.md index e8baa7f8..55d94f1d 100644 --- a/exampleSite/content/docs/shortcodes.md +++ b/exampleSite/content/docs/shortcodes.md @@ -59,6 +59,40 @@ Call to action Call to action {{< /button >}} +## Chart + +`chart` uses the Chart.js library to embed charts into articles using simple structured data. It supports a number of [different chart styles](https://www.chartjs.org/docs/latest/samples/) and everything can be configured from within the shortcode. Simply provide the chart parameters between the shortcode tags and Chart.js will do the rest. + +Refer to the [official Chart.js docs](https://www.chartjs.org/docs/latest/general/) for details on syntax and supported chart types. + +**Example:** + +```js +{{* chart */>}} +type: 'bar', +data: { + labels: ['Tomato', 'Blueberry', 'Banana', 'Lime', 'Orange'], + datasets: [{ + label: '# of votes', + data: [12, 19, 3, 5, 2, 3], + }] +} +{{* /chart */>}} +``` + + +{{< chart >}} +type: 'bar', +data: { + labels: ['Tomato', 'Blueberry', 'Banana', 'Lime', 'Orange'], + datasets: [{ + label: '# of votes', + data: [12, 19, 3, 5, 3], + }] +} +{{< /chart >}} + + ## Icon `icon` outputs an SVG icon and takes the icon name as its only parameter. The icon is scaled to match the current text size. @@ -93,7 +127,7 @@ When life gives you lemons, make lemonade. ## Mermaid -`mermaid` allows you to draw detailed diagrams and visualisations using text. It uses MermaidJS under the hood and supports a wide variety of diagrams, charts and other output formats. +`mermaid` allows you to draw detailed diagrams and visualisations using text. It uses Mermaid under the hood and supports a wide variety of diagrams, charts and other output formats. Simply write your Mermaid syntax within the `mermaid` shortcode and let the plugin do the rest. diff --git a/layouts/partials/head.html b/layouts/partials/head.html index f9eb9534..13c270d5 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -116,6 +116,23 @@ {{ end }} {{ end }} + {{/* Chart */}} + {{ if .Page.HasShortcode "chart" }} + {{ $chartJS := resources.Get "vendor/chart/chart.min.js" }} + {{ if $chartJS }} + {{ $chartJS := $chartJS | resources.Fingerprint "sha512" }} + + + {{ end }} + {{ end }} {{/* Analytics */}} {{ partialCached "analytics.html" .Site }} {{/* Extend head - eg. for custom analytics scripts, etc. */}} diff --git a/layouts/shortcodes/chart.html b/layouts/shortcodes/chart.html new file mode 100644 index 00000000..bcfc4d2a --- /dev/null +++ b/layouts/shortcodes/chart.html @@ -0,0 +1,12 @@ +