From c8d5d1628711a7d4bc8646becd9c4e58498ddfed Mon Sep 17 00:00:00 2001 From: SukkaW Date: Tue, 29 Oct 2019 09:49:53 +0800 Subject: [PATCH] refactor: better usage of fragment_cache --- layout/_partial/after-footer.ejs | 63 ++++++++++++++++++-------------- layout/layout.ejs | 13 ++++++- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/layout/_partial/after-footer.ejs b/layout/_partial/after-footer.ejs index 603b01c9..c4e327ab 100644 --- a/layout/_partial/after-footer.ejs +++ b/layout/_partial/after-footer.ejs @@ -13,34 +13,41 @@ <% } %> -<%- js('js/jquery-3.4.1.min.js') %> +<%- fragment_cache('after_footer_custom', () => { + let html = '' + html += js('js/jquery-3.4.1.min.js'); + if (theme.fancybox) { + html += js('fancybox/jquery.fancybox.min.js') + } -<% if (theme.fancybox){ %> - <%- js('fancybox/jquery.fancybox.min.js') %> -<% } %> + html += js('js/script'); + html += partial('gauges-analytics') -<%- js('js/script') %> -<%- partial('gauges-analytics') %> + if (theme.valine.enable && theme.valine.appId && theme.valine.appKey) { + html += js('https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'); -<% if(theme.valine.enable && theme.valine.appId && theme.valine.appKey){ %> - <%- js('https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js') %> - -<% } %> \ No newline at end of file + html += ` + + ` + } + + return html +}) %> \ No newline at end of file diff --git a/layout/layout.ejs b/layout/layout.ejs index d676e3d4..00ffe957 100644 --- a/layout/layout.ejs +++ b/layout/layout.ejs @@ -7,9 +7,18 @@ <%- partial('_partial/header', null, {cache: !config.relative_link}) %>
<%- body %>
- <% if (theme.sidebar && theme.sidebar !== 'bottom'){ %> - <%- partial('_partial/sidebar', null, {cache: !config.relative_link}) %> + + <% if (!config.relative_link) { %> + <%- fragment_cache('sidebar', function() { + if (theme.sidebar && theme.sidebar !== 'bottom') return partial('_partial/sidebar'); + return ''; + }) %> + <% } else { %> + <% if (theme.sidebar && theme.sidebar !== 'bottom') { %> + <%- partial('_partial/sidebar') %> + <% } %> <% } %> +
<%- partial('_partial/footer', null, {cache: !config.relative_link}) %>