-
-
Notifications
You must be signed in to change notification settings - Fork 581
Expand file tree
/
Copy pathpost.hbs
More file actions
296 lines (254 loc) · 10.1 KB
/
post.hbs
File metadata and controls
296 lines (254 loc) · 10.1 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
{{!< default}}
{{!-- Everything inside the #post tags pulls data from the post --}}
{{#post}}
<div class="progress-container">
<span class="progress-bar"></span>
</div>
<header class="post-header {{#if feature_image}} has-cover {{/if}}">
<div class="inner">
<span class="post-info">
<span class="post-type">{{t "Article"}}</span>
{{#if tags}}
<span class="post-count">{{primary_tag.name}}</span>
{{/if}}
</span>
<h1 class="post-title">{{{title}}}</h1>
<div class="post-meta">
<div class="post-meta-avatars">
{{#foreach authors}}
{{#if profile_image}}
<figure class="post-meta-avatar">
<a href="{{url}}" class="author-avatar">
<img class="author-profile-image" src="{{img_url profile_image size="xs"}}" alt="{{name}}" />
</a>
</figure>
{{else}}
<figure class="post-meta-avatar avatar"></figure>
{{/if}}
{{/foreach}}
</div>
<h4 class="post-meta-author">{{authors separator=", "}}</h4>
<time datetime="{{date format='DD-MM-YYYY'}}">{{date format="DD MMM YYYY"}}</time> • {{reading_time minute=(t "1 min read") minutes=(t "% min read")}}
</div>
{{#if feature_image}}
<div class="post-cover cover">
<img
srcset="{{img_url feature_image size="s"}} 320w,
{{img_url feature_image size="m"}} 640w,
{{img_url feature_image size="l"}} 960w,
{{img_url feature_image size="xl"}} 1920w"
src="{{img_url feature_image size="xl"}}"
alt="{{title}}" />
</div>
{{/if}}
</div>
</header>
<main class="content" role="main">
<article class="{{post_class}}">
<div class="inner">
<section class="post-content">
{{content}}
</section>
<section class="post-footer">
{{#match @custom.post_share "Native"}}
<div class="post-share">
<span class="post-info-label">{{t "Share"}}</span>
<button aria-label="{{t "Share"}} {{t "Article"}}" class="post-share-button" id="share-button"><i class="icon icon-share" aria-hidden="true">{{> "icons/icon-share"}}</i></button>
</div>
{{/match}}
{{#match @custom.post_share "Default"}}
<div class="post-share">
<span class="post-info-label">{{t "Share"}}</span>
<a title="Twitter" aria-label="Twitter" class="twitter" href="https://twitter.com/share?text={{title}}&url={{url absolute="true"}}" onclick="window.open(this.href, 'twitter-share', 'width=550,height=235');return false;">
<i class="icon icon-twitter" aria-hidden="true">{{> "icons/icon-twitter"}}</i>
</a>
<a title="Facebook" aria-label="Facebook" class="facebook" href="https://www.facebook.com/sharer/sharer.php?u={{url absolute="true"}}" onclick="window.open(this.href, 'facebook-share','width=580,height=296');return false;">
<i class="icon icon-facebook" aria-hidden="true">{{> "icons/icon-facebook"}}</i>
</a>
<a title="LinkedIn" aria-label="LinkedIn" class="linkedin" href="https://www.linkedin.com/shareArticle?mini=true&url={{url absolute="true"}}/&title={{title}}" onclick="window.open(this.href, 'linkedin-share', 'width=930,height=720');return false;">
<i class="icon icon-linkedin" aria-hidden="true">{{> "icons/icon-linkedin"}}</i>
</a>
<a title="Email" aria-label="Email" class="email" href="mailto:?subject={{title}}&body={{url absolute="true"}}">
<i class="icon icon-mail" aria-hidden="true">{{> "icons/icon-mail"}}</i>
</a>
</div>
{{/match}}
{{#if tags}}
<aside class="post-tags">
<span class="post-info-label">{{t "Topic"}}</span>
{{tags separator=" "}}
</aside>
{{/if}}
</section>
{{#if @custom.disqus_shortname}}
<section class="post-comments">
<div id="disqus_thread"></div>
</section>
{{/if}}
{{#if comments}}
<section class="post-comments">
{{comments}}
</section>
{{/if}}
{{#if @labs.subscribers}}
<section class="post-subscribe">
<p>{{t "Get the latest posts delivered right to your inbox."}}</p>
{{subscribe_form placeholder=(t "Your email address") form_class="post-subscribe-form" input_class="post-subscribe-input" button_class="post-subscribe-button"}}
</section>
{{/if}}
{{!-- Links to Previous/Next posts --}}
<aside class="post-nav">
{{!-- If there's a next post, display it using the same markup included from - partials/post-card.hbs --}}
{{#next_post}}
<a class="post-nav-next" href="{{url}}">
<section class="post-nav-teaser">
<i class="icon icon-arrow-left" aria-label="{{t "Next post"}}">{{> "icons/icon-arrow-left"}}</i>
<h2 class="post-nav-title">{{title}}</h2>
<p class="post-nav-excerpt">{{excerpt words="12"}}…</p>
<p class="post-nav-meta"><time datetime="{{date format='DD-MM-YYYY'}}">{{date format="DD MMM YYYY"}}</time></p>
</section>
</a>
{{/next_post}}
{{!-- If there's a previous post, display it using the same markup included from - partials/post-card.hbs --}}
{{#prev_post}}
<a class="post-nav-prev" href="{{url}}">
<section class="post-nav-teaser">
<i class="icon icon-arrow-right" aria-label="{{t "Previous post"}}">{{> "icons/icon-arrow-right"}}</i>
<h2 class="post-nav-title">{{title}}</h2>
<p class="post-nav-excerpt">{{excerpt words="12"}}…</p>
<p class="post-nav-meta"><time datetime="{{date format='DD-MM-YYYY'}}">{{date format="DD MMM YYYY"}}</time></p>
</section>
</a>
{{/prev_post}}
<div class="clear"></div>
</aside>
</div>
</article>
</main>
{{/post}}
{{!-- The #contentFor helper here will send everything inside it up to the matching #block helper found in default.hbs --}}
{{#contentFor "scripts"}}
<script>
document.addEventListener("DOMContentLoaded", function () {
//responsive videos
const sources = [
'.post-content iframe[src*="youtube.com"]',
'.post-content iframe[src*="youtube-nocookie.com"]',
'.post-content iframe[src*="player.vimeo.com"]',
'.post-content iframe[src*="kickstarter.com"][src*="video.html"]',
'.post-content object',
'.post-content embed',
];
reframe(document.querySelectorAll(sources.join(',')));
});
{{#if @custom.disqus_shortname}}
var disqus = '{{@custom.disqus_shortname}}';
function launchDisqus() {
// Dynamically load the Disqus embed script
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '//' + disqus + '.disqus.com/embed.js';
script.async = true;
script.setAttribute('data-timestamp', +new Date());
script.onload = function() {
console.log('Disqus script loaded successfully.');
};
// Append the script to the document head
document.head.appendChild(script);
// Add the 'activated' class to the parent of the triggering element
var parent = document.querySelector('.disqus-button'); // Replace with the correct triggering element
if (parent) {
parent.classList.add('activated');
}
}
// Execute the function
launchDisqus();
{{/if}}
{{#match @custom.post_share "Native"}}
document.getElementById('share-button').addEventListener('click', async () => {
try {
await navigator.share({
//title: 'Title',
//text: 'Text',
url: '{{url absolute="true"}}',
});
console.log('Data was shared successfully');
} catch (err) {
console.error('error:', err.message);
}
});
{{/match}}
document.addEventListener("DOMContentLoaded", function () {
// Format code blocks and add line numbers
function codestyling() {
// Select all `pre code` elements
document.querySelectorAll('pre code').forEach(function (codeBlock) {
// Code highlight
hljs.highlightElement(codeBlock);
// Skip plain text blocks
if (!codeBlock.classList.contains('language-text')) {
// Calculate the number of lines
var lines = codeBlock.innerHTML.split(/\n(?!$)/g).length;
if (lines > 1) lines++; // Account for extra line
// Generate line numbers
var numbers = Array.from({ length: lines - 1 }, (_, i) => {
return `<span class="line" aria-hidden="true">${i + 1}</span>`;
}).join('');
// Create and append the lines container
var linesContainer = document.createElement('div');
linesContainer.className = 'lines';
linesContainer.innerHTML = numbers;
codeBlock.parentNode.appendChild(linesContainer);
}
});
}
codestyling();
});
document.addEventListener("DOMContentLoaded", function () {
var post = document.querySelector('.post-content');
var progressBar = document.querySelector('.progress-bar');
var progressContainer = document.querySelector('.progress-container');
// Helper to calculate the element's position relative to the document
function getOffsetTop(element) {
var rect = element.getBoundingClientRect();
return rect.top + window.scrollY;
}
// Reading progress bar on window top
function readingProgress() {
if (!post || !progressBar || !progressContainer) return;
var postBottom = getOffsetTop(post) + post.offsetHeight;
var viewportHeight = window.innerHeight;
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
// Calculate progress
var progress = 100 - (((postBottom - (scrollTop + viewportHeight) + viewportHeight / 3) /
(postBottom - viewportHeight + viewportHeight / 3)) * 100);
// Update progress bar width
progressBar.style.width = Math.min(progress, 100) + '%';
// Add or remove the 'complete' class
if (progress > 100) {
progressContainer.classList.add('complete');
} else {
progressContainer.classList.remove('complete');
}
}
// Initial call
readingProgress();
// Throttle function to optimize scroll and resize events
function throttle(callback, delay) {
var lastCall = 0;
return function () {
var now = Date.now();
if (now - lastCall >= delay) {
lastCall = now;
callback();
}
};
}
// Attach scroll, resize, and orientationchange events
var optimizedReadingProgress = throttle(readingProgress, 50);
window.addEventListener('scroll', optimizedReadingProgress);
window.addEventListener('resize', optimizedReadingProgress);
window.addEventListener('orientationchange', optimizedReadingProgress);
});
</script>
{{/contentFor}}