Skip to content

Commit

Permalink
add simple navbar for pages; also jquery is cool
Browse files Browse the repository at this point in the history
  • Loading branch information
SeeBeeSee committed Aug 5, 2024
1 parent 95b72ba commit b8bfa1e
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@
type="image/svg+xml"
href="./img/favicon.svg"
/>

<script src="./src/jquery-3.7.1.min.js"></script>
<script src="./src/nav.js"></script>
</head>

<body>
<div class="navigation-bar">
<!-- populate via script -->
</div>
<h3>Hello, Github!</h3>
<p>Stuff here momentarily.</p>
</body>
Expand Down
21 changes: 21 additions & 0 deletions pages/grocery.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>SeeBeeSee.github.io - Seeb's Grocery List</title>
<link
rel="icon"
sizes="any"
type="image/svg+xml"
href="./img/favicon.svg"
/>

<script src="../src/jquery-3.7.1.min.js"></script>
<script src="../src/nav.js"></script>
</head>
<body>
<div class="navigation-bar">
<!-- populate via script -->
</div>
<h3>Future location for a static grocery-shopping static page.</h3>
</body>
</html>
21 changes: 21 additions & 0 deletions pages/sample.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>SeeBeeSee.github.io - Sample Page</title>
<link
rel="icon"
sizes="any"
type="image/svg+xml"
href="./img/favicon.svg"
/>

<script src="../src/jquery-3.7.1.min.js"></script>
<script src="../src/nav.js"></script>
</head>
<body>
<div class="navigation-bar">
<!-- populate via script -->
</div>
<h3>This is a sample page for the sake of testing navigation.</h3>
</body>
</html>
2 changes: 2 additions & 0 deletions src/jquery-3.7.1.min.js

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions src/nav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// navigation bar functionality

// Pages to populate the navbar with, and accompanying data
// (update here instead of re-writing navbar for each page)
const pages = [
{
title: "Seeb's Grocery List",
link: "grocery.html",
},
{
title: "Sample page",
link: "sample.html",
},
];

// When the page is ready, populate the navbar
$(document).ready(function () {
let urlSplit = document.location.href.split("/");
let currentPage = urlSplit[urlSplit.length - 1];

// distinguish whether we're at top-level index or a sub-page (assuming only 1 level of depth)
if (currentPage === "index.html") {
// append home link
$(".navigation-bar").append(
"<button><a href='index.html'>Home</a></button>"
);

// append remaining pages
pages.forEach((pageData) => {
let newButton =
"<button><a href='./pages/" +
pageData.link +
"'>" +
pageData.title +
"</a></button>";
$(".navigation-bar").append(newButton);
});
} else {
// append home link
$(".navigation-bar").append(
"<button><a href='../index.html'>Home</a></button>"
);

// append remaining pages
pages.forEach((pageData) => {
let newButton =
"<button><a href='" +
pageData.link +
"'>" +
pageData.title +
"</a></button>";
$(".navigation-bar").append(newButton);
});
}
});

0 comments on commit b8bfa1e

Please sign in to comment.