-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (54 loc) · 1.85 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict';
hexo.extend.tag.register('language_switch', function(args) {
const defaultOptions = {
buttonClass: 'lang-switch-btn',
languages: ['en', 'zh'],
defaultLang: 'en',
labels: {
en: '切换中文',
zh: 'Switch to English'
}
};
const styles =
'<style>' +
'.lang-content {' +
'width: 100%;' +
'overflow: hidden;' +
'}' +
'.lang-content:not(:first-child) {' +
'display: none;' +
'}' +
'</style>';
const button =
'<div style="text-align: right; margin: 0 0 20px auto; max-width: 200px;">' +
'<button id="langToggle" onclick="toggleLanguage()" class="' + defaultOptions.buttonClass + '" style="' +
'width: 100%;' +
'padding: 10px 20px;' +
'border-radius: 8px;' +
'border: 2px solid #2c3e50;' +
'background-color: #fff;' +
'cursor: pointer;' +
'color: #2c3e50;' +
'font-size: 15px;' +
'transition: all 0.3s ease;' +
'display: flex;' +
'align-items: center;' +
'justify-content: center;' +
'gap: 8px;' +
'box-shadow: 0 2px 4px rgba(0,0,0,0.1);">' +
'<span class="button-text">' + defaultOptions.labels[defaultOptions.defaultLang] + '</span>' +
'</button>' +
'</div>';
return styles + button;
}, {ends: false});
hexo.extend.tag.register('lang_content', function(args, content) {
const lang = args[0] || 'en';
const defaultLang = 'en';
const display = lang === defaultLang ? 'block' : 'none';
// 直接渲染内容,让 Hexo 处理标题 ID
const rendered = hexo.render.renderSync({text: content, engine: 'markdown'});
return '<div id="' + lang + '-content" class="lang-content" style="display: ' + display + ';">' +
rendered +
'</div>';
}, {ends: true});
hexo.extend.injector.register('head_end', require('./lib/injector'));