Skip to content

Commit

Permalink
remove leading ##_ from filename
Browse files Browse the repository at this point in the history
  • Loading branch information
dylansdaniels committed Dec 13, 2024
1 parent de937f4 commit f0468a6
Show file tree
Hide file tree
Showing 7 changed files with 507 additions and 5 deletions.
35 changes: 32 additions & 3 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# %%
import os
import re
import pypandoc
from create_page_index import update_page_index
from create_navbar import generate_navbar_html
Expand Down Expand Up @@ -80,9 +81,37 @@ def generate_page_html(page_paths):

for page, path in page_paths.items():
page_components = html_parts.copy()
out_path = path.split(".md")[0] + ".html"

converted = pypandoc.convert_file(path, 'html')
# get path only
out_path = path.split(page)[0]

# ENHANCEMENT
'''
# remove instances of `##_` from out_path
# build html to separate `build` folder
# this will make the urls look neater
'''
# out_path = re.sub(r"\d\d_", "", out_path)

# remove leading `##_` from page
page = page.split("_", 1)[1]
# change file extension for page
page = page.split(".md")[0] + ".html"

# combine path and page
out_path = out_path + page

# use pypandoc to convert md to html
try:
converted = pypandoc.convert_file(path, 'html')
except Exception as ex:
# download Pandoc dependency if needed
if "No pandoc was found" in ex:
print("Downloading pandoc dependency")
pypandoc.download_pandoc()
converted = pypandoc.convert_file(path, 'html')
else:
raise ex
# format html for readability
converted = BeautifulSoup(converted, 'html.parser').prettify()
page_components['body'] = converted

Expand Down
155 changes: 155 additions & 0 deletions content/01_under_the_hood/cortical_column_structure.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HNN Textbook</title>
<base href="/website_redesign/">
<link href="https://fonts.googleapis.com/css2?family=Fira+Sans:wght@400&display=swap" rel="stylesheet">
<link rel="stylesheet" href="styles.css">
</head>
<body>

<div id="mySidebar" class="sidebar">
<p style="color:#e5a734">
Human Neocortical Neurosolver
</p>
<br>
<a href="content/00_preface.html">Preface</a>
<div class="sidebar-list">
<a id="sidebar-header" onclick="toggleSubmenu(event)">
1. Under the Hood
</a>
<div class="submenu">
<a href="content/01_under_the_hood/01_cortical_column_structure.html">1.1 Cortical Column Structure</a>
<a href="content/01_under_the_hood/02_primary_electric_currents.html">1.2 Calculation of Primary Electric Currents</a>
</div>
</div>
<div class="sidebar-list">
<a id="sidebar-header" onclick="toggleSubmenu(event)">
2 Simulating ERPs
</a>
<div class="submenu">
<a href="content/02_simulating_erps/01_overview_of_erps.html">2.1 Review of ERPs</a>
</div>
</div>
</div>

<div id="main">
<div class="topbar">
<button class="openbtn" onclick="toggleNav()"></button>
<div class="dropdown">
<button id="dropdownButton" class="dropdown-button">
<span>A</span>
</button>
<div class="dropdown-content">
<button class="fontsize-btn" onclick="decreaseFontSize()">A-</button>
<button class="fontsize-btn" onclick="increaseFontSize()">A+</button>
</div>
</div>
<img src="https://hnn.brown.edu/wp-content/uploads/hnn-medium.png"></img>
</div>

<div id="content-wrapper">
<div id="content">

<!--
# Title: 1.1 Cortical Column Structure
# Updated: 2024-11-14
#
# Contributors:
# Dylan Daniels
-->
</div> <!-- close content wrapper -->
</div> <!-- close content -->
</div> <!-- close main -->

<script>
let isSidebarOpen = true; // Sidebar is initially open

function toggleNav() {
const sidebar = document.getElementById("mySidebar");
const main = document.getElementById("main");

// Toggle sidebar state
if (isSidebarOpen) {
sidebar.style.width = "0";
main.style.marginLeft = "0";
} else {
sidebar.style.width = "350px"; // Adjust width as needed
main.style.marginLeft = "350px"; // Match margin to new width
}

// Toggle the sidebar state
isSidebarOpen = !isSidebarOpen;
}

// Open the sidebar on page load
window.onload = function() {
// Set initial styles for open state without animation
const sidebar = document.getElementById("mySidebar");
const main = document.getElementById("main");

sidebar.style.transition = "none";
main.style.transition = "none";
sidebar.style.width = "350px";
main.style.marginLeft = "350px";

// Re-enable transition for subsequent toggles
setTimeout(() => {
sidebar.style.transition = "width 0.5s";
main.style.transition = "margin-left 0.5s";
}, 10);
}

function increaseFontSize() {
event.stopPropagation(); // Prevent dropdown from closing
const content = document.getElementById("content");
const currentSize = window.getComputedStyle(content).fontSize;
content.style.fontSize = (parseFloat(currentSize) + 2) + "px";
}

function decreaseFontSize() {
event.stopPropagation(); // Prevent dropdown from closing
const content = document.getElementById("content");
const currentSize = window.getComputedStyle(content).fontSize;
content.style.fontSize = (parseFloat(currentSize) - 2) + "px";
}

// Dropdown for font buttons
function toggleDropdown() {
const dropdownContent = document.querySelector('.dropdown-content');
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
}

// Open/close dropdown on click of the button
document.getElementById('dropdownButton').onclick = function(event) {
event.stopPropagation(); // Prevent the click from triggering the window.onclick event
toggleDropdown();
};

// Close dropdown if clicking outside
window.onclick = function(event) {
const dropdownContent = document.querySelector('.dropdown-content');
if (!event.target.closest('.dropdown')) { // Close if click outside the dropdown
dropdownContent.style.display = 'none';
}
};

function toggleSubmenu(event) {
const submenu = event.target.nextElementSibling; // Get the submenu for the clicked header

// If the submenu exists, toggle it
if (submenu && submenu.classList.contains('submenu')) {
submenu.classList.toggle('open'); // Toggle the 'open' class to control visibility
}
};

// This function will add the full text to the title attribute for all anchor tags
document.querySelectorAll('.sidebar a').forEach(anchor => {
anchor.setAttribute('title', anchor.textContent);
});
</script>

</body>
</html>
2 changes: 1 addition & 1 deletion content/01_under_the_hood/primary_electric_currents.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</a>
<div class="submenu">
<a href="content/01_under_the_hood/01_cortical_column_structure.html">1.1 Cortical Column Structure</a>
<a href="content/01_under_the_hood/primary_electric_currents.html">1.2 Calculation of Primary Electric Currents</a>
<a href="content/01_under_the_hood/02_primary_electric_currents.html">1.2 Calculation of Primary Electric Currents</a>
</div>
</div>
<div class="sidebar-list">
Expand Down
155 changes: 155 additions & 0 deletions content/02_simulating_erps/overview_of_erps.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HNN Textbook</title>
<base href="/website_redesign/">
<link href="https://fonts.googleapis.com/css2?family=Fira+Sans:wght@400&display=swap" rel="stylesheet">
<link rel="stylesheet" href="styles.css">
</head>
<body>

<div id="mySidebar" class="sidebar">
<p style="color:#e5a734">
Human Neocortical Neurosolver
</p>
<br>
<a href="content/00_preface.html">Preface</a>
<div class="sidebar-list">
<a id="sidebar-header" onclick="toggleSubmenu(event)">
1. Under the Hood
</a>
<div class="submenu">
<a href="content/01_under_the_hood/01_cortical_column_structure.html">1.1 Cortical Column Structure</a>
<a href="content/01_under_the_hood/02_primary_electric_currents.html">1.2 Calculation of Primary Electric Currents</a>
</div>
</div>
<div class="sidebar-list">
<a id="sidebar-header" onclick="toggleSubmenu(event)">
2 Simulating ERPs
</a>
<div class="submenu">
<a href="content/02_simulating_erps/01_overview_of_erps.html">2.1 Review of ERPs</a>
</div>
</div>
</div>

<div id="main">
<div class="topbar">
<button class="openbtn" onclick="toggleNav()"></button>
<div class="dropdown">
<button id="dropdownButton" class="dropdown-button">
<span>A</span>
</button>
<div class="dropdown-content">
<button class="fontsize-btn" onclick="decreaseFontSize()">A-</button>
<button class="fontsize-btn" onclick="increaseFontSize()">A+</button>
</div>
</div>
<img src="https://hnn.brown.edu/wp-content/uploads/hnn-medium.png"></img>
</div>

<div id="content-wrapper">
<div id="content">

<!--
# Title: 2.1 Review of ERPs
# Updated: 2024-11-14
#
# Contributors:
# Dylan Daniels
-->
</div> <!-- close content wrapper -->
</div> <!-- close content -->
</div> <!-- close main -->

<script>
let isSidebarOpen = true; // Sidebar is initially open

function toggleNav() {
const sidebar = document.getElementById("mySidebar");
const main = document.getElementById("main");

// Toggle sidebar state
if (isSidebarOpen) {
sidebar.style.width = "0";
main.style.marginLeft = "0";
} else {
sidebar.style.width = "350px"; // Adjust width as needed
main.style.marginLeft = "350px"; // Match margin to new width
}

// Toggle the sidebar state
isSidebarOpen = !isSidebarOpen;
}

// Open the sidebar on page load
window.onload = function() {
// Set initial styles for open state without animation
const sidebar = document.getElementById("mySidebar");
const main = document.getElementById("main");

sidebar.style.transition = "none";
main.style.transition = "none";
sidebar.style.width = "350px";
main.style.marginLeft = "350px";

// Re-enable transition for subsequent toggles
setTimeout(() => {
sidebar.style.transition = "width 0.5s";
main.style.transition = "margin-left 0.5s";
}, 10);
}

function increaseFontSize() {
event.stopPropagation(); // Prevent dropdown from closing
const content = document.getElementById("content");
const currentSize = window.getComputedStyle(content).fontSize;
content.style.fontSize = (parseFloat(currentSize) + 2) + "px";
}

function decreaseFontSize() {
event.stopPropagation(); // Prevent dropdown from closing
const content = document.getElementById("content");
const currentSize = window.getComputedStyle(content).fontSize;
content.style.fontSize = (parseFloat(currentSize) - 2) + "px";
}

// Dropdown for font buttons
function toggleDropdown() {
const dropdownContent = document.querySelector('.dropdown-content');
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
}

// Open/close dropdown on click of the button
document.getElementById('dropdownButton').onclick = function(event) {
event.stopPropagation(); // Prevent the click from triggering the window.onclick event
toggleDropdown();
};

// Close dropdown if clicking outside
window.onclick = function(event) {
const dropdownContent = document.querySelector('.dropdown-content');
if (!event.target.closest('.dropdown')) { // Close if click outside the dropdown
dropdownContent.style.display = 'none';
}
};

function toggleSubmenu(event) {
const submenu = event.target.nextElementSibling; // Get the submenu for the clicked header

// If the submenu exists, toggle it
if (submenu && submenu.classList.contains('submenu')) {
submenu.classList.toggle('open'); // Toggle the 'open' class to control visibility
}
};

// This function will add the full text to the title attribute for all anchor tags
document.querySelectorAll('.sidebar a').forEach(anchor => {
anchor.setAttribute('title', anchor.textContent);
});
</script>

</body>
</html>
Loading

0 comments on commit f0468a6

Please sign in to comment.