jekyll如何使用ajax,Using MathJax with Jekyll

Some notes before trying either of the following options

Option 0 will increase build times even with --incremental and really option 1 should likely be used in most instances, however, this along with the extra space taken up maybe worth the costs if you're deploying on a network with clients that may not have access to CDNs.

Both options have been tested on a private server with kramdown as the markdown interpreter and mathjax: true set within the project's _config.yml file; see Step 2 of Soham Bhattacharyya's answer and their preface, and upto Caramdir's first two code blocks for the how-to for those bits.

Option 0 download and copy the unpacked source to project-name

Download the source

cd ~

mkdir -p git/hub && cd git/hub

git clone --depth 1 https://github.com/mathjax/MathJax.git

Make a directory path in your project's and copy files from MathJax/unpacked to this path

cd ~

mkdir -p git/lan/project-name/assets/JS_3rd_Party/MathJax

cp -r git/hub/MathJax/unpacked/* git/lan/project-name/assets/JS_3rd_Party/MathJax/

Add the source to git tracking

cd git/lan/project-name/

git add assets/JS_3rd_Party/MathJax

git commit -m 'Added MathJax.js unpacked source to git tracking'

Write an include file

tee ./_includes/MathJax.html 1>/dev/null <

{%- if jekyll.environment == 'production' and site.mathjax == true -%}

{%- elsif jekyll.environment != 'production' and site.mathjax == true -%}

{%- endif -%}

EOF

Private server builds will use MathJax.js where as production environment (GitHub) will use latest.js using the above Liquid if...elsif...endif statement.

Write a post to test it

tee ./_posts/$(date +'%Y-%d-%m')-math-tests.markdown 1>/dev/null <

---

layout: post

title: "Math Tests"

date: $(date +'%Y-%d-%m %H:%M:%S %z')

categories: math

---

{%- include MathJax.html -%}

for $x,y,z \in \{1, 2,\dots 9\}$

$$

\sum_{i=1}^n X_n

$$

EOF

I've not tried it without s because cboettig's suggestion seems to totally do the trick.

Additionally that extra new-line within spans are no mistake, without'em there where still issues with rendered output.

Add these latest files to git tracking

git add _posts/$(date +'%Y-%d-')math-tests.markdown

git add _includes/MathJax.html

Build locally, or push and build on a remote server

bundle exec jekyll build --destination /tmp/www/project-name --config _config.yml --incremental

Option 1 copy just latest.js to use a CDN (Content Delivery Network)

See Option 0 step 1.

Make a directory path for third party JavaScripts and copy MathJax/unpacked/latest.js there

cd ~

mkdir -p git/lan/project-name/assets/JS_3rd_Party/MathJax

cp git/hub/MathJax/unpacked/latest.js git/lan/project-name/assets/JS_3rd_Party/MathJax/

Write an include file

cd git/lan/project-name

tee ./_includes/MathJax.html 1>/dev/null <

EOF

See Option 0 Step 5.

Add these three files to git tracking

git add _includes/MathJax.html

git add _posts/$(date +'%Y-%d-')math-tests.markdown

git add assets/JS_3rd_Party/MathJax

git commit -m 'Added `MathJax.html`, `latest.js`, and a test post to git tracking'

See Option 0 Step 7. for building locally

For either of the options

If deploying on a private server you may also need to define baseurl within your project's _config.yml file, especially if emulating the username.tld/project-name URL scheme that GitHub uses on your private server.

If deploying to both a private server and GitHub it may be better to use a separate config file and when building issue --config _config.yml,_config_baseurl.yml, eg...

# Write the special config file

tee ./_config_baseurl.yml 1>/dev/null <

baseurl: "project-name"

EOF

# Build with extra config

bundle exec jekyll build --destination /tmp/www/project-name --config _config.yml,_config_baseurl.yml --incremental

Hope that helps with loading assets via an include.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值