jekyll-ham 0.3.3 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -0
- data/_config.yml +2 -0
- data/_includes/comments.html +4 -49
- data/_includes/ham/comments.html +49 -0
- data/_includes/{external-link.html → ham/external-link.html} +1 -1
- data/_includes/ham/navbar.html +25 -0
- data/_includes/{search-modal.html → ham/search-modal.html} +1 -1
- data/_includes/ham/sidebar.html +37 -0
- data/_includes/navbar.html +3 -27
- data/_layouts/default.html +23 -10
- data/_layouts/page.html +70 -19
- data/assets/bootstrap-color-modes.js +90 -0
- data/assets/cookies.js +21 -0
- data/assets/default.css +18 -9
- data/assets/entry-parser.js +112 -22
- data/assets/halfmoon-variables.min.css +22 -11
- data/assets/halfmoon.min.js +7 -11
- data/assets/main.css +0 -11
- metadata +11 -8
- data/_includes/custom-comments.html +0 -4
- data/_includes/sidebar.html +0 -62
- /data/_includes/{footer.html → ham/footer.html} +0 -0
- /data/_includes/{random-posts.html → ham/random-posts.html} +0 -0
data/assets/entry-parser.js
CHANGED
@@ -23,10 +23,19 @@ function parseRawEntry(originalContent, onThisPageEntry, siteTitle, siteTagline)
|
|
23
23
|
var headingTags = ['H2', 'H3', 'H4', 'H5', 'H6'];
|
24
24
|
var i, j;
|
25
25
|
var taglinePlaced = false;
|
26
|
-
var
|
26
|
+
var originalChildren = originalContent.childNodes;
|
27
27
|
var currentAccordionId = '';
|
28
|
-
|
29
|
-
|
28
|
+
|
29
|
+
var onThisPageEntryDraft = document.createElement('ul');
|
30
|
+
onThisPageEntryDraft.className = 'list-group';
|
31
|
+
|
32
|
+
var firstH2 = true;
|
33
|
+
var accordionContainer = document.createElement('div');
|
34
|
+
accordionContainer.className = 'accordion';
|
35
|
+
|
36
|
+
// Scan the content to generate On This Page list and style blockquotes
|
37
|
+
for (i = 0; i < originalChildren.length; i++) {
|
38
|
+
var node = originalChildren[i];
|
30
39
|
if (node.nodeName == 'H1' && !taglinePlaced && typeof siteTitle === 'string' && siteTitle.length > 0){
|
31
40
|
var newTagline = document.createElement('span');
|
32
41
|
newTagline.textContent = 'from ' + siteTitle;
|
@@ -47,23 +56,82 @@ function parseRawEntry(originalContent, onThisPageEntry, siteTitle, siteTagline)
|
|
47
56
|
}
|
48
57
|
|
49
58
|
// Create "On This Page entry"
|
59
|
+
var newLi = document.createElement('li');
|
60
|
+
newLi.className = 'list-group-item';
|
50
61
|
var newA = document.createElement('a');
|
51
62
|
newA.href = '#' + node.id;
|
52
|
-
newA.className = '
|
53
|
-
newA.setAttribute('
|
63
|
+
newA.className = 'nav-link text-truncate';
|
64
|
+
newA.setAttribute('data-bs-dismiss', 'offcanvas');
|
65
|
+
newA.setAttribute('data-bs-target', '#_ham_sidebar');
|
66
|
+
newA.setAttribute('onclick', 'expandAccordion(\'' + currentAccordionId + '\', \'' + node.id + '\')');
|
54
67
|
for (j = 2; j < currentHeadingLevel; j++){
|
55
68
|
var newSpan = document.createElement('span');
|
56
|
-
|
69
|
+
if (j == currentHeadingLevel - 1) {
|
70
|
+
newSpan.className = 'me-1 d-inline-block text-body-tertiary';
|
71
|
+
newSpan.innerHTML = '<i class="bi bi-arrow-return-right"></i>';
|
72
|
+
} else {
|
73
|
+
newSpan.className = 'ms-3 d-inline-block';
|
74
|
+
}
|
57
75
|
newSpan.setAttribute('aria-hidden', true);
|
58
76
|
newA.appendChild(newSpan);
|
59
77
|
}
|
60
78
|
newA.appendChild(document.createTextNode(node.textContent));
|
61
|
-
|
79
|
+
newLi.appendChild(newA)
|
80
|
+
onThisPageEntryDraft.appendChild(newLi);
|
81
|
+
}
|
82
|
+
if (node.nodeName == 'BLOCKQUOTE') {
|
83
|
+
var blockquoteChildren = node.childNodes;
|
84
|
+
node.className = 'alert';
|
85
|
+
var firstP = true;
|
86
|
+
for (j = 0; j < blockquoteChildren.length; j++) {
|
87
|
+
// Support GitHub-style Note, Important, and Warning blockquote style
|
88
|
+
if (blockquoteChildren[j].nodeName == 'P' && firstP) {
|
89
|
+
switch (blockquoteChildren[j].textContent) {
|
90
|
+
case '[!NOTE]':
|
91
|
+
node.className += ' alert-primary';
|
92
|
+
blockquoteChildren[j].className = ' fs-5 fw-bolder text-primary';
|
93
|
+
blockquoteChildren[j].innerHTML = '<i class="bi bi-info-circle"></i> Note';
|
94
|
+
break;
|
95
|
+
case '[!TIP]':
|
96
|
+
node.className += ' alert-success';
|
97
|
+
blockquoteChildren[j].className = ' fs-5 fw-bolder text-success';
|
98
|
+
blockquoteChildren[j].innerHTML = '<i class="bi bi-lightbulb"></i> Tip';
|
99
|
+
break;
|
100
|
+
case '[!IMPORTANT]':
|
101
|
+
node.className += ' alert-info';
|
102
|
+
blockquoteChildren[j].className = ' fs-5 fw-bolder text-info';
|
103
|
+
blockquoteChildren[j].innerHTML = '<i class="bi bi-exclamation-diamond"></i> Important';
|
104
|
+
break;
|
105
|
+
case '[!WARNING]':
|
106
|
+
node.className += ' alert-warning';
|
107
|
+
blockquoteChildren[j].className = ' fs-5 fw-bolder text-warning';
|
108
|
+
blockquoteChildren[j].innerHTML = '<i class="bi bi-exclamation-triangle"></i> Warning';
|
109
|
+
break;
|
110
|
+
case '[!CAUTION]':
|
111
|
+
node.className += ' alert-danger';
|
112
|
+
blockquoteChildren[j].className = ' fs-5 fw-bolder text-danger';
|
113
|
+
blockquoteChildren[j].innerHTML = '<i class="bi bi-exclamation-octagon"></i> Caution';
|
114
|
+
break;
|
115
|
+
default:
|
116
|
+
node.className += ' alert-secondary';
|
117
|
+
}
|
118
|
+
firstP = false;
|
119
|
+
}
|
120
|
+
}
|
62
121
|
}
|
63
122
|
}
|
123
|
+
|
124
|
+
// Rescan the content to create collapsible headings
|
125
|
+
var children = originalContent.cloneNode(true).childNodes;
|
64
126
|
for (i = 0; i < children.length; i++){
|
65
127
|
var node = children[i];
|
66
128
|
if (node.nodeName === 'H2'){
|
129
|
+
if (firstH2) {
|
130
|
+
// Delete the original children to create a new accordion container
|
131
|
+
for (j = i; j < originalChildren.length; j++) originalChildren[j].remove();
|
132
|
+
firstH2 = false;
|
133
|
+
}
|
134
|
+
|
67
135
|
var start = i; end = i;
|
68
136
|
var collapseChildren = [];
|
69
137
|
while (end + 1 < children.length && children[end + 1].nodeName !== 'H2') end++;
|
@@ -77,21 +145,38 @@ function parseRawEntry(originalContent, onThisPageEntry, siteTitle, siteTagline)
|
|
77
145
|
}
|
78
146
|
|
79
147
|
// Create actual collapse
|
80
|
-
var newDetails = document.createElement('
|
81
|
-
newDetails.className = '
|
82
|
-
var newSummary = document.createElement('summary');
|
83
|
-
newSummary.className = 'collapse-header font-size-20 h2';
|
84
|
-
newSummary.innerHTML = node.innerHTML;
|
85
|
-
var newDiv = document.createElement('div');
|
86
|
-
newDiv.className = 'collapse-content';
|
87
|
-
for (j = 0; j < collapseChildren.length; j++) newDiv.appendChild(collapseChildren[j]);
|
88
|
-
newDetails.appendChild(newSummary);
|
89
|
-
newDetails.appendChild(newDiv);
|
90
|
-
|
148
|
+
var newDetails = document.createElement('div')
|
149
|
+
newDetails.className = 'accordion-item';
|
91
150
|
newDetails.id = children[i].id;
|
92
|
-
|
151
|
+
var newSummary = document.createElement('h2');
|
152
|
+
newSummary.className = 'accordion-header';
|
153
|
+
var newSummaryButton = document.createElement('button');
|
154
|
+
newSummaryButton.className = 'accordion-button fs-4';
|
155
|
+
newSummaryButton.setAttribute('type', 'button');
|
156
|
+
newSummaryButton.setAttribute('data-bs-toggle', 'collapse');
|
157
|
+
newSummaryButton.setAttribute('data-bs-target', '#' + children[i].id + "-content");
|
158
|
+
newSummaryButton.setAttribute('aria-expanded', 'true');
|
159
|
+
newSummaryButton.setAttribute('aria-controls', children[i].id + "-content");
|
160
|
+
newSummaryButton.setAttribute('type', 'button');
|
161
|
+
newSummaryButton.setAttribute('type', 'button');
|
162
|
+
newSummaryButton.innerHTML = node.innerHTML;
|
163
|
+
newSummary.appendChild(newSummaryButton);
|
164
|
+
|
165
|
+
var newCollapse = document.createElement('div');
|
166
|
+
newCollapse.className = 'accordion-collapse collapse show';
|
167
|
+
newCollapse.id = children[i].id + "-content";
|
168
|
+
var newBody = document.createElement('div');
|
169
|
+
newBody.className = 'accordion-body';
|
170
|
+
for (j = 0; j < collapseChildren.length; j++) newBody.appendChild(collapseChildren[j]);
|
171
|
+
newCollapse.appendChild(newBody);
|
172
|
+
newDetails.appendChild(newSummary);
|
173
|
+
newDetails.appendChild(newCollapse);
|
174
|
+
accordionContainer.appendChild(newDetails);
|
93
175
|
}
|
94
176
|
}
|
177
|
+
|
178
|
+
originalContent.appendChild(accordionContainer);
|
179
|
+
onThisPageEntry.appendChild(onThisPageEntryDraft);
|
95
180
|
}
|
96
181
|
|
97
182
|
var _ham_state_is_all_accordion_collapsed = true;
|
@@ -110,9 +195,14 @@ function autoexpandAccordion(){
|
|
110
195
|
}
|
111
196
|
}
|
112
197
|
|
113
|
-
function expandAccordion(
|
114
|
-
var el = document.getElementById(
|
115
|
-
el.
|
198
|
+
async function expandAccordion(collapsibleId, contentId){
|
199
|
+
var el = new bootstrap.Collapse(document.getElementById(collapsibleId + "-content"), {toggle: false});
|
200
|
+
await el.show();
|
201
|
+
if (contentId) {
|
202
|
+
location.hash = "";
|
203
|
+
location.hash = "#" + contentId;
|
204
|
+
scrollBy(0, -66);
|
205
|
+
}
|
116
206
|
}
|
117
207
|
|
118
208
|
window.addEventListener("load", autoexpandAccordion);
|