-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
72 lines (64 loc) · 2.37 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>My Blazing Blog</title>
<link rel="stylesheet" href="styles.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.6/handlebars.min.js"></script>
</head>
<body>
<div class="align-right">
<button id="theme-resume" onclick="window.location.href = 'https://blazingvx.github.io/resume/';">Resume</button>
<button id="theme-toggle">Toggle Theme</button>
</div>
<div id="blog-container">
<!-- Blog posts will be inserted here -->
</div>
<script src="data.js"></script>
<script id="blog-template" type="text/x-handlebars-template">
{{> blogPost}}
</script>
<script id="blog-post-template" type="text/x-handlebars-template">
<article>
<h2>{{title}}</h2>
{{#if imageUrl}}
<center>
<img src="{{imageUrl}}" alt="{{imageAltText}} width="100" height="100"">
</center>
{{/if}}
<p>{{{content}}}</p>
<!--<p>{{truncate content 100}}</p> -->
{{#if link}}
<a href="{{link}}" target="_blank">See More...</a>
{{/if}}
<p><em>Posted by {{author}} on {{date}}</em></p>
</article>
</script>
<script>
// Define the truncate Handlebars helper function
Handlebars.registerHelper('truncate', function(str, len) {
if (str.length > len) {
let newStr = str.substr(0, len + 1);
// Trim the string to the last word
newStr = newStr.substr(0, Math.min(newStr.length, newStr.lastIndexOf(" ")));
// Add ellipsis if the string was truncated
if (newStr.length < str.length) {
newStr += '...';
}
return new Handlebars.SafeString(newStr);
}
return str;
});
Handlebars.registerPartial('blogPost', document.getElementById('blog-post-template').innerHTML);
const blogTemplate = Handlebars.compile(document.getElementById("blog-template").innerHTML);
const blogContainer = document.getElementById("blog-container");
blogPosts.forEach((post) => {
blogContainer.innerHTML += blogTemplate(post);
});
const themeToggle = document.getElementById("theme-toggle");
const body = document.body;
themeToggle.addEventListener("click", () => {
body.classList.toggle("dark-theme");
});
</script>
</body>
</html>