Skip to content

Commit 7556f70

Browse files
committed
refactor: streamline Waline configuration and helper functions
- Removed redundant configuration options in waline.ejs and replaced them with a more concise helper function for generating configuration. - Introduced new helper functions in waline-helpers.js to handle array and object configurations, improving readability and maintainability. - Updated CSS import paths in style.styl for consistency. - Deleted unused CSS modules related to comments and layout to reduce clutter and improve performance.
1 parent 69afdc7 commit 7556f70

29 files changed

Lines changed: 55 additions & 20 deletions

layout/components/comments/waline.ejs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,21 @@
77
init({
88
el: '#waline',
99
serverURL: '<%= theme.comment.config.waline.serverUrl %>',
10-
lang: '<%= theme.comment.config.waline.lang %>',
1110
dark: 'body[class~="dark-mode"]',
1211
reaction: <%- waline_reaction_config(theme.comment.config.waline.reaction) %>,
1312
requiredMeta: ['nick', 'mail'],
14-
emoji: [<%- theme.comment.config.waline.emoji && theme.comment.config.waline.emoji.map(
15-
(item) => `'${item}'`
16-
).join(','
17-
) %>],
18-
locale: <%= theme.comment.config.waline.locale %>,
19-
login: '<%= theme.comment.config.waline.login %>',
20-
wordLimit: <%= theme.comment.config.waline.wordLimit %>,
21-
pageSize: <%= theme.comment.config.waline.pageSize %>,
22-
commentSorting: '<%= theme.comment.config.waline.commentSorting %>'
23-
meta: <%= theme.comment.config.waline.meta %>
24-
<%- theme.comment.config.waline.recaptchaV3Key &&
25-
`recaptchaV3Key: "${theme.comment.config.waline.recaptchaV3Key}",`;
26-
%>
27-
<%- theme.comment.config.waline.turnstileKey &&
28-
`turnstileKey: "${theme.comment.config.waline.turnstileKey}",`;
29-
%>
13+
emoji: <%- waline_array_config(theme.comment.config.waline.emoji) %>,
14+
<%- waline_config_options({
15+
lang: theme.comment.config.waline.lang,
16+
locale: theme.comment.config.waline.locale,
17+
login: theme.comment.config.waline.login,
18+
wordLimit: theme.comment.config.waline.wordLimit,
19+
pageSize: theme.comment.config.waline.pageSize,
20+
commentSorting: theme.comment.config.waline.commentSorting,
21+
meta: theme.comment.config.waline.meta,
22+
recaptchaV3Key: theme.comment.config.waline.recaptchaV3Key,
23+
turnstileKey: theme.comment.config.waline.turnstileKey
24+
}) %>
3025
});
3126
}
3227

scripts/helpers/theme-helpers.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,17 @@ hexo.extend.helper.register("checkDeprecation", function (condition, id, message
235235
}
236236
return false;
237237
});
238+
239+
hexo.extend.helper.register("configOptions", function (obj, indent = ' ') {
240+
if (!obj || typeof obj !== 'object') return '';
241+
242+
return Object.entries(obj)
243+
.filter(([key, value]) => value !== undefined && value !== null && value !== '')
244+
.map(([key, value]) => {
245+
if (typeof value === 'string') {
246+
return `${indent}${key}: '${value}',`;
247+
}
248+
return `${indent}${key}: ${value},`;
249+
})
250+
.join('\n');
251+
});

scripts/helpers/waline-helpers.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,30 @@ hexo.extend.helper.register('waline_reaction_config', function(reactionConfig) {
44
} else {
55
return Boolean(reactionConfig);
66
}
7+
});
8+
9+
hexo.extend.helper.register('waline_array_config', function(arrayConfig) {
10+
if (Array.isArray(arrayConfig) && arrayConfig.length) {
11+
return `[${arrayConfig.map(item => `'${item}'`).join(', ')}]`;
12+
}
13+
return '[]';
14+
});
15+
16+
hexo.extend.helper.register('waline_config_options', function(config) {
17+
if (!config || typeof config !== 'object') return '';
18+
19+
const formatValue = (value) => {
20+
if (typeof value === 'string') {
21+
return `'${value}'`;
22+
}
23+
if (Array.isArray(value)) {
24+
return `[${value.map(item => typeof item === 'string' ? `'${item}'` : item).join(', ')}]`;
25+
}
26+
return value;
27+
};
28+
29+
return Object.entries(config)
30+
.filter(([key, value]) => value !== undefined && value !== null && value !== '')
31+
.map(([key, value]) => ` ${key}: ${formatValue(value)},`)
32+
.join('\n');
733
});
File renamed without changes.

0 commit comments

Comments
 (0)