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: auto enable math in posts #241

Merged
merged 1 commit into from
Dec 10, 2020
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
4 changes: 2 additions & 2 deletions exampleSite/content/en/posts/mathjax.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: MathJax Support
description: Beautiful math in all browsers
title: MathJax Support $E=mc^2$
description: Beautiful math in all browsers $E=mc^2$
publishdate: 2020-01-01T01:00:00.000Z
# draft: true
# eyecatch: images/mathjax.jpg
Expand Down
18 changes: 18 additions & 0 deletions layouts/_default/list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{{ define "main" }}

{{ $math := false }}
{{ $hasDollar := false }}

<main>
<article>
<!-- "{{.Content}}" pulls from the markdown content of the corresponding _index.md -->
Expand All @@ -23,7 +27,16 @@
{{ end }}
{{ end }}
<h2 class="title">{{ $title }}</h2>
{{ if (findRE "\\$$" $title) }}
{{ $hasDollar = true }}
{{ end }}
<p>{{ .Description }}</p>
{{ if (findRE "\\$$" .Description) }}
{{ $hasDollar = true }}
{{ end }}
{{ if .Params.math }}
{{ $math = true }}
{{ end }}
<!-- TODO: is-pulled-right does not work -->
<p>{{ .Date.Format "2006-01-02" }}{{ partial "badges/slide" . }}</p>
</div>
Expand All @@ -33,4 +46,9 @@ <h2 class="title">{{ $title }}</h2>
</div>
{{ end }}
</main>

{{ if and $math $hasDollar }}
{{ partialCached "mathjax" . }}
{{ end }}

{{ end }}