Skip to content

Commit

Permalink
Add survival guide to website
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Nov 29, 2024
1 parent a4d1428 commit 885e366
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 2 deletions.
8 changes: 6 additions & 2 deletions site/guide.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ function loadGuide(guide) {
window.history.replaceState({}, '', `${location.pathname}?${params}`);

// Get the title from the ID
const title = guide.split('_').slice(1).map(w => w[0].toUpperCase() + w.slice(1)).join(' ');
const sliceAmount = guide.startsWith('survival') ? 2 : 1;
const title = guide.split('_').slice(sliceAmount).map(w => w[0].toUpperCase() + w.slice(1)).join(' ');

// Load the markdown
return fetch(`${baseUrl}/guide_${guide}.md`)
.then(response => response.text())
.then(text => {
let html = toHTML(`# ${title}\n${text}`);
let html = toHTML(`# ${title}${guide === "tool_survival_guide" ? "\n[View survival guide online](survival_guides)\n" : ""}\n${text}`);
// Shift all the headers down by one h1 -> h2, h2 -> h3, etc.
html = html.replace(/<h(\d).*>(.*)<\/h(\d)>/gm, (match, p1, p2, p3) => `<h${parseInt(p1) + 1}>${p2}</h${parseInt(p1) + 1}>`);
// Resolve all images
html = html.replaceAll('file:///android_asset/', 'https://raw.githubusercontent.com/kylecorry31/Trail-Sense/main/app/src/main/assets/');

document.querySelector('#guide-text').innerHTML = html;
});
}
Expand Down
1 change: 1 addition & 0 deletions site/guides.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const guides = [
"tool_sensors",
"tool_settings",
"tool_solar_panel_aligner",
"tool_survival_guide",
"tool_temperature_estimation",
"tool_tides",
"tool_tools",
Expand Down
6 changes: 6 additions & 0 deletions site/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ img {
background: rgba(0, 0, 0, 0.05);
}

#guide-text img {
width: 100%;
height: auto;
display: block;
}

.device-rating {
float: right;
font-weight: bold;
Expand Down
40 changes: 40 additions & 0 deletions site/survival_guides.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Trail Sense</title>
<link rel="shortcut icon" href="logo.png" type="image/x-icon">
<link rel="stylesheet" href="pluto.css" />
<link rel="stylesheet" href="style.css" />
</head>

<body>
<section id="hero">
<div class="grid">
<div id="titlebar" class="navbar">
<a href="index.html">HOME</a>
<a href="https://github.com/kylecorry31/Trail-Sense/wiki/Frequently-Asked-Questions-(FAQ)"
target="_blank">FAQ</a>
<a href="index.html/#contact">CONTACT</a>
<a href="https://github.com/kylecorry31/Trail-Sense" target="_blank">GITHUB</a>
</div>
</div>
</section>

<section id="guide-content">
<div class="card-round">
<section id="guide">
<div class="container">
<h2>Survival Guide</h2>
<div id="guide-list"></div>
</div>
</section>
</div>
</section>

<script src="survival_guides.js"></script>
</body>

</html>
25 changes: 25 additions & 0 deletions site/survival_guides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const guides = [
"survival_chapter_overview",
"survival_chapter_medical",
"survival_chapter_water",
"survival_chapter_food",
"survival_chapter_fire",
"survival_chapter_shelter_and_clothing",
"survival_chapter_navigation",
"survival_chapter_weather",
"survival_chapter_crafting"
];

// Populate the guide list
const guideList = document.querySelector("#guide-list");
for (const guide of guides) {
const guideItem = document.createElement("a");
guideItem.innerText = guide
.split("_")
.slice(2)
.map((w) => w[0].toUpperCase() + w.slice(1))
.join(" ");
guideItem.classList.add("guide-list-item");
guideItem.href = `guide?id=${guide}`;
guideList.appendChild(guideItem);
}

0 comments on commit 885e366

Please sign in to comment.