Skip to content

Commit

Permalink
Ran rye sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce Eckel authored and Bruce Eckel committed Nov 8, 2023
1 parent 7e7da64 commit d9793d6
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 198 deletions.
Empty file added tools/check-links/README.md
Empty file.
1 change: 0 additions & 1 deletion tools/javascript/.python-version

This file was deleted.

104 changes: 0 additions & 104 deletions tools/javascript/generate.py

This file was deleted.

21 changes: 0 additions & 21 deletions tools/javascript/pyproject.toml

This file was deleted.

File renamed without changes.
File renamed without changes.
157 changes: 87 additions & 70 deletions tools/make_slides/make_slides.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,90 @@
# generate.py
# Generates "slides.html" for each lecture directory in "Thinking in C"
from pathlib import Path
import json

header = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Thinking in C</title>
<style>
body { font-family: Arial, sans-serif; margin: 0; display: flex; flex-direction: column; height: 100vh; }
img { max-width: 100%; max-height: 80vh; margin: auto; }
footer {
margin-top: auto;
display: flex;
justify-content: center;
align-items: center;
padding: 1em;
}
audio {
flex-grow: 0; /* Ensure it doesn't grow beyond its width */
width: 600px; /* Fixed width for the audio control */
margin-left: 1em;
}
</style>
</head>
<body>
"""

footer = """
</body>
</html>
"""


def generate_html_for_lecture(lecture_directory):
# Get all SVG and MP3 files

def generate_html_with_javascript(lecture_directory: Path) -> None:
svg_files = sorted(lecture_directory.glob("*.svg"))
mp3_files = sorted(lecture_directory.glob("*.mp3"))

for idx, svg in enumerate(svg_files):
mp3 = svg.with_suffix(".mp3")
if mp3 not in mp3_files:
print(f"No associated MP3 found for {svg.name}. Skipping...")
continue

with open(lecture_directory / f"slide_{idx + 1}.html", "w") as f:
f.write(header)

# SVG and MP3 content
f.write(f'<img src="{svg.name}" alt="Slide {idx + 1}">')

# Navigation and audio at the bottom
f.write("<footer>")
if idx != 0:
f.write(
f'<a href="slide_{idx}.html">Previous</a>&nbsp;&nbsp;&nbsp;&nbsp;'
)
if idx != len(svg_files) - 1:
f.write(f'<a href="slide_{idx + 2}.html">Next</a>')
f.write(
f'<audio controls autoplay><source src="{mp3.name}" type="audio/mpeg"></audio>'
)
f.write('&nbsp;&nbsp;&nbsp;<a href="../../Index.html">Home</a>')
f.write("</footer>")

f.write(footer)


def generate_html(directory="."):
slides = [
{"svg": svg.name, "mp3": svg.with_suffix(".mp3").name}
for svg in svg_files
if svg.with_suffix(".mp3") in mp3_files
]
slides_json = json.dumps(slides)
html_content = f"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Thinking in C</title>
<style>
/* Add your CSS styles here */
</style>
</head>
<body>
<img id="slideImage" alt="Slide" style="max-width: 100%; max-height: 80vh; margin: auto;">
<br/>
<button id="previousButton" onclick="previousSlide()">Previous</button>
<button id="nextButton" onclick="nextSlide()">Next</button>
<audio id="slideAudio" controls style="width: 600px; margin-left: 1em;"></audio>
<button onclick="goHome()">Home</button>
<script>
const slides = {slides_json};
let currentSlide = 0;
function showSlide(index) {{
const slide = slides[index];
document.getElementById('slideImage').src = slide.svg;
document.getElementById('slideAudio').src = slide.mp3;
currentSlide = index;
document.getElementById('slideAudio').play();
updateNavigationButtons();
}}
function nextSlide() {{
if (currentSlide < slides.length - 1) {{
showSlide(currentSlide + 1);
}}
}}
function previousSlide() {{
if (currentSlide > 0) {{
showSlide(currentSlide - 1);
}}
}}
function updateNavigationButtons() {{
document.getElementById('previousButton').style.display = currentSlide === 0 ? 'none' : 'inline';
document.getElementById('nextButton').style.display = currentSlide === slides.length - 1 ? 'none' : 'inline';
}}
function goHome() {{
window.location.href = '../../Index.html';
}}
document.getElementById('slideAudio').addEventListener('ended', nextSlide);
window.onload = () => {{
showSlide(0);
updateNavigationButtons();
}};
</script>
</body>
</html>
"""

with open(lecture_directory / "slides.html", "w") as f:
f.write(html_content)

print(
f"Single HTML file with JavaScript created successfully for {lecture_directory.name}!"
)


def generate_single_html(directory: str = ".") -> None:
main_directory = Path(directory)
lectures_directory = main_directory / "lectures"

Expand All @@ -77,11 +94,11 @@ def generate_html(directory="."):

for lecture_dir in lectures_directory.iterdir():
if lecture_dir.is_dir():
print(f"Generating slides for lecture: {lecture_dir.name}")
generate_html_for_lecture(lecture_dir)
print(f"Generating single HTML for lecture: {lecture_dir.name}")
generate_html_with_javascript(lecture_dir)

print("HTML files generated successfully!")
print("All lectures have been processed.")


if __name__ == "__main__":
generate_html(Path("../../src"))
generate_single_html(Path("../../src"))
4 changes: 2 additions & 2 deletions tools/make_slides/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[project]
name = "make-slides"
name = "javascript"
version = "0.1.0"
description = "Add your description here"
authors = [
{ name = "Bruce Eckel", email = "mindviewinc@gmail.com" }
{ name = "Bruce Eckel", email = "MindviewInc@gmail.com" }
]
dependencies = []
readme = "README.md"
Expand Down

0 comments on commit d9793d6

Please sign in to comment.