From 141e4077b7fc08e6edd21b02b13162e3161cb41c Mon Sep 17 00:00:00 2001 From: Shohei Ueda <30958501+peaceiris@users.noreply.github.com> Date: Fri, 11 Dec 2020 03:43:50 +0900 Subject: [PATCH] feat: auto enable math in posts (#241) --- exampleSite/content/en/posts/mathjax.md | 4 ++-- layouts/_default/list.html | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/exampleSite/content/en/posts/mathjax.md b/exampleSite/content/en/posts/mathjax.md index bf72fe529..0b8db765d 100644 --- a/exampleSite/content/en/posts/mathjax.md +++ b/exampleSite/content/en/posts/mathjax.md @@ -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 diff --git a/layouts/_default/list.html b/layouts/_default/list.html index e9f588306..b5507fa3c 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,4 +1,8 @@ {{ define "main" }} + +{{ $math := false }} +{{ $hasDollar := false }} +
@@ -23,7 +27,16 @@ {{ end }} {{ end }}

{{ $title }}

+ {{ if (findRE "\\$$" $title) }} + {{ $hasDollar = true }} + {{ end }}

{{ .Description }}

+ {{ if (findRE "\\$$" .Description) }} + {{ $hasDollar = true }} + {{ end }} + {{ if .Params.math }} + {{ $math = true }} + {{ end }}

{{ .Date.Format "2006-01-02" }}{{ partial "badges/slide" . }}

@@ -33,4 +46,9 @@

{{ $title }}

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