mirror of https://github.com/jpanther/congo.git
✨ Add chart shortcode
parent
04b5cb0f92
commit
68c05b97b2
|
@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- Chart.js support using `chart` shortcode
|
||||||
- French translation ([#18](https://github.com/jpanther/congo/pull/18))
|
- French translation ([#18](https://github.com/jpanther/congo/pull/18))
|
||||||
- Grouping by year can now be specificed in front matter on list pages
|
- Grouping by year can now be specificed in front matter on list pages
|
||||||
|
|
||||||
|
|
|
@ -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
|
- Flexible with any content types, taxonomies and menus
|
||||||
- Ability to link to posts on third-party websites
|
- Ability to link to posts on third-party websites
|
||||||
- Diagrams and visualisations using Mermaid
|
- Diagrams and visualisations using Mermaid
|
||||||
|
- Charts using Chart.js
|
||||||
- SVG icons from FontAwesome 5
|
- SVG icons from FontAwesome 5
|
||||||
- Heading anchors, Buttons, Badges and more
|
- Heading anchors, Buttons, Badges and more
|
||||||
- HTML and Emoji support in articles 🎉
|
- HTML and Emoji support in articles 🎉
|
||||||
|
|
|
@ -59,6 +59,40 @@ Call to action
|
||||||
Call to action
|
Call to action
|
||||||
{{< /button >}}
|
{{< /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 */>}}
|
||||||
|
```
|
||||||
|
|
||||||
|
<!-- prettier-ignore-start -->
|
||||||
|
{{< chart >}}
|
||||||
|
type: 'bar',
|
||||||
|
data: {
|
||||||
|
labels: ['Tomato', 'Blueberry', 'Banana', 'Lime', 'Orange'],
|
||||||
|
datasets: [{
|
||||||
|
label: '# of votes',
|
||||||
|
data: [12, 19, 3, 5, 3],
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
{{< /chart >}}
|
||||||
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
## Icon
|
## 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.
|
`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
|
||||||
|
|
||||||
`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.
|
Simply write your Mermaid syntax within the `mermaid` shortcode and let the plugin do the rest.
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,23 @@
|
||||||
</script>
|
</script>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
{{/* Chart */}}
|
||||||
|
{{ if .Page.HasShortcode "chart" }}
|
||||||
|
{{ $chartJS := resources.Get "vendor/chart/chart.min.js" }}
|
||||||
|
{{ if $chartJS }}
|
||||||
|
{{ $chartJS := $chartJS | resources.Fingerprint "sha512" }}
|
||||||
|
<script defer src="{{ $chartJS.RelPermalink }}" integrity="{{ $chartJS.Data.Integrity }}"></script>
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
|
function css(name) {
|
||||||
|
return getComputedStyle(document.documentElement).getPropertyValue(name);
|
||||||
|
}
|
||||||
|
Chart.defaults.font.size = 14
|
||||||
|
Chart.defaults.backgroundColor = css("--color-primary-300")
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
{{/* Analytics */}}
|
{{/* Analytics */}}
|
||||||
{{ partialCached "analytics.html" .Site }}
|
{{ partialCached "analytics.html" .Site }}
|
||||||
{{/* Extend head - eg. for custom analytics scripts, etc. */}}
|
{{/* Extend head - eg. for custom analytics scripts, etc. */}}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<div class="chart">
|
||||||
|
{{ $id := delimit (shuffle (seq 1 9)) "" }}
|
||||||
|
<canvas id="{{ $id }}"></canvas>
|
||||||
|
<script>
|
||||||
|
document.addEventListener("DOMContentLoaded", (event) => {
|
||||||
|
const ctx = document.getElementById("{{ $id }}");
|
||||||
|
const chart = new Chart(ctx, {
|
||||||
|
{{ .Inner | safeJS }}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</div>
|
Loading…
Reference in New Issue