From 51ccaa3ddaa687ec0985e58910c6fd98c84204c7 Mon Sep 17 00:00:00 2001 From: XPoet Date: Thu, 19 Nov 2020 17:02:49 +0800 Subject: [PATCH] fix: fixed bug where wordcount was empty --- layout/_partial/article-meta-info.ejs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/layout/_partial/article-meta-info.ejs b/layout/_partial/article-meta-info.ejs index e13b95b..88df737 100644 --- a/layout/_partial/article-meta-info.ejs +++ b/layout/_partial/article-meta-info.ejs @@ -26,14 +26,25 @@ <% } %> - <% if(is_post() && theme.post_wordcount.enable && theme.post_wordcount.wordcount){ %> + + <% + let temp_wordcount_count, temp_min2read_count = null; + try { + temp_wordcount_count = wordcount(page.content); + temp_min2read_count = min2read(page.content); + } catch (e) { + temp_wordcount_count = 0; + temp_min2read_count = 0; + } + %> + <% if(is_post() && theme.post_wordcount.enable && theme.post_wordcount.wordcount && temp_wordcount_count){ %> - <%= wordcount(page.content) %> <%- __('wordcount') %> + <%= temp_wordcount_count %> <%- __('wordcount') %> <% } %> - <% if(is_post() && theme.post_wordcount.enable && theme.post_wordcount.min2read){ %> + <% if(is_post() && theme.post_wordcount.enable && theme.post_wordcount.min2read && temp_min2read_count){ %> - <%= min2read(page.content) %> <%- __('min2read') %> + <%= temp_min2read_count %> <%- __('min2read') %> <% } %> <% if (is_post() && theme.website_count.busuanzi_count.enable && theme.website_count.busuanzi_count.page_pv) { %>