Skip to content

Commit

Permalink
new: [website] New optional blueprint able to serve the static HTML f…
Browse files Browse the repository at this point in the history
…iles generated by Sphinx for the documentation of Vulnerability-Lookup.
  • Loading branch information
cedricbonhomme committed Nov 22, 2024
1 parent 915f08f commit e27ac9f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions website/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from website.web import views

application.register_blueprint(views.home_bp)
application.register_blueprint(views.documentation_bp)
if get_config("generic", "user_accounts"):
application.config["user_accounts"] = True
application.register_blueprint(views.admin_bp)
Expand Down
2 changes: 2 additions & 0 deletions website/web/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from website.web.views.admin import admin_bp
from website.web.views.bundle import bundle_bp, bundles_bp
from website.web.views.comment import comment_bp, comments_bp
from website.web.views.documentation import documentation_bp
from website.web.views.home import home_bp
from website.web.views.user import user_bp, users_bp
from website.web.views.sighting import sighting_bp, sightings_bp
Expand All @@ -17,6 +18,7 @@
"bundle_bp",
"comment_bp",
"comments_bp",
"documentation_bp",
"sighting_bp",
"sightings_bp",
]
29 changes: 29 additions & 0 deletions website/web/views/documentation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3

from flask import abort
from flask import Blueprint
from flask import send_from_directory
from werkzeug import Response as WerkzeugResponse

from vulnerabilitylookup.default import get_homedir

# Define the blueprint
homedir = get_homedir()
static_folder = homedir.joinpath("docs/_build/html")
documentation_bp = Blueprint('documentation', __name__, url_prefix="/documentation", static_folder=static_folder)


@documentation_bp.route('/<path:filename>')
def serve_documentation(filename: str) -> WerkzeugResponse:
"""Serve static files from the Sphinx build folder."""
if None is documentation_bp.static_folder:
return abort(404)
return send_from_directory(documentation_bp.static_folder, filename)


@documentation_bp.route('/')
def serve_index() -> WerkzeugResponse:
"""Redirect `/documentation` to `/documentation/index.html`"""
if None is documentation_bp.static_folder:
return abort(404)
return send_from_directory(documentation_bp.static_folder, 'index.html')

0 comments on commit e27ac9f

Please sign in to comment.