From 5d7f131c0ec95024f9ec5ff0022dc1264a6a0902 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Thu, 4 Jan 2024 13:39:50 +0800 Subject: [PATCH] [opt] head & inject --- _config.yml | 11 +++-- layout/_partial/head.ejs | 48 +++++++++++-------- layout/_partial/plugins/parser/head.ejs | 3 ++ layout/_partial/plugins/parser/katex/head.ejs | 3 ++ .../_partial/plugins/parser/katex/script.ejs | 4 ++ layout/_partial/plugins/parser/script.ejs | 3 ++ layout/_partial/scripts/index.ejs | 23 +++++++-- source/css/_layout/tag-plugins/tabs.styl | 2 + source/css/_plugins/index.styl | 2 +- 9 files changed, 71 insertions(+), 28 deletions(-) create mode 100644 layout/_partial/plugins/parser/head.ejs create mode 100644 layout/_partial/plugins/parser/katex/head.ejs create mode 100644 layout/_partial/plugins/parser/katex/script.ejs diff --git a/_config.yml b/_config.yml index 2c0626e..f29a09c 100755 --- a/_config.yml +++ b/_config.yml @@ -8,6 +8,10 @@ stellar: ######## head tags ######## +preconnect: + # - https://gcore.jsdelivr.net + # - https://unpkg.com + open_graph: enable: true twitter_id: # for open_graph meta @@ -353,7 +357,7 @@ plugins: # 需在Markdown文件开头加入mathjax: true # 推荐使用Pandoc: npm uninstall hexo-renderer-marked --save & npm install hexo-renderer-pandoc --save mathjax: - enable: true + # set to enable in page's front-matter js: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS-MML_HTMLorMML # Katex - The fastest math typesetting library for the web @@ -361,7 +365,7 @@ plugins: # https://github.com/KaTeX/KaTeX # 使用 hexo-renderer-markdown-it-plus 作为公式渲染器:npm uninstall hexo-renderer-marked --save npm install hexo-renderer-markdown-it-plus --save katex: - enable: false + # set to enable in page's front-matter min_css: min_js: auto_render_min_js: @@ -376,7 +380,8 @@ plugins: # B -->|option 2| C(Section C) # ``` mermaid: - enable: true + # set to enable in page's front-matter + style_optimization: false # use custom style in stellar # js: https://unpkg.com/mermaid@9.0.0/dist/mermaid.min.js js: https://cdn.jsdelivr.net/npm/mermaid@v9/dist/mermaid.min.js # Available themes: default | dark | forest | neutral diff --git a/layout/_partial/head.ejs b/layout/_partial/head.ejs index a3a06d9..6e3d4f8 100755 --- a/layout/_partial/head.ejs +++ b/layout/_partial/head.ejs @@ -67,18 +67,38 @@ function og_args() { } return Object.assign(args, page.open_graph); } + +function preconnect() { + var el = ''; + for (let href of (theme.preconnect || [])) { + el += ``; + } + return el; +} + +function custom_inject() { + var el = ''; + for (let item of (config.inject?.head || [])) { + el += item; + } + for (let item of (theme.inject?.head || [])) { + el += item; + } + for (let item of (page.inject?.head || [])) { + el += item; + } + return el; +} + %> + - <%- meta_generator() %> - + <%- generate_robots() %> - + <%- meta_generator() %> - - - - + <%- preconnect() %> @@ -115,16 +135,6 @@ function og_args() { <%- css(theme.style.codeblock.highlightjs_theme) %> <% } %> - <% if (theme.plugins.katex && theme.plugins.katex.enable) { %> - <%- theme.plugins.katex.min_css %> - <%- theme.plugins.katex.min_js %> - <%- theme.plugins.katex.auto_render_min_js %> - <% } %> - - - <% if (config.inject && config.inject.head){ %> - <% (config.inject.head||[]).forEach(function(item){ %> - <%- item %> - <% }) %> - <% } %> + <%- partial('plugins/parser/head') %> + <%- custom_inject() %> diff --git a/layout/_partial/plugins/parser/head.ejs b/layout/_partial/plugins/parser/head.ejs new file mode 100644 index 0000000..77aca89 --- /dev/null +++ b/layout/_partial/plugins/parser/head.ejs @@ -0,0 +1,3 @@ +<% if (page.katex == true) { %> + <%- partial('katex/head') %> +<% } %> \ No newline at end of file diff --git a/layout/_partial/plugins/parser/katex/head.ejs b/layout/_partial/plugins/parser/katex/head.ejs new file mode 100644 index 0000000..b34197e --- /dev/null +++ b/layout/_partial/plugins/parser/katex/head.ejs @@ -0,0 +1,3 @@ +<% if (theme.plugins.katex) { %> + <%- theme.plugins.katex.min_css %> +<% } %> diff --git a/layout/_partial/plugins/parser/katex/script.ejs b/layout/_partial/plugins/parser/katex/script.ejs new file mode 100644 index 0000000..c51d756 --- /dev/null +++ b/layout/_partial/plugins/parser/katex/script.ejs @@ -0,0 +1,4 @@ +<% if (theme.plugins.katex) { %> + <%- theme.plugins.katex.min_js %> + <%- theme.plugins.katex.auto_render_min_js %> +<% } %> diff --git a/layout/_partial/plugins/parser/script.ejs b/layout/_partial/plugins/parser/script.ejs index f1e95b2..b30bf39 100644 --- a/layout/_partial/plugins/parser/script.ejs +++ b/layout/_partial/plugins/parser/script.ejs @@ -1,3 +1,6 @@ +<% if (page.katex == true) { %> + <%- partial('katex/script') %> +<% } %> <% if (page.mathjax == true) { %> <%- partial('mathjax/script') %> <% } %> diff --git a/layout/_partial/scripts/index.ejs b/layout/_partial/scripts/index.ejs index ce494e7..a57f201 100644 --- a/layout/_partial/scripts/index.ejs +++ b/layout/_partial/scripts/index.ejs @@ -1,3 +1,20 @@ +<% + +function custom_inject() { + var el = ''; + for (let item of (config.inject?.script || [])) { + el += item; + } + for (let item of (theme.inject?.script || [])) { + el += item; + } + for (let item of (page.inject?.script || [])) { + el += item; + } + return el; +} + +%>