From eee22b08f59c7d7ee008dd58c8a2c167ab8ed3df Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Fri, 17 Mar 2023 16:44:50 +0100 Subject: [PATCH] Adjustments to the katex integration, part 2. --- README.md | 5 +++-- assets/js/cookieconsent.js | 1 - assets/js/math.js | 21 +++++++++++++++++++++ assets/js/search.js | 9 +++++---- assets/js/tracking.js | 5 +++-- layouts/partials/math.html | 11 +++++------ 6 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 assets/js/math.js diff --git a/README.md b/README.md index 26a110d..d79e7ad 100644 --- a/README.md +++ b/README.md @@ -796,9 +796,10 @@ Node.js software you need. To install them run: ## Math typesetting with Katex -Download the latest release from . Unpack and place the resulting "katex" directory in the root `assets/vendor` directory. +Download the latest release from . Unpack and place the resulting "katex" directory in the root `static` directory. + +The resulting path should be `static/katex`. Then set the `math` param to "true" and write some math to be typeset. -The resulting path should be `assets/vendor/katex`. Then set the `math` param to true and write some math to be typeset. ## Getting help diff --git a/assets/js/cookieconsent.js b/assets/js/cookieconsent.js index 4b4512b..74fd030 100644 --- a/assets/js/cookieconsent.js +++ b/assets/js/cookieconsent.js @@ -1,4 +1,3 @@ -/* eslint-disable no-undef */ (function () { 'use strict'; diff --git a/assets/js/math.js b/assets/js/math.js new file mode 100644 index 0000000..5cd4109 --- /dev/null +++ b/assets/js/math.js @@ -0,0 +1,21 @@ +/** + * @file + * A JavaScript file for Katex auto renderer. + */ + +(function () { + + 'use strict'; + + document.addEventListener('DOMContentLoaded', function () { + // eslint-disable-next-line no-undef + renderMathInElement(document.body, { + delimiters: [ + {left: '$$', right: '$$', display: true}, + {left: '$', right: '$', display: false} + ], + throwOnError: false + }); + }); + +})(); diff --git a/assets/js/search.js b/assets/js/search.js index e609fbe..03c3194 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -1,12 +1,13 @@ -/* eslint-disable no-undef, guard-for-in */ - /** * @file * A JavaScript file for flexsearch. */ +/* eslint-disable */ import * as params from '@params'; +/* eslint-enable */ +/* eslint-disable no-undef, guard-for-in */ (function () { 'use strict'; @@ -14,8 +15,8 @@ import * as params from '@params'; const index = new FlexSearch.Document({ document: { id: 'id', - index: ['title','tags','content','date'], - store: ['title','summary','date','permalink'] + index: ['title', 'tags', 'content', 'date'], + store: ['title', 'summary', 'date', 'permalink'] }, tokenize: 'forward' }); diff --git a/assets/js/tracking.js b/assets/js/tracking.js index 757a964..de00fde 100644 --- a/assets/js/tracking.js +++ b/assets/js/tracking.js @@ -1,12 +1,13 @@ -/* eslint-disable no-undef */ - /** * @file * A JavaScript file for analytic tracking. */ +/* eslint-disable */ import * as params from '@params'; +/* eslint-enable */ +/* eslint-disable no-undef */ const cookiebanner = params.cookieConsent; const cookieconsent = localStorage.getItem('cookieconsent'); const idSite = params.piwikSiteID; diff --git a/layouts/partials/math.html b/layouts/partials/math.html index c5f71a0..4039f1e 100644 --- a/layouts/partials/math.html +++ b/layouts/partials/math.html @@ -1,6 +1,5 @@ -{{ $katex_style := resources.Get "vendor/katex/katex.min.css" | fingerprint -}} - -{{ $katex := resources.Get "vendor/katex/katex.min.js" | fingerprint -}} - -{{ $auto_render := resources.Get "vendor/katex/contrib/auto-render.min.js" | fingerprint -}} - + + + +{{ $math := resources.Get "js/math.js" | minify | fingerprint -}} +