-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblog.html
More file actions
188 lines (162 loc) · 5.64 KB
/
blog.html
File metadata and controls
188 lines (162 loc) · 5.64 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ETA Blogs</title>
<link rel="stylesheet" href="https://unpkg.com/xp.css" />
<style>
body {
background-image: url('./img/bliss-winxp.jpg');
background-size: cover;
background-position: center;
font-family: "Tahoma", sans-serif;
margin: 0;
padding: 20px;
display: flex;
justify-content: center;
gap: 10px;
height: 100vh;
box-sizing: border-box;
}
.blog-container {
display: flex;
gap: 10px;
width: 95vw;
max-width: 1000px;
height: 80vh;
}
.window {
display: flex;
flex-direction: column;
box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.5);
background: #ece9d8;
}
.window-body {
flex: 1;
overflow-y: auto;
padding: 8px;
display: flex;
flex-direction: column;
gap: 10px;
}
.sidebar {
width: 200px;
}
.sidebar button {
width: 100%;
margin-bottom: 5px;
text-align: left;
cursor: pointer;
font-weight: bold;
background: #e0e0e0;
border: 1px solid #808080;
padding: 3px 6px;
}
.sidebar button:active {
background: #c0c0c0;
border-top: 1px solid #404040;
border-left: 1px solid #404040;
}
.blog-title {
font-weight: bold;
font-size: 18px;
margin-bottom: 5px;
}
.blog-meta {
font-size: 12px;
color: #333;
margin-bottom: 10px;
}
.blog-caption {
font-style: italic;
margin-bottom: 10px;
}
.blog-content {
line-height: 1.5;
}
</style>
</head>
<body>
<div class="blog-container">
<!-- sidebar -->
<div class="window sidebar">
<div class="title-bar">
<div class="title-bar-text">bloglist.exe</div>
<div class="title-bar-controls">
<button aria-label="Minimize"></button>
<button aria-label="Maximize"></button>
<button aria-label="Close" onclick="window.location.href='index.html'"></button>
</div>
</div>
<div class="window-body" id="blog-list">
loading...
</div>
</div>
<!-- main -->
<div class="window main-window" style="flex:1">
<div class="title-bar">
<div class="title-bar-text">blogview.exe</div>
<div class="title-bar-controls">
<button aria-label="Minimize"></button>
<button aria-label="Maximize"></button>
<button aria-label="Close" onclick="window.location.href='index.html'"></button>
</div>
</div>
<div class="window-body" id="blog-display">
loading...
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
const owner = "ETAModder";
const repo = "etamodder.github.io";
const folder = "blogs";
let blogs = [];
async function loadBlogs() {
const listContainer = document.getElementById('blog-list');
const displayContainer = document.getElementById('blog-display');
listContainer.innerHTML = '';
displayContainer.innerHTML = '';
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}/contents/${folder}`);
const files = await res.json();
const mdFiles = files.filter(f => f.name.endsWith('.md'));
for (const file of mdFiles) {
try {
const rawRes = await fetch(file.download_url);
const text = await rawRes.text();
const match = text.match(/---\s*([\s\S]*?)\s*---\s*([\s\S]*)/);
if (!match) continue;
const frontmatter = match[1];
const content = match[2];
const metadata = Object.fromEntries(
frontmatter.split('\n').map(line => line.split(':').map(s => s.trim()))
);
blogs.push({ metadata, content });
} catch (e) {
console.error('failed to load blog:', file.name, e);
}
}
blogs.sort((a, b) => new Date(b.metadata.date) - new Date(a.metadata.date));
blogs.forEach((blog, index) => {
const btn = document.createElement('button');
btn.textContent = blog.metadata.title;
btn.onclick = () => displayBlog(index);
listContainer.appendChild(btn);
});
if (blogs.length) displayBlog(0);
}
function displayBlog(index) {
const displayContainer = document.getElementById('blog-display');
const blog = blogs[index];
displayContainer.innerHTML = `
<div class="blog-title">${blog.metadata.title}</div>
<div class="blog-meta">by ${blog.metadata.author} - ${blog.metadata.date}</div>
<div class="blog-caption"><i>${blog.metadata.caption}</i></div>
<div class="blog-content">${marked.parse(blog.content)}</div>
`;
}
loadBlogs();
</script>
</body>
</html>