Skip to content

Commit

Permalink
feat: auto enable math in posts (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris authored Dec 10, 2020
1 parent ffa0556 commit 141e407
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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 }}

0 comments on commit 141e407

Please sign in to comment.