include_file custom template

Custom Template - include_file

$line is current line of code
$index is current line index of code

1
2
3
4
5
6
7
8
9
10
11
12
<table>
<thead>
<tr>
<th>index</th><th>contents line</th>
</tr>
</thead>
<tbody>
{% include_file lang:javascript 'test.js' pretext:false %}
<tr><td>$index</td><td>$line</td></tr>
{% endinclude_file %}
</tbody>
</table>
indexcontents line
1// global variables
2const toMatch = new Date('2022-12-01T09:30:20');
3let data = `date to match: ${toMatch}
`;
4document.getElementById('variables').innerHTML = data;
5
6// method 1 using timestamp
7
8const yourDate = toMatch.getTime(); //Get the timestamp
9const today = Date.now();
10// 2 days in millisecond
11const day = 60 * 60 * 1000 * 24 * 2;
12data = `
13today: ${today}
14yourDate: ${yourDate}
152 days in millisecond: ${day}
16today - yourDate: ${today - yourDate}
17is greater than 2 days: ${today - yourDate > day ? 'true' : 'false'}`;
18document.getElementById('timestamp').innerHTML = data;
19
20// method 2 using hours
21const now = new Date();
22
23const msBetweenDates = Math.abs(toMatch.getTime() - now.getTime());
24
25// 👇️ convert ms to hours min sec ms
26const hoursBetweenDates = msBetweenDates / (60 * 60 * 1000);
27
28data = `
29hoursBetweenDates: ${hoursBetweenDates}
30date is within 24 hours: ${
31 hoursBetweenDates < 24 ? 'true' : 'false'
32}
33date is greater than 48 hours: ${
34 hoursBetweenDates > 48 ? 'true' : 'false'
35}
36`;
37document.getElementById('hours').innerHTML = data;
38
39// unused
40function _isOverEighteen(year = 0, month = 0, day = 0) {
41 var now = parseInt(new Date().toISOString().slice(0, 10).replace(/-/g, ''));
42 var dob = year * 10000 + month * 100 + day * 1; // Coerces strings to integers
43
44 return now - dob > 180000;
45}
46
avatar
Dimas Lanjaka (L3n4r0x)
All in one collection shortcodes for hexo
Follow Me
Announcement
This is my Blog
Recent Post
Info
Article :
0
UV :
PV :
Last Push :