-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpost.hbs
497 lines (466 loc) · 24 KB
/
post.hbs
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
{{> head}}
{{> navbar}}
<main class="post">
<div class="wrapper">
{{#if @customHTML.beforePost}}
<div class="banner banner--before-content">
{{{@customHTML.beforePost }}}
</div>
{{/if}}
{{#post}}
<article class="content">
<header class="content__header">
{{#if @config.post.displayCategoryName}}
{{#if mainTag}}
<a href="{{ mainTag.url }}" class="content__maintag">
{{mainTag.name }}
</a>
{{/if}}
{{/if}}
<h1 class="content__title">
{{title}}
</h1>
{{#checkIfAny @config.post.displayAuthor @config.post.displayDate @config.post.displayComments}}
<div class="content__meta">
{{#if @config.post.displayAuthor}}
<div class="content__author">{{ translate 'post.publishedBy' }}
{{#author}}
<a href="{{url}}" class="invert" rel="author" title="{{name}}">{{name}}</a>
{{/author}}
</div>
{{/if}}
{{#if @config.post.displayDate}}
<time datetime="{{date createdAt 'YYYY-MM-DDTHH:mm'}}">
{{#checkIf @config.custom.formatDate '!=' 'custom'}}
{{date createdAt @config.custom.formatDate}}
{{else}}
{{date createdAt @config.custom.formatDateCustom}}
{{/checkIf}}
</time>
{{/if}}
{{#if @config.post.displayComments}}
<div class="content__comments">
<a href="{{url}}#comments" rel="nofollow" aria-label="{{ translate 'common.comments' }}">
<svg aria-hidden="true">
<title>{{ translate 'common.comments' }}</title>
<use xlink:href="{{@website.assetsUrl}}/svg/svg-map.svg#comments"/>
</svg>
</a>
</div>
{{/if}}
</div>
{{/checkIfAny}}
</header>
{{#featuredImage}}
{{#if url}}
<figure class="content__featured-image">
<img
src="{{url}}"
{{#if @config.site.responsiveImages}}
{{responsiveImageAttributes 'featuredImage' srcset sizes}}
{{/if}}
{{ lazyload "eager" }}
height="{{height}}"
width="{{width}}"
alt="{{alt}}">
{{#checkIfAny caption credits}}
<figcaption>
{{caption}}
{{credits}}
</figcaption>
{{/checkIfAny}}
</figure>
{{/if}}
{{/featuredImage}}
<div class="content__inner">
{{#if @config.custom.pdfDownloadButton}}
<button style="margin: 0px 20px 20px 30px; align-items: center;" class="pdf-download-button"><img src="./assets/svg/filetype-pdf.svg" alt="Icon"><span style="margin-left: 8px;">Download PDF</span></button>
{{/if}}
{{#if @config.custom.copyCitation}}
<button class="citation-copy-button"><img src="./assets/svg/quote.svg" alt="Icon"><span style="margin-left: 8px;">Copy Citation</span></button>
{{/if}}
<div class="content__entry">
{{{text}}}
</div>
{{#checkIfAny @config.post.displayLastUpdatedDate @config.post.displayTags @config.post.displayShareButtons @config.post.displayAuthorBio @config.post.displayPostNavigation}}
<footer>
{{#if @config.post.displayLastUpdatedDate}}
{{#if modifiedAt}}
<p class="content__last-updated">
{{ translate 'post.lastUpdatedDate' }}
{{#checkIf @config.custom.formatDate '!=' 'custom'}}
{{date modifiedAt @config.custom.formatDate}}
{{else}}
{{date modifiedAt @config.custom.formatDateCustom}}
{{/checkIf}}
</p>
{{/if}}
{{/if}}
{{#checkIfAny @config.post.displayTags @config.post.displayShareButtons}}
<div class="content__tags-share">
{{#if @config.post.displayTags}}
{{#if tags}}
<ul class="content__tag">
{{#each tags}}
<li>
<a href="{{url}}">{{name}}</a>
</li>
{{/each}}
</ul>
{{/if}}
{{/if}}
{{#if @config.post.displayShareButtons}}
{{#checkIfAll @plugins.socialSharing @plugins.socialSharing.state}}
<aside class="content__share">
{{{@customSocialSharing}}}
</aside>
{{else}}
<aside class="content__share">
{{> share-buttons}}
</aside>
{{/checkIfAll}}
{{/if}}
</div>
{{/checkIfAny}}
{{#if @config.post.displayAuthorBio}}
{{#author}}
<div class="content__bio bio">
{{#if avatar}}
<img
src="{{avatarImage.url}}"
{{ lazyload "lazy" }}
height="{{avatarImage.height}}"
width="{{avatarImage.width}}"
class="bio__avatar"
alt="{{avatarImage.alt}}">
{{/if}}
<div>
{{#if name}}
<h3 class="h6 bio__name">
<a href="{{url}}" class="invert" title="{{name}}">{{name}}</a>
</h3>
{{/if}}
{{#if description}}
<div class="bio__desc">{{{description}}}</div>
{{/if}}
</div>
</div>
{{/author}}
{{/if}}
{{#if @config.post.displayPostNavigation}}
{{#checkIfAny ../previousPost ../nextPost}}
<nav class="content__nav">
{{#../previousPost}}
<div class="content__nav__prev">
<a class="content__nav__link" href="{{url}}" rel="prev">
{{ translate 'post.previousPost' }}
<h3 class="h6">{{title}}</h3>
</a>
</div>
{{/../previousPost}}
{{#../nextPost}}
<div class="content__nav__next">
<a class="content__nav__link" href="{{url}}" rel="prev">
{{ translate 'post.nextPost' }}
<h3 class="h6">{{title}}</h3>
</a>
</div>
{{/../nextPost}}
</nav>
{{/checkIfAny}}
{{/if}}
</footer>
{{/checkIfAny}}
</div>
</article>
{{/post}}
{{#if @config.post.displayComments}}
<div class="comments-area content__inner" id="comments">
{{{@commentsCustomCode}}}
</div>
{{/if}}
{{#if @customHTML.afterPost}}
<div class="banner banner--after-content">
{{{@customHTML.afterPost}}}
</div>
{{/if}}
</div>
{{#if @config.post.displayRelatedPosts}}
{{#if relatedPosts}}
<div class="content__related">
<div class="wrapper">
<h2 class="h5">
{{ translate 'post.relatedPosts' }}
</h2>
<div class="l-grid l-grid--4">
{{#each relatedPosts}}
<article class="c-card">
{{#if @config.custom.cardsImage}}
{{#featuredImage}}
{{#if url}}
<a href="{{../url}}" class="c-card__image">
<img
src="{{url}}"
{{#if @config.site.responsiveImages}}
{{responsiveImageAttributes 'featuredImage' srcset sizes}}
{{/if}}
{{ lazyload "lazy" }}
height="{{height}}"
width="{{width}}"
alt="{{alt}}">
</a>
{{/if}}
{{/featuredImage}}
{{/if}}
<div class="c-card__wrapper">
<header class="c-card__header">
{{#if @config.custom.cardsTag}}
{{#if mainTag}}
<div class="c-card__tag">
<a href="{{ mainTag.url }}">{{ mainTag.name }}</a>
</div>
{{/if}}
{{/if}}
<h3 class="c-card__title">
<a href="{{url}}" class="invert">
{{title}}
</a>
</h3>
</header>
{{#if @config.custom.cardsExcerpt}}
<p class="c-card__text">{{{ excerpt }}}</p>
{{/if}}
{{#checkIfAny @config.custom.cardsDate @config.custom.cardsComments}}
<footer class="c-card__meta">
{{#if @config.custom.cardsDate}}
<time datetime="{{date createdAt 'YYYY-MM-DDTHH:mm'}}">
{{#checkIf @config.custom.formatDate '!=' 'custom'}}
{{date createdAt @config.custom.formatDate}}
{{else}}
{{date createdAt @config.custom.formatDateCustom}}
{{/checkIf}}
</time>
{{/if}}
{{#if @config.custom.cardsComments}}
<div class="c-card__comments">
<a href="{{url}}#comments" rel="nofollow" aria-label="{{ translate 'common.comments' }}">
<svg aria-hidden="true">
<title>{{ translate 'common.comments' }}</title>
<use xlink:href="{{@website.assetsUrl}}/svg/svg-map.svg#comments"/>
</svg>
</a>
</div>
{{/if}}
</footer>
{{/checkIfAny}}
</div>
</article>
{{/each}}
</div>
</div>
</div>
{{/if}}
{{/if}}
</main>
{{> footer}}
{{#if @config.custom.pdfDownloadButton}}
<script src="{{@website.assetsUrl}}/js/jspdf.umd.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
// Ensure jsPDF is available
if (window.jspdf) {
const { jsPDF } = window.jspdf;
// Attach event listener to the button
const button = document.querySelector('.pdf-download-button');
if (button) {
button.addEventListener('click', function () {
const doc = new jsPDF({ format: 'a4' });
const pageWidth = doc.internal.pageSize.getWidth();
const pageHeight = doc.internal.pageSize.getHeight();
const margin = 20;
let y = margin;
// Retrieve the title and content
const postTitle = document.querySelector('h1')?.innerText || 'Document';
let content = document.querySelector('.post__entry') || document.querySelector('.content__entry');
// If no content is found, exit
if (!content) return;
// Add the title to the PDF
doc.setFont('{{@config.custom.headingFont}}', 'bold');
doc.setFontSize({{@config.custom.titleFontSize}});
const wrappedTitle = doc.splitTextToSize(postTitle, pageWidth - 2 * margin);
doc.text(wrappedTitle, pageWidth / 2, y, { align: 'center' });
y += {{@config.custom.titleFontSize}} + 10;
// Process content elements
doc.setFont('{{@config.custom.contentFont}}', 'normal');
doc.setFontSize({{@config.custom.contentFontSize}});
const elements = content.children;
function processElement(element) {
const tagName = element.tagName.toLowerCase();
switch (tagName) {
case 'h1':
doc.setFontSize({{@config.custom.h1FontSize}});
doc.setFont('{{@config.custom.headingFont}}', '{{@config.custom.headingFontWeight}}');
y += 5;
break;
case 'h2':
doc.setFontSize({{@config.custom.h2FontSize}});
doc.setFont('{{@config.custom.headingFont}}', '{{@config.custom.headingFontWeight}}');
y += 5;
break;
case 'h3':
doc.setFontSize({{@config.custom.h3FontSize}});
doc.setFont('{{@config.custom.headingFont}}', '{{@config.custom.headingFontWeight}}');
y += 5;
break;
case 'h4':
doc.setFontSize({{@config.custom.h4FontSize}});
doc.setFont('{{@config.custom.headingFont}}', '{{@config.custom.headingFontWeight}}');
y += 5;
break;
case 'h5':
doc.setFontSize({{@config.custom.h5FontSize}});
doc.setFont('{{@config.custom.headingFont}}', '{{@config.custom.headingFontWeight}}');
y += 5;
break;
case 'h6':
doc.setFontSize({{@config.custom.h6FontSize}});
doc.setFont('{{@config.custom.headingFont}}', '{{@config.custom.headingFontWeight}}');
y += 5;
break;
case 'strong':
doc.setFont('{{@config.custom.headingFont}}', 'bold');
break;
case 'em':
doc.setFont('{{@config.custom.headingFont}}', 'italic');
break;
case 'u':
doc.setFont('{{@config.custom.headingFont}}', 'normal');
break;
case 'p':
default:
doc.setFontSize({{@config.custom.contentFontSize}});
doc.setFont('{{@config.custom.contentFont}}', 'normal');
}
// Handle inline formatting within paragraphs (strong, em, etc.)
const childNodes = element.childNodes;
let textContent = '';
let inlineText = '';
childNodes.forEach(node => {
if (node.nodeType === Node.TEXT_NODE) {
inlineText = node.nodeValue;
textContent += inlineText;
} else if (node.nodeType === Node.ELEMENT_NODE) {
const tagName = node.tagName.toLowerCase();
// Check for inline tags (strong, em, u)
if (tagName === 'strong') {
doc.setFont('{{@config.custom.contentFont}}', 'bold');
inlineText = node.innerText;
textContent += inlineText;
} else if (tagName === 'em') {
doc.setFont('{{@config.custom.contentFont}}', 'italic');
inlineText = node.innerText;
textContent += inlineText;
} else if (tagName === 'u') {
doc.setFont('{{@config.custom.contentFont}}', 'normal');
inlineText = node.innerText;
textContent += inlineText;
} else {
inlineText = node.innerText;
textContent += inlineText;
}
}
});
// Handle the text content of the element
const text = element.innerText.trim();
if (text) {
const lines = doc.splitTextToSize(text, pageWidth - 2 * margin);
lines.forEach(line => {
if (y + {{@config.custom.contentFontSize}} > pageHeight - margin) {
doc.addPage();
y = margin;
}
doc.text(line, margin, y);
y += {{@config.custom.contentFontSize}} * {{@config.custom.lineSpacing}};
});
}
// Reset font style after processing the element
doc.setFont('helvetica', 'normal');
}
// Loop through all content elements and process them
Array.from(elements).forEach(el => processElement(el));
// Optionally include images
if ({{@config.custom.includeImages}}) {
const images = content.querySelectorAll('img');
images.forEach(image => {
const imgSrc = image.src;
const altText = image.alt || 'View image';
if (y > pageHeight - margin) {
doc.addPage();
y = margin;
}
doc.setTextColor(0, 0, 255);
doc.textWithLink(altText, margin, y, { url: imgSrc });
doc.setTextColor(0, 0, 0);
y += 10;
});
}
// Save the generated PDF
const fileName = postTitle.replace(/[^a-z0-9]/gi, '_').toLowerCase();
doc.save(fileName + '.pdf');
});
}
}
});
</script>
{{/if}}
{{#if @config.custom.copyCitation}}
<script>
document.addEventListener('DOMContentLoaded', function() {
const copyButton = document.querySelector('.citation-copy-button');
copyButton?.addEventListener('click', function() {
const author = "{{#post}}{{#author}}{{name}}{{/author}}{{/post}}"; // Replace with dynamic author fetching if available
const title = "{{#post}}{{title}}{{/post}}";
const website = "{{@website.name}}";
const pubDate = "{{date createdAt 'MMMM D, YYYY'}}"; // Replace with dynamic publication date if available
const url = "{{@website.pageUrl}}";
// Construct the citation in the standard format
const citation = `${author}. "${title}." ${website}, ${pubDate}, ${url}.`;
// Copy citation to the clipboard
navigator.clipboard.writeText(citation).then(() => {
alert("Citation copied to clipboard!");
}).catch(err => {
console.error("Error copying citation:", err);
});
});
});
</script>
{{/if}}
{{#if @config.custom.copyProtectionCredits}}
<script>
document.addEventListener('copy', function(event) {
// Function to get the current date in "Month Day, Year" format
function getCurrentDate() {
const options = { day: 'numeric', month: 'long', year: 'numeric' };
return new Date().toLocaleDateString('en-US', options);
}
const author = "{{#post}}{{#author}}{{name}}{{/author}}{{/post}}";
const title = "{{#post}}{{title}}{{/post}}";
const website = "{{@website.name}}";
const pubDate = "{{date createdAt 'MMMM D, YYYY'}}";
const url = "{{@website.pageUrl}}";
const accessedDate = getCurrentDate();
const sitename = "{{@website.rootUrl}}";
const currentYear = new Date().getFullYear();
// Construct the citation
const citation = `\n\n© ${currentYear} ${sitename}.\nCitation: ${author}. "${title}." ${website}, ${pubDate}, ${url}. Accessed on ${accessedDate}. This content is copied from ${sitename}`;
// Check if there's any selected text
const selection = window.getSelection().toString();
if (selection) {
// Append the citation to the copied content
const copiedText = `${selection}${citation}`;
event.clipboardData.setData('text/plain', copiedText);
event.preventDefault(); // Prevent the default copy behavior
}
});
</script>
{{/if}}