diff --git a/app.py b/app.py index 25f7c6a..b5e4b1f 100644 --- a/app.py +++ b/app.py @@ -3,10 +3,12 @@ from flask import Flask from config import Config from routes.transcriptionRoute import transcription_bp from routes.scraperZLibraryRoute import scraperZLibraryRoute +from routes.headerRoute import header_bp def create_app(): """Application factory function""" - app = Flask(__name__, template_folder='views') + # static_folder=None → tắt hoàn toàn thư mục /static mặc định của Flask + app = Flask(__name__, template_folder='views', static_folder=None) # Load configuration app.config.from_object(Config) @@ -18,6 +20,7 @@ def create_app(): Config.init_app() # Register blueprints + app.register_blueprint(header_bp) app.register_blueprint(transcription_bp) app.register_blueprint(scraperZLibraryRoute, url_prefix='/scraperZLibrary') diff --git a/routes/headerRoute.py b/routes/headerRoute.py new file mode 100644 index 0000000..228db15 --- /dev/null +++ b/routes/headerRoute.py @@ -0,0 +1,11 @@ +# routes/headerRoute.py +from flask import Blueprint + +# Blueprint để serve headerLoader.js từ views/header/ +# → URL: /assets/header/headerLoader.js +header_bp = Blueprint( + 'header', + __name__, + static_folder='../views/header', + static_url_path='/assets/header', +) diff --git a/routes/scraperZLibraryRoute.py b/routes/scraperZLibraryRoute.py index b825923..ebf0598 100644 --- a/routes/scraperZLibraryRoute.py +++ b/routes/scraperZLibraryRoute.py @@ -1,23 +1,30 @@ -# routes/scraperZLibraryRoute.py -from flask import Blueprint -from controllers.scraperZLibraryController import ScraperController - -# Create blueprint -scraperZLibraryRoute = Blueprint('scraperZLibrary', __name__) - -# Define routes -scraperZLibraryRoute.route('/', methods=['GET'])(ScraperController.index) -scraperZLibraryRoute.route('/api/search', methods=['POST'])(ScraperController.search_books) -scraperZLibraryRoute.route('/api/download/txt', methods=['POST'])(ScraperController.download_txt) -scraperZLibraryRoute.route('/api/download/json', methods=['POST'])(ScraperController.download_json) -scraperZLibraryRoute.route('/api/download/books', methods=['POST'])(ScraperController.download_books_zip) # New route -scraperZLibraryRoute.add_url_rule( - '/api/download/stream', - view_func=ScraperController.download_books_stream, - methods=['POST'], -) -scraperZLibraryRoute.add_url_rule( - '/api/download/file/', - view_func=ScraperController.fetch_stored_file, - methods=['GET'], -) \ No newline at end of file +# routes/scraperZLibraryRoute.py +from flask import Blueprint +from controllers.scraperZLibraryController import ScraperController + +# Blueprint với static_folder trỏ vào views/scraperZLibraryPages +# → Flask serve CSS/JS qua URL /scraperZLibrary/assets/scraper/... +# Lưu ý: static_url_path chỉ cần phần sau /scraperZLibrary/ (url_prefix đã được thêm khi register) +scraperZLibraryRoute = Blueprint( + 'scraperZLibrary', + __name__, + static_folder='../views/scraperZLibraryPages', + static_url_path='/assets/scraper', +) + +# Define routes +scraperZLibraryRoute.route('/', methods=['GET'])(ScraperController.index) +scraperZLibraryRoute.route('/api/search', methods=['POST'])(ScraperController.search_books) +scraperZLibraryRoute.route('/api/download/txt', methods=['POST'])(ScraperController.download_txt) +scraperZLibraryRoute.route('/api/download/json', methods=['POST'])(ScraperController.download_json) +scraperZLibraryRoute.route('/api/download/books', methods=['POST'])(ScraperController.download_books_zip) # New route +scraperZLibraryRoute.add_url_rule( + '/api/download/stream', + view_func=ScraperController.download_books_stream, + methods=['POST'], +) +scraperZLibraryRoute.add_url_rule( + '/api/download/file/', + view_func=ScraperController.fetch_stored_file, + methods=['GET'], +) \ No newline at end of file diff --git a/routes/transcriptionRoute.py b/routes/transcriptionRoute.py index 40679ec..3fdb84a 100644 --- a/routes/transcriptionRoute.py +++ b/routes/transcriptionRoute.py @@ -1,14 +1,20 @@ -# routes/transcriptionRoute.py -from flask import Blueprint -from controllers.transcriptionController import TranscriptionController - -# Create blueprint -transcription_bp = Blueprint('transcription', __name__) - -# Define routes -transcription_bp.route('/', methods=['GET'])(TranscriptionController.index) -transcription_bp.route('/upload-chunk', methods=['POST'])(TranscriptionController.upload_chunk) -transcription_bp.route('/status/', methods=['GET'])(TranscriptionController.status) -transcription_bp.route('/transcript/', methods=['GET'])(TranscriptionController.download_transcript) -transcription_bp.route('/view/', methods=['GET'])(TranscriptionController.view_transcript) -transcription_bp.route('/jobs', methods=['GET'])(TranscriptionController.list_jobs) \ No newline at end of file +# routes/transcriptionRoute.py +from flask import Blueprint +from controllers.transcriptionController import TranscriptionController + +# Blueprint với static_folder trỏ vào views/transcriptionPages +# → Flask serve CSS/JS qua URL /assets/transcription/... +transcription_bp = Blueprint( + 'transcription', + __name__, + static_folder='../views/transcriptionPages', + static_url_path='/assets/transcription', +) + +# Define routes +transcription_bp.route('/', methods=['GET'])(TranscriptionController.index) +transcription_bp.route('/upload-chunk', methods=['POST'])(TranscriptionController.upload_chunk) +transcription_bp.route('/status/', methods=['GET'])(TranscriptionController.status) +transcription_bp.route('/transcript/', methods=['GET'])(TranscriptionController.download_transcript) +transcription_bp.route('/view/', methods=['GET'])(TranscriptionController.view_transcript) +transcription_bp.route('/jobs', methods=['GET'])(TranscriptionController.list_jobs) \ No newline at end of file diff --git a/views/header/headerLoader.js b/views/header/headerLoader.js new file mode 100644 index 0000000..38f961b --- /dev/null +++ b/views/header/headerLoader.js @@ -0,0 +1,234 @@ +// views/header/headerLoader.js +(function () { + "use strict"; + + // Configuration + const CONFIG = { + insertPosition: "afterbegin", + containerSelector: "body", + activeClass: "active", + version: "1.1", + }; + + // Header HTML inlined — không cần fetch file nữa + const headerHTML = ` +
+ +
`; + + const styles = ` + + `; + + // Inject header directly (no fetch needed) + function loadHeader() { + // Inject styles if not already present + if (!document.getElementById("header-component-styles")) { + document.head.insertAdjacentHTML("beforeend", styles); + } + + // Insert header HTML inline + const container = document.querySelector(CONFIG.containerSelector); + container.insertAdjacentHTML(CONFIG.insertPosition, headerHTML); + + // Highlight active link + highlightActiveLink(); + + console.log("✅ Header component loaded v" + CONFIG.version); + } + + // Highlight current page link + function highlightActiveLink() { + const currentPath = window.location.pathname; + const links = document.querySelectorAll(".nav-link"); + + links.forEach((link) => { + const href = link.getAttribute("href"); + + // Check if current path matches + if ( + currentPath === href || + (href !== "/" && currentPath.startsWith(href)) + ) { + link.classList.add(CONFIG.activeClass); + } + + // Special case for root + if (currentPath === "/" && href === "/transcription") { + link.classList.add(CONFIG.activeClass); + } + }); + } + + // Initialize when DOM is ready + if (document.readyState === "loading") { + document.addEventListener("DOMContentLoaded", loadHeader); + } else { + loadHeader(); + } +})(); diff --git a/views/scraperZLibraryPages/scraperZLibraryMain.html b/views/scraperZLibraryPages/scraperZLibraryMain.html index 0f91a8f..0438d9b 100644 --- a/views/scraperZLibraryPages/scraperZLibraryMain.html +++ b/views/scraperZLibraryPages/scraperZLibraryMain.html @@ -7,7 +7,7 @@ Tìm Kiếm Sách Z-Library - +
@@ -73,7 +73,7 @@
- - + + diff --git a/views/transcriptionPages/transcriptionMain.html b/views/transcriptionPages/transcriptionMain.html index c4701d5..e43f60c 100644 --- a/views/transcriptionPages/transcriptionMain.html +++ b/views/transcriptionPages/transcriptionMain.html @@ -7,7 +7,7 @@ Phiên Âm - +
@@ -105,7 +105,7 @@
- - + + diff --git a/views/transcriptionPages/transcriptionReview.html b/views/transcriptionPages/transcriptionReview.html index 424813f..d9874b8 100644 --- a/views/transcriptionPages/transcriptionReview.html +++ b/views/transcriptionPages/transcriptionReview.html @@ -7,7 +7,7 @@ Transcript - {{ filename }} - +
@@ -24,6 +24,6 @@
{{ content }}
- +