no more comments (im evil)

This commit is contained in:
bearfm 2024-01-27 16:52:54 -08:00
parent af3fe3d628
commit 3d20fba3b3
Signed by untrusted user who does not match committer: bearfm
GPG Key ID: 573A776FED58E1A4
1 changed files with 7 additions and 20 deletions

View File

@ -1,8 +1,8 @@
function convertCamelCaseToReadable(text) { function convertCamelCaseToReadable(text) {
return text return text
.replace(/([a-z])([A-Z])/g, '$1 $2') // Convert camelCase to separate words .replace(/([a-z])([A-Z])/g, '$1 $2')
.replace(/(\d{4}-\d{2}-\d{2})/g, ' $1') // Add space before date-like patterns .replace(/(\d{4}-\d{2}-\d{2})/g, ' $1')
.replace(/\b\w/g, c => c.toUpperCase()); // Capitalize each word .replace(/\b\w/g, c => c.toUpperCase());
} }
function blogIndex() { function blogIndex() {
@ -13,39 +13,27 @@ function blogIndex() {
fetch('/blogindex.txt') fetch('/blogindex.txt')
.then(response => response.text()) .then(response => response.text())
.then(data => { .then(data => {
// Split the data into an array of timestamped URIs
const uriList = data.split('\n'); const uriList = data.split('\n');
// Remove any empty lines
const filteredUriList = uriList.filter(entry => entry.trim() !== ''); const filteredUriList = uriList.filter(entry => entry.trim() !== '');
// Create an array of objects with timestamp and URI properties
const entries = filteredUriList.map(entry => { const entries = filteredUriList.map(entry => {
const parts = entry.split(' '); const parts = entry.split(' ');
return { timestamp: parseInt(parts[0]), uri: parts[1] || '' }; return { timestamp: parseInt(parts[0]), uri: parts[1] || '' };
}); });
// Sort the entries by timestamp in descending order (latest first)
entries.sort((a, b) => b.timestamp - a.timestamp); entries.sort((a, b) => b.timestamp - a.timestamp);
// Create an unordered list element
const ulElement = document.createElement('ul'); const ulElement = document.createElement('ul');
// Iterate through the sorted entries and extract pretty names, excluding the index page
entries.forEach(entry => { entries.forEach(entry => {
// Check if the URI is defined before processing
if (entry.uri) { if (entry.uri) {
// Extract the file name without extension
const fileName = entry.uri.split('/').pop().replace('.html', ''); const fileName = entry.uri.split('/').pop().replace('.html', '');
const readableName = convertCamelCaseToReadable(fileName); const readableName = convertCamelCaseToReadable(fileName);
// Exclude the index page
if (fileName.toLowerCase() !== 'index') { if (fileName.toLowerCase() !== 'index') {
// Create list items with links using relative paths
const liElement = document.createElement('li'); const liElement = document.createElement('li');
const aElement = document.createElement('a'); const aElement = document.createElement('a');
// Use a relative link instead of the full URI
aElement.href = entry.uri.substring(entry.uri.indexOf('/blog/')); aElement.href = entry.uri.substring(entry.uri.indexOf('/blog/'));
aElement.textContent = readableName; aElement.textContent = readableName;
liElement.appendChild(aElement); liElement.appendChild(aElement);
@ -54,7 +42,6 @@ function blogIndex() {
} }
}); });
// Append the unordered list to the blogIndex div
document.getElementById('blogIndex').appendChild(ulElement); document.getElementById('blogIndex').appendChild(ulElement);
}) })
.catch(error => { .catch(error => {