Skip to content

Commit

Permalink
Merge pull request #8 from ZuliusRoolf/JSON-to-HTML-converter
Browse files Browse the repository at this point in the history
Json to html converter
  • Loading branch information
ZuliusRoolf authored Jul 27, 2024
2 parents c2cd712 + 881aea4 commit 8864bea
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 87 deletions.
12 changes: 10 additions & 2 deletions JOURNAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ This is a quick journal on how I develop this website. It will be used for docum
- [Descendant vs. Child Selectors](#descendant-vs-child-selectors)
- [Flexbox and Grid](#flexbox-and-grid)
- [Design Considerations](#design-considerations)
- [JSON to HTML in Biography](#json-to-html-in-biography)

## July 13

Expand Down Expand Up @@ -226,9 +227,9 @@ I made [JSON content structure](#json-content-structure) on the 15 of July. I'll
## July 27

- [x] Translate portfolio HTML into JSON structure
- [ ] Javascript convert JSON to HTML
- [x] Javascript convert JSON to HTML
- [x] Portfolio
- [ ] Biography
- [x] Biography
- [x] Recap Mr. Ranedeer lessons
- [ ] Reach step 1.10 in Mr. Ranedeer website curriculum

Expand Down Expand Up @@ -272,3 +273,10 @@ Learning about CSS made me think about what the best way to layout the website.
Also need to think about how to handle a square screen. Will three columns still suffice or should one be hidden? If yes, how should it be accessable?
One solution could be to have an arrow that opens the timeline column or shift the entire view towards the timeline, hiding the portfolio until the left arrow is pressed.
All of these solutions are extra steps to a simple design, making it more complex. For now, especially considering I only have two columns at the moment, I will implement the flexbox for now with media queries.

### JSON to HTML in Biography

I only did portfolio converter earlier today. Now I will attempt to use chatGPT to make a biography converter.

That went surprisingly easy...
ChatGPT just took the HTML template as a string and inserted replacable values to then insert JSON into. I changed some class names as well, nothing major. On a sidenote, I have begun liking two space indentation more than four, so I switched the `script.js` to be that as well.
4 changes: 2 additions & 2 deletions website/content/biography.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
{
"name": "LinkedIn",
"link": "https://www.linkedin.com/in/johndoe",
"icon": "linkedin"
"icon": "content/icons/linkedin.svg"
},
{
"name": "Twitter",
"link": "https://twitter.com/johndoe",
"icon": "twitter"
"icon": "content/icons/twitter.svg"
},
{
"name": "GitHub",
Expand Down
6 changes: 5 additions & 1 deletion website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
<span id="company">BTH</span>
</div>
<div class="profile-links">
<a class="column" href="https://github.com/ZuliusRoolf">
<a class="link-column" href="https://github.com/">
<img src="content\icons\github.svg" alt="GitHub" height="64">
</a>
<a class="link-column" href="https://apple.com/">
<img src="content\icons\apple.svg" alt="Apple" height="64">
</a>
</div>
<div class="profile-information">
Hello! <br> Seems like JavaScript was unable to load the content of this website.
Expand Down Expand Up @@ -83,6 +86,7 @@


<script>
fetchBiography();
fetchPortfolio();
</script>
</div>
Expand Down
201 changes: 119 additions & 82 deletions website/script.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,125 @@
function fetchPortfolio() {
// Fetch the JSON data
fetch('content/portfolio.json')
// Fetch the JSON data
fetch('content/portfolio.json')
.then(response => response.json())
.then(data => {
const portfolioContainer = document.getElementById('portfolio');

// Iterate over the portfolio items and create HTML elements
data.portfolio.forEach(item => {
const portfolioItem = document.createElement('div');
portfolioItem.classList.add('portfolio-item');

// Title Navigation button
const portfolioTitle = document.createElement('div');
portfolioTitle.classList.add('portfolio-title', 'navbutton');

const title = document.createElement('div');
title.textContent = item.title;
title.classList.add('title');
portfolioTitle.appendChild(title);

const year = document.createElement('div');
year.textContent = item.year;
title.classList.add('year');
portfolioTitle.appendChild(year);

portfolioItem.appendChild(portfolioTitle);

// Portfolio Content
const portfolioContent = document.createElement('div');
portfolioContent.classList.add('portfolio-content');

const video = document.createElement('video');
video.src = item.video;
video.textContent = 'Your browser does not support the video tag.';
portfolioContent.appendChild(video);

// Context Island
const island = document.createElement('div');
island.classList.add('island');

const companyLogo = document.createElement('img');
companyLogo.src = item.companyLogo;
companyLogo.height = '16';
island.appendChild(companyLogo);

const companyName = document.createElement('text');
companyName.textContent = ' ' + item.companyName;
companyName.classList.add('company');

if (item.collaborators != '') {
const collaborators = document.createElement('span');
collaborators.textContent = ' · with ' + item.collaborators;
companyName.appendChild(collaborators);
}

island.appendChild(companyName);
portfolioContent.appendChild(island);

// Text Content
const text = document.createElement('div');
text.classList.add('text');

const descriptiveTitle = document.createElement('div');
descriptiveTitle.classList.add('descriptive-title');
descriptiveTitle.style.fontWeight = 'bold';
descriptiveTitle.textContent = item.descriptiveTitle;
text.appendChild(descriptiveTitle);

const reason = document.createElement('div');
reason.classList.add('reason');
reason.textContent = item.reason;
text.appendChild(reason);

const projectRedirect = document.createElement('a');
projectRedirect.classList.add('project-redirect');
projectRedirect.textContent = 'View Project on ' + item.projectHostName;
projectRedirect.href = item.projectLink;
text.appendChild(projectRedirect);

portfolioContent.appendChild(text);
portfolioItem.appendChild(portfolioContent);

portfolioContainer.appendChild(portfolioItem);
});
const portfolioContainer = document.getElementById('portfolio');

// Iterate over the portfolio items and create HTML elements
data.portfolio.forEach(item => {
const portfolioItem = document.createElement('div');
portfolioItem.classList.add('portfolio-item');

// Title Navigation button
const portfolioTitle = document.createElement('div');
portfolioTitle.classList.add('portfolio-title', 'navbutton');

const title = document.createElement('div');
title.textContent = item.title;
title.classList.add('title');
portfolioTitle.appendChild(title);

const year = document.createElement('div');
year.textContent = item.year;
title.classList.add('year');
portfolioTitle.appendChild(year);

portfolioItem.appendChild(portfolioTitle);

// Portfolio Content
const portfolioContent = document.createElement('div');
portfolioContent.classList.add('portfolio-content');

const video = document.createElement('video');
video.src = item.video;
video.textContent = 'Your browser does not support the video tag.';
portfolioContent.appendChild(video);

// Context Island
const island = document.createElement('div');
island.classList.add('island');

const companyLogo = document.createElement('img');
companyLogo.src = item.companyLogo;
companyLogo.height = '16';
island.appendChild(companyLogo);

const companyName = document.createElement('text');
companyName.textContent = ' ' + item.companyName;
companyName.classList.add('company');

if (item.collaborators != '') {
const collaborators = document.createElement('span');
collaborators.textContent = ' · with ' + item.collaborators;
companyName.appendChild(collaborators);
}

island.appendChild(companyName);
portfolioContent.appendChild(island);

// Text Content
const text = document.createElement('div');
text.classList.add('text');

const descriptiveTitle = document.createElement('div');
descriptiveTitle.classList.add('descriptive-title');
descriptiveTitle.style.fontWeight = 'bold';
descriptiveTitle.textContent = item.descriptiveTitle;
text.appendChild(descriptiveTitle);

const reason = document.createElement('div');
reason.classList.add('reason');
reason.textContent = item.reason;
text.appendChild(reason);

const projectRedirect = document.createElement('a');
projectRedirect.classList.add('project-redirect');
projectRedirect.textContent = 'View Project on ' + item.projectHostName;
projectRedirect.href = item.projectLink;
text.appendChild(projectRedirect);

portfolioContent.appendChild(text);
portfolioItem.appendChild(portfolioContent);

portfolioContainer.appendChild(portfolioItem);
});
})
.catch(error => console.error('Error fetching the JSON data:', error));
}

function fetchBiography() {
// Fetch the JSON data
fetch('content/biography.json')
.then(response => response.json())
.then(profile => {

const biographyDiv = document.getElementById('biography');

const profileHTML = `
<div class="biography-container">
<div class="profile-picture">
<img src="${profile.portrait}" alt="Profile Picture">
</div>
<div class="profile-introduction">
<span id="name">${profile.name}</span>,
<br>
<span id="profession">${profile.title}</span>
at
<span id="company">${profile.workplace}</span>
</div>
<div class="profile-links">
${profile.links.map(link => `
<a class="link-column" href="${link.link}">
<img src="${link.icon}" alt="${link.name}">
</a>
`).join('')}
</div>
<div class="profile-information">
${profile.aboutMeText}
</div>
</div>
`;
biographyDiv.innerHTML = profileHTML;
})
.catch(error => console.error('Error fetching the JSON data:', error));
}

0 comments on commit 8864bea

Please sign in to comment.