-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbooks.html
More file actions
137 lines (120 loc) · 6.43 KB
/
books.html
File metadata and controls
137 lines (120 loc) · 6.43 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<link href="styles.css" rel="stylesheet">
<title>Luis Minaya</title>
<link rel="icon" type="image/x-icon" href="/images/LNM2.1.jpg">
</head>
<body>
<div id="mainHeader">
<h1>Luis N. Minaya</h1>
<div id="menu">
<!-- this is for the menu bar-->
<a href="/index.html" class="menuButton" id="index-link">Home</a>
<a href="/books.html" class="menuButton" id="books-link">Books I've Read</a>
<a href="/cooking.html" class="menuButton" id="cooking-link">Pictures of my Cooking</a>
<a href="/links.html" class="menuButton" id="links-link">Links</a>
</div>
</div>
<div class="container-fluid">
<!--Testing the input of a csv file for making a table-->
<!-- <input type="file" id="booksRead" accept=".csv"> -->
<table id="booksTable"></table>
<!--List books I've read in 2023 - 2024 in a table-->
</div>
<!-- Bootstrap's popper script-->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js" integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous"></script>
<!-- Bootstrap script-->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
<!--Script to add currentPage class to current URL in order to bold the link font-->
<script>
document.addEventListener("DOMContentLoaded", function() {
const currentPage = window.location.pathname.split("/").pop();
const linkId = currentPage.split(".")[0] + "-link";
const currentLink = document.getElementById(linkId);
if (currentLink) {
currentLink.classList.add("currentPage");
}
});
</script>
<!--Script for changing the way links open if you are on mobile-->
<script>
if (window.innerWidth <= 768) {
let targetTypes = document.querySelectorAll('a[target="_blank"]');
for (let targetType of targetTypes) {
targetType.setAttribute('target', '_top');
}
}
</script>
<!--Script for reading csv file-->
<script>
// document.getElementById('booksRead').addEventListener('change', function(event) {
// const file = event.target.files[0];
// const reader = new FileReader();
// reader.onload = function(e) {
// const text = e.target.result;
// // This parses file
// // The following code should parse the text and create the table
// const rows = text.split('\n');
// rows.forEach(row => {
// const columns = row.split(',');
// console.log(row);
// console.log(columns);
// });
// };
// reader.readAsText(file);
// });
// Second attempt
window.onload = function() {
fetch('booksRead.csv')
.then(response => response.text())
.then(data => {
// The following code should parse the text and create the table
const rows = data.split('\n');
const table = document.getElementById('booksTable');
const headers = rows[0].split(',');
// Columns that will be included in the table
const tableColumns = [
headers.indexOf('Book Name'),
headers.indexOf('Author'),
headers.indexOf('Year Read')];
// Columns for book title hyperlink
const bookUrl = headers.map(headers => headers.trim()).indexOf('Links');
const bookTitle = headers.map(headers => headers.trim()).indexOf('Book Name');
rows.forEach((row, rindex) => {
// Creates each row
const columns = row.split(',');
const tr = document.createElement('tr');
// Creates each column for the row
columns.forEach((column, index) => {
const th = document.createElement('th');
const td = document.createElement('td');
// Create the headers
if (rindex === 0) {
th.textContent = column;
// Create a hyperlink for the book title
} else if ((index === bookTitle) && (columns[bookUrl].startsWith('http'))) {
const a = document.createElement('a');
a.textContent = column;
a.href = columns[bookUrl];
td.appendChild(a);
} else {
td.textContent = column;
}
if ((tableColumns.includes(index)) && (rindex === 0)) {
tr.appendChild(th);
} else if ((tableColumns.includes(index)) && (!rindex == 0)) {
tr.appendChild(td);
}
});
// Add the created and populated row to the table
table.appendChild(tr);
});
});
};
</script>
</body>
</html>