-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
129 lines (109 loc) · 2.63 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const css = `
<style>
* {
box-sizing: border-box;
}
*:focus, input:focus + label {
}
.tabs {
display: flex;
flex-wrap: wrap;
margin: 0 auto 20px;
}
.radiotab {
position: absolute;
opacity: 0;
}
.label {
width: 100%;
padding: .75rem 1.6rem;
background: rgb(245, 247, 249);
z-index: 1;
cursor: pointer;
font-size: 1.4rem;
color: rgb(136, 153, 168);
border: 1px solid rgb(211, 220, 228);
border-radius: 0;
text-align: center;
margin: 0 -1px -1px 0;
text-rendering: optimizelegibility;
}
.label:first-of-type {
border-radius: .4rem 0 0 0;
}
.label:last-of-type {
border-radius: 0 .4rem 0 0;
}
.label:hover {
background: rgb(233 235 237);
}
.label:active {
}
.radiotab:checked + .label {
z-index: 3;
color: rgb(59, 69, 78);
border-bottom: 1px solid rgb(255, 255, 255);
background: rgb(255, 255, 255);
}
.panel {
display: none;
padding: 3rem 1.6rem 1rem 1.6rem;
width: 100%;
z-index: 2;
border-radius: 0 .4rem .4rem .4rem;
border: 1px solid rgb(211, 220, 228);
color: rgb(59, 69, 78);
font-size: 1.5rem;
}
.radiotab:checked + .label + .panel {
display: block;
}
@media (min-width: 600px) {
.panel {
order: 99;
}
.label {
width: max-content;
}
}
</style>
`;
module.exports = {
hooks: {
'page': function (page) {
var content = page.content;
var tabBlocks = content.split('<!-- tabs:end -->').filter(Boolean);
tabBlocks.forEach(function (block) {
var match = block.match(/<!-- tabs:start -->([\s\S]*)/);
if (match) {
var tabsHtml = '<div class="tabs">\n';
var tabCount = 0;
var tabContent = match[1].trim();
var individualTabs = tabContent.split('<h2>').filter(Boolean);
individualTabs.forEach(function (tab) {
tabCount++;
var lines = tab.split('\n');
var tabName = lines[0].replace('</h2>', '').trim();
var tabBody = lines.slice(1).join('\n').trim();
var tabId = `tab${tabCount}`;
var isChecked = tabCount === 1 ? 'checked="checked"' : '';
tabsHtml += `
<input class="radiotab" name="tabs" tabindex="1" type="radio" id="${tabId}" ${isChecked}>
<label class="label" for="${tabId}">${tabName}</label>
<div class="panel" tabindex="1">
${tabBody}
</div>
`;
});
tabsHtml += '</div>\n';
content = content.replace(match[0], tabsHtml);
}
});
page.content = content;
if (!page.content.includes('<style>')) {
page.content = css + page.content;
}
return page;
}
}
};