Skip to content

Commit

Permalink
fix mastodon auto-find logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sudorandom committed May 28, 2024
1 parent 0592918 commit ba514a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions content/posts/2024/hugo-chartjs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ slug: "hugo-chartjs"
type: "posts"
devtoSkip: true
canonical_url: https://kmcd.dev/posts/hugo-chartjs
mastodonID: "112517411212093961"
---

I recently wanted to add some charts to a blog post and [mermaid](https://mermaid.live) just wasn't cutting it. Mermaid didn't support the options I wanted to use and ultimately wasn't flexible enough to show a horizontal bar chart with the customization options I wanted. So I went looking for alternatives... and that's when I found this [shen-yu/hugo-chart](https://github.com/shen-yu/hugo-chart)... layout? for hugo that adds [Chart.js](https://www.chartjs.org/) support. Chart.js is a great javascript library for creating many kinds of charts with many customization options. *Perfect*, I thought. As I started using `shen/yu-hugo-chart` to add chart.js to my site, a few things stood out to me:
Expand Down
11 changes: 6 additions & 5 deletions layouts/partials/load-mastodon.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
{{- if .Params.mastodonID -}}
{{- $statusMap := (index .Site.Data.mastodon.index.statuses .Params.mastodonID) -}}
{{- $statusPath := $statusMap.path -}}
{{- $toot := (index .Site.Data.mastodon (split (path.Dir $statusPath) "/")) -}}
{{- $toot := (index $.Site.Data.mastodon (split (path.Dir $statusPath) "/")) -}}
{{- $.Page.Store.Set "toot" $toot -}}
{{- else -}}
{{- range .Site.Data.mastodon.index.statuses -}}
{{- $statusPath := .path -}}
{{- $toot := (index .Site.Data.mastodon (split (path.Dir $statusPath) "/")) -}}
{{- if (strings.Contains $toot.Content $.Page.RelPermalink) -}}
{{- $.Page.Store.Set "toot" . -}}
{{- warnf "Mastodon post found for post: '%s' mastodonID: \"%s\"" $.Page.Path .Params.id -}}
{{- $toot := (index $.Site.Data.mastodon (split (path.Dir $statusPath) "/")) -}}
{{ $path := (split (path.Dir $statusPath) "/") }}
{{- if (strings.Contains $toot.status.content $.Page.RelPermalink) -}}
{{- $.Page.Store.Set "toot" $toot -}}
{{- warnf "Mastodon post found for post: '%s' mastodonID: \"%s\"" $.Page.Path $toot.status.id -}}
{{- end -}}
{{- end -}}
{{- end -}}
Expand Down

0 comments on commit ba514a2

Please sign in to comment.