-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.html
195 lines (189 loc) · 5.77 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Speaks</title>
<style>
/* Simple Hacker News–like styling */
body {
font-family: Verdana, sans-serif;
background-color: #f6f6ef;
margin: 0;
padding: 0;
}
.header {
background-color: #ff6600;
color: #000;
padding: 10px;
text-align: center;
font-size: 24px;
font-weight: bold;
}
.container {
width: 90%;
max-width: 800px;
margin: 20px auto;
}
.news-item {
padding: 8px 0;
border-bottom: 1px solid #e0e0e0;
}
.news-item a {
color: #000;
text-decoration: none;
font-size: 16px;
cursor: pointer;
}
.news-item a:hover {
text-decoration: underline;
}
.subtext {
margin-top: 4px;
color: #828282;
font-size: 12px;
}
/* Story container styling */
#story {
display: none;
padding: 10px;
background-color: #fff;
border: 1px solid #e0e0e0;
margin-bottom: 20px;
position: relative;
height: auto;
}
#close-story {
position: absolute;
top: 10px;
right: 10px;
background: #ff6600;
color: #000;
border: none;
padding: 5px 10px;
cursor: pointer;
font-size: 16px;
}
#story-content {
margin-top: 40px;
white-space: pre-wrap;
font-family: Verdana, sans-serif;
overflow: auto;
line-height: 2rem;
}
footer {
text-align: center;
padding: 10px 0;
font-size: 12px;
color: #828282;
border-top: 1px solid #e0e0e0;
margin-top: 20px;
}
footer a {
color: #828282;
text-decoration: none;
}
footer a:hover {
text-decoration: underline;
}
.underlink {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="header">AI Speaks</div>
<div class="container">
<!-- Story container (hidden by default) -->
<div id="story">
<button id="close-story">X</button>
<div id="story-content"></div>
</div>
<!-- News list container -->
<div id="news"></div>
</div>
<footer>
<p>Disclaimer: The entire content is generated by AI</p>
<p><a class="underlink" href="https://github.com/ergate-ai/ai-speaks" target="_blank">Hosted with ❤️ by Github, see the code at AI Speaks</a></p>
<p>© 2025 <a href="https://ergate.ai" target="_blank">Ergate AI</a></p>
</footer>
<script>
/**
* Parse a CSV line in the format:
* timestamp,uuid,heading
* The heading may contain commas, so we split only on the first two commas.
*/
function parseCSVLine(line) {
const firstComma = line.indexOf(',');
const secondComma = line.indexOf(',', firstComma + 1);
if (firstComma === -1 || secondComma === -1) {
return { timestamp: "", uuid: "", heading: line };
}
const timestamp = line.substring(0, firstComma).trim();
const uuid = line.substring(firstComma + 1, secondComma).trim();
const heading = line.substring(secondComma + 1).trim();
return { timestamp, uuid, heading };
}
// Fetch the CSV file (mind.csv) from the /mind/ directory
fetch('/mind/mind.csv')
.then(response => {
if (!response.ok) {
throw new Error('Failed to load mind.csv');
}
return response.text();
})
.then(text => {
const lines = text.split("\n").filter(line => line.trim() !== "");
const newsContainer = document.getElementById("news");
let html = "";
let rank = 1;
lines.forEach(line => {
const item = parseCSVLine(line);
// Convert the RFC timestamp to a human-friendly format if possible
html += '<div class="news-item">';
html += '<span>' + rank + '. </span>';
// The anchor uses a data-uuid attribute for fetching the story.
html += '<a href="#" data-uuid="' + item.uuid + '">' + item.heading + '</a>';
html += '<div class="subtext">' + item.timestamp + '</div>';
html += '</div>';
rank++;
});
newsContainer.innerHTML = html;
// Add click event listeners to each story link
document.querySelectorAll('.news-item a').forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const uuid = this.getAttribute('data-uuid');
// Fetch the story text from /mind/stories/{uuid}.txt
fetch('/mind/stories/' + uuid + '.txt')
.then(response => {
if (!response.ok) {
throw new Error("Could not load story");
}
return response.text();
})
.then(text => {
// Hide the news list and show the story container with the story content
document.getElementById("news").style.display = "none";
document.getElementById("story-content").innerHTML = text;
document.getElementById("story").style.display = "block";
})
.catch(err => {
console.error(err);
alert("Failed to load story.");
});
});
});
})
.catch(error => {
console.error(error);
document.getElementById("news").innerHTML = "<p>Error loading news.</p>";
});
// When the user clicks the close button, hide the story view and show the news list again.
document.getElementById("close-story").addEventListener("click", function() {
document.getElementById("story").style.display = "none";
document.getElementById("news").style.display = "block";
});
</script>
</body>
</html>