This is a solution to the Planets fact site challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Note: Delete this note and update the table of contents based on what sections you keep.
Users should be able to:
- View the optimal layout for the app depending on their device's screen size
- See hover states for all interactive elements on the page
- View each planet page and toggle between "Overview", "Internal Structure", and "Surface Geology"
- Solution URL: https://github.com/tomwinskell/planets
- Live Site URL: https://tomwinskell.github.io/planets
-
Bootstrap Integration:
- Navigation components were used directly from Bootstrap.
- Most styling relies on Bootstrap classes for simplicity and consistency.
-
Responsive Design:
- The HTML and initial Bootstrap classes were designed for mobile-first layouts.
- Additional classes were added to enhance layouts for larger screens.
-
Custom Styling:
- A minimal amount of custom CSS in
style.cssis used for styling outside Bootstrap's scope, such as colors and font styles.
- A minimal amount of custom CSS in
-
Template Rendering:
- Mustache templates are used for rendering dynamic content.
-
JavaScript Functionality:
- The Fetch API is used to load data from a locally stored JSON file.
- Based on user-selected resources, this data is dynamically injected into templates using Mustache.js.
- The resulting HTML is then inserted into
index.html.
-
Optimized Performance:
- All data is loaded from the server when
index.htmlis initially accessed. - After this, everything is rendered client-side, ensuring quick and seamless website transitions.
- All data is loaded from the server when
- Semantic HTML5 markup
- CSS custom properties
- Flexbox
- Bootstrap 5.3
- Mobile-first workflow
- JavaScript
- Mustache.js - for templating
For this project, I utilized Mustache.js to handle HTML templating. The library was included via a CDN link in index.html. JavaScript is then used to dynamically set the innerHTML of a <div> element with content rendered by Mustache.js.
The following snippet demonstrates how data is rendered into a Mustache template and subsequently inserted into the DOM:
mainText.innerHTML = Mustache.render(
await renderTemplate('main_text'),
dataObject
);Here’s an example of the corresponding Mustache template:
<h1 class="display-1 font-antonio text-uppercase mb-3" id="js__name">
{{name}}
</h1>
<div class="font-spartan fs-6">
{{content}}
<div class="mt-3">Source: <a href="{{{source}}}">Wikipedia</a></div>
</div>The project leverages the Fetch API to load both JSON data and Mustache template files. Below is a function that retrieves a Mustache template file as a string:
async function renderTemplate(templateName) {
const response = await fetch(`./${templateName}.mustache`);
const template = await response.text();
return template;
}By combining these elements, the application dynamically renders content into the DOM, creating a responsive and modular design workflow.
- Bootstrap - Official documentation for the popular CSS framework.
- Mustache.js - Official site for the Mustache templating library.
- MDN: Fetch API - Comprehensive guide to the Fetch API on MDN.
- Frontend Mentor - @tomwinskell
- LinkedIn - Professional network and career connections.
- Notion - Personal workspace and knowledge management.
- GitHub - Check out my projects and code repositories.


