updated app.py, index.html, as well as uploaded bookshelf of sample epubs

This commit is contained in:
miggymofongo2 2023-12-27 22:33:55 -08:00
parent dadbf42b2b
commit a9c6316ccb
7 changed files with 112 additions and 133 deletions

68
app.py
View file

@ -1,75 +1,47 @@
from flask import Flask, render_template, request, send_from_directory from flask import Flask, request, send_from_directory
import os import os
# Initialize Flask app
app = Flask(__name__) app = Flask(__name__)
EPUBS_DIR = { # Directory containing EPUB files
'default': './bookshelf/' EPUBS_DIR = './bookshelf/'
}
@app.route('/') @app.route('/')
def index(): def index():
# Serve the main HTML page
return send_from_directory(app.root_path, 'index.html') return send_from_directory(app.root_path, 'index.html')
@app.route('/search', methods=['GET']) @app.route('/search', methods=['GET'])
def search(): def search():
# Get the search query parameter and convert it to lowercase for case-insensitive matching
query = request.args.get('searchQuery', '').lower() query = request.args.get('searchQuery', '').lower()
# List to store filenames of matching EPUB files
matching_files = [] matching_files = []
for _, dir_path in EPUBS_DIR.items():
all_files = [f for f in os.listdir(dir_path) if f.lower().endswith('.epub')] # Fetch all EPUB files from the directory and filter them based on the search query
all_files = [f for f in os.listdir(EPUBS_DIR) if f.lower().endswith('.epub')]
matching_files += [f for f in all_files if query in f.lower()] matching_files += [f for f in all_files if query in f.lower()]
# Render the results as HTML # Generate HTML for the list of matching files
results_html = "".join([f'<li><a href="#" onclick="loadEpubInBibi(\'/bookshelf/{file}\'); return false;">{file}</a></li>' for file in matching_files]) results_html = "".join([f'<li><a href="#" onclick="loadEpubInBibi(\'/bookshelf/{file}\'); return false;">{file}</a></li>' for file in matching_files])
return results_html return results_html
@app.route('/bookshelf/<filename>')
def serve_epub(filename):
# Serve an EPUB file from the bookshelf directory
return send_from_directory(EPUBS_DIR, filename)
@app.route('/reader/<path:subpath>') @app.route('/reader/<path:subpath>')
def serve_bibi_assets(subpath): def serve_bibi_assets(subpath):
# This will serve all of Bibi's assets, such as JavaScript, CSS, etc. # Serve assets for the Bibi EPUB reader (JavaScript, CSS, etc.)
return send_from_directory('./reader', subpath) return send_from_directory('./reader', subpath)
@app.route('/bookshelf/<filename>')
def serve_epub(filename):
return send_from_directory('./bookshelf', filename)
#@app.route('/reader')
#def serve_bibi_reader():
# book_path = request.args.get('book')
# You might want to do some checks on `book_path` for security reasons.
# return send_from_directory('./reader', 'index.html')
@app.route('/reader')
def serve_bibi_reader():
book_path = request.args.get('book', '')
if book_path:
# Check if the EPUB file exists in the bookshelf
full_path = os.path.join('bookshelf', book_path.strip('/'))
if os.path.exists(full_path):
# Serve the Bibi reader's index.html
# The book path will be handled by Bibi's JavaScript
return send_from_directory('reader', 'index.html')
else:
return "EPUB file not found", 404
return "No book specified", 400
@app.route('/favicon.ico') @app.route('/favicon.ico')
def favicon(): def favicon():
return send_from_directory(os.path.join(app.root_path, './favicon.ico'), # Serve the favicon
'favicon.ico', mimetype='image/vnd.microsoft.icon') return send_from_directory(os.path.join(app.root_path, 'favicon.ico'), 'favicon.ico', mimetype='image/vnd.microsoft.icon')
if __name__ == "__main__": if __name__ == "__main__":
app.run(debug=True) app.run(debug=True)

BIN
bookshelf/Teaching.epub Normal file

Binary file not shown.

BIN
bookshelf/interact.epub Normal file

Binary file not shown.

Binary file not shown.

BIN
bookshelf/sample.epub Normal file

Binary file not shown.

View file

@ -6,8 +6,7 @@
<title>El Asteroide De Miguel</title> <title>El Asteroide De Miguel</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
<script src="https://unpkg.com/htmx.org"></script> <script src="https://unpkg.com/htmx.org@1.9.10" integrity="sha384-D1Kt99CQMDuVetoL1lrYwg5t+9QdHe7NLX/SoJYkXDFfX37iInKRy5xLSi8nO7UC" crossorigin="anonymous"></script>
<style> <style>
.quote-banner { .quote-banner {
/* Your styling for the banner */ /* Your styling for the banner */
@ -28,62 +27,84 @@
<body> <body>
<nav class="navbar sticky-top bg-body-tertiary"> <div class="container">
<nav class="navbar navbar-expand-lg sticky-top bg-body-tertiary">
<div class="container-fluid"> <div class="container-fluid">
<a class="navbar-brand" href="#">Sticky top</a> <a class="navbar-brand" href="#">Bienvenidos a mi Asteroide!</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<!-- Home Page Link -->
<li class="nav-item">
<a class="nav-link" href="/home">Home</a>
</li>
<!-- Resume Dropdown -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarResume" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Resume
</a>
<ul class="dropdown-menu" aria-labelledby="navbarResume">
<li><a class="dropdown-item" href="/resume1">Hospitality</a></li>
<li><a class="dropdown-item" href="/resume2">Organizing</a></li>
<li><a class="dropdown-item" href="/resume3">Tech</a></li>
</ul>
</li>
<!-- Library Link -->
<li class="nav-item">
<a class="nav-link" href="https://library.miguelalmodo.com/">Library</a>
</li>
<!-- Blog Dropdown -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="https://migs.uber.space/blog" id="navbarBlog" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Blog
</a>
<ul class="dropdown-menu" aria-labelledby="navbarBlog">
<li><a class="dropdown-item" href="/blog1">Blog 1</a></li>
<li><a class="dropdown-item" href="/blog2">Blog 2</a></li>
<li><a class="dropdown-item" href="/blog3">Blog 3</a></li>
</ul>
</li>
</ul>
</div>
</div> </div>
</nav> </nav>
<!-- implement a search here for book reader
<form class="d-flex" role="search">
<input type="text"
hx-get="/search"
hx-params="searchQuery:val"
hx-trigger="keyup delay:300ms"
hx-target="#resultsContainer"
placeholder="Search for EPUBs...">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</nav>-->
<div class="navbar">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Contact</a>
</div>
<section class="hero"> <section class="hero">
<h2>Welcome to Your Website</h2> <h2>This site is hosted on my asteroid at Uberspace.de.</h2>
<p>Your message or call to action goes here.</p> <p>Scroll through to learn a little more about me!</p>
</section>
<div class="container">
<h2>About Us</h2> <div class="card mb-3" style="max-width: 540px;">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget dui in quam tincidunt malesuada. Vestibulum euismod urna a odio vulputate, ut cursus elit rhoncus.</p> <div class="row g-0">
<div class="col-md-4">
<img class="imga-fluid rounded-start" src="/img/headshot.jpg" alt="miguel headshot" style="width:100%">
</div> </div>
<div class="col-md-8">
<section>
<div class="container">
<div class="row">
<div class="container mt-3">
<h2>¡Soy Miguel!</h2>
<div class="card" style="width:400px">
<img class="card-img-top" src="/img/headshot.jpg" alt="miguel headshot" style="width:100%">
<div class="card-body"> <div class="card-body">
<h4 class="card-title">Miguel Almodovar</h4> <h5 class="card-title">Card title</h5>
<p class="card-text">Miguel es un profesional comunicatorio que esta aprendiendo como programar</p> <p class="card-text">Miguel is currently studying for a <a href="https://partners.comptia.org/certifications/a">COMPTIA certification</a> <br>
<a href="https://miguelalmodo.com/about" class="btn btn-primary">See Main Bio</a> Follow me on github and linkedin!</p>
<p class="card-text"><small class="text-body-secondary"><a href="https://miguelalmodo.com/about" class="btn btn-primary">See Main Bio</a>Last updated 3 months ago</small></p>
</div>
</div>
</div> </div>
</div> </div>
<br>
</div></div></div>
</section> </section>
</div>
<div class="container">
<section> <section>
<div class="container-fluid"> <div class="container-fluid">
<!-- In your HTML file --> <!-- In your HTML file -->
@ -116,43 +137,29 @@
</section> </section>
<section> <section>
<div class="container"> <div class="container">
<p>Aqui puedes completar tareas sobre la ciencia politica y varias otras temas</p> <p>Aqui puedes completar tareas sobre la ciencia politica y varias otras temas
<form class="d-flex" role="search">
<input type="search"
hx-get="/search"
hx-vals='{"searchQuery": "value"}'
hx-trigger="keyup delay:300ms"
hx-target="#resultsContainer"
placeholder="Search for EPUBs...">
</form>
</p>
</div> </div>
</section> </section>
<section> <section>
<!-- search results --> <!-- search results -->
<div id="resultsContainer"></div> <div id="resultsContainer"></div>
<!-- search results --> <!-- search results -->
</section> </section>
<section>
<div class="container">
<a href="https://migs.uber.space/reader/index.html" data-bibi="embed" data-bibi-style="[[ CSS for embeded Bibi frame, as you like ]]">[[ Title of the Book ]]</a>
<script src="/reader/resources/scripts/bibi.js"></script>
<iframe id="bibi-frame" src="/reader/index.html" width="100%" height="600px" frameborder="0"></iframe>
<script>
function loadEpubInBibi(epubUrl) {
document.getElementById('bibi-frame').src = "reader/?book=" + epubUrl;
}
</script>
</div>
</section>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>