From 8d4199892976110750147fe0fa23f0c429b5c0ef Mon Sep 17 00:00:00 2001
From: david
Date: Mon, 7 Apr 2025 23:31:33 -0700
Subject: [PATCH] format js
---
js/load.js | 42 +++++++++++++++++++++---------------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/js/load.js b/js/load.js
index e2cabe0..fd2f915 100644
--- a/js/load.js
+++ b/js/load.js
@@ -1,38 +1,38 @@
-const loadSection = (sectionName) =>{
+const loadSection = (sectionName) => {
fetch(`data/${sectionName}.json`)
- .then(response => response.json())
- .then(data => {
- const container = document.getElementById(sectionName);
- container.innerHTML = renderItems(data)
- })
- .catch(error => console.error('Error loading JSON:', error));
+ .then(response => response.json())
+ .then(data => {
+ const container = document.getElementById(sectionName);
+ container.innerHTML = renderItems(data)
+ })
+ .catch(error => console.error('Error loading JSON:', error));
}
function cap(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
- }
+}
// Recursive function to handle strings, arrays, and objects
const renderItems = (items) => {
return items.map(item => {
- if (typeof item === 'string') {
- return `${item}
`;
- } else if (Array.isArray(item)) {
- return renderItems(item); // recurse into nested array
- } else if (typeof item === 'object') {
- return `${Object.entries(item).map(([key, value]) =>
- // `${value}`).join('
')}
`;
- `${cap(key)}: ${value}`).join('
')}
`;
- } else {
- return `${String(item)}
`;
- }
+ if (typeof item === 'string') {
+ return `${item}
`;
+ } else if (Array.isArray(item)) {
+ return renderItems(item); // recurse into nested array
+ } else if (typeof item === 'object') {
+ return `${Object.entries(item).map(([key, value]) =>
+ // `${value}`).join('
')}
`;
+ `${cap(key)}: ${value}`).join('
')}`;
+ } else {
+ return `${String(item)}
`;
+ }
}).join('');
- };
+};
const sections = document.getElementsByClassName('section')
-Array.from(sections).forEach(section =>{
+Array.from(sections).forEach(section => {
loadSection(section.id)
})
\ No newline at end of file