Skip to content

Commit

Permalink
static and app_path refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fzumstein committed Oct 30, 2024
1 parent 3986777 commit 96d5f8d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
5 changes: 5 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .routers.manifest import router as manifest_router
from .routers.taskpane import router as taskpane_router
from .routers.xlwings import router as xlwings_router
from .templates import templates

# Logging
logging.basicConfig(level=settings.log_level.upper())
Expand All @@ -23,6 +24,10 @@
# App
app = FastAPI(docs_url=None, redoc_url=None, openapi_url=None)

# Starlette's url_for returns fully qualified URLs causing issues if the reverse proxy
# handles TLS and the app runs on http (https://github.com/encode/starlette/issues/843)
templates.env.globals["url_for"] = app.url_path_for

# Register Converter
ObjectCacheConverter.register(object, "object", "obj")

Expand Down
56 changes: 28 additions & 28 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Task pane</title>
<link rel="icon" type="image/png" href="{{ settings.static_url_path }}/images/favicon.png" />
<link rel="icon" type="image/png" href="{{ url_for('static', path='/images/favicon.png') }}" />
{# htmx #}
{% if settings.enable_htmx %}
<script src="{{ settings.static_url_path }}/vendor/htmx.org/dist/htmx.min.js"></script>
<script src="{{ settings.static_url_path }}/vendor/htmx-ext-head-support/head-support.js"></script>
<script src="{{ settings.static_url_path }}/vendor/htmx-ext-loading-states/loading-states.js"></script>
<script src="{{ settings.static_url_path }}/js/core/htmx-handlers.js" defer></script>
<script src="{{ url_for('static', path='/vendor/htmx.org/dist/htmx.min.js') }}"></script>
<script src="{{ url_for('static', path='/vendor/htmx-ext-head-support/head-support.js') }}"></script>
<script src="{{ url_for('static', path='/vendor/htmx-ext-loading-states/loading-states.js') }}"></script>
<script src="{{ url_for('static', path='/js/core/htmx-handlers.js') }}" defer></script>
{% endif %}
<script src="{{ settings.static_url_path }}/js/core/officejs-history-fix-part1.js"></script>
<script src="{{ url_for('static', path='/js/core/officejs-history-fix-part1.js') }}"></script>
{# Office.js #}
{% if settings.public_addin_store %}
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
{% else %}
<script src="{{ settings.static_url_path }}/vendor/@microsoft/office-js/dist/office.js"></script>
<script src="{{ url_for('static', path='/vendor/@microsoft/office-js/dist/office.js') }}"></script>
{% endif %}
<script src="{{ settings.static_url_path }}/js/core/officejs-history-fix-part2.js"></script>
<script src="{{ url_for('static', path='/js/core/officejs-history-fix-part2.js') }}"></script>
{# Socket.io (must come before xlwings.js) #}
{% if settings.enable_socketio %}
<script src="{{ settings.static_url_path }}/vendor/socket.io/client-dist/socket.io.min.js"></script>
<script src="{{ url_for('static', path='/vendor/socket.io/client-dist/socket.io.min.js') }}"></script>
{% endif %}
{# xlwings.js (must come before custom-function-code) #}
<script type="module" src="{{ settings.static_url_path }}/js/core/xlwingsjs/xlwings.js" defer></script>
<script type="module" src="{{ settings.static_url_path }}/js/core/xlwingsjs/auth.js" defer></script>
<script type="module" src="{{ settings.static_url_path }}/js/core/xlwingsjs/utils.js" defer></script>
<script type="module" src="{{ settings.static_url_path }}/js/core/xlwingsjs/alert.js" defer></script>
<script type="module" src="{{ url_for('static', path='/js/core/xlwingsjs/xlwings.js') }}" defer></script>
<script type="module" src="{{ url_for('static', path='/js/core/xlwingsjs/auth.js') }}" defer></script>
<script type="module" src="{{ url_for('static', path='/js/core/xlwingsjs/utils.js') }}" defer></script>
<script type="module" src="{{ url_for('static', path='/js/core/xlwingsjs/alert.js') }}" defer></script>
{# Alpine.js CSP boilerplate (must come before custom JS, which must come before alpinejs library) #}
{% if settings.enable_alpinejs_csp %}
<script src="{{ settings.static_url_path }}/js/core/alpinejs-csp-boilerplate.js" defer></script>
<script src="{{ url_for('static', path='/js/core/alpinejs-csp-boilerplate.js') }}" defer></script>
{% endif %}
{# JS Config #}
<!-- prettier-ignore-start -->
Expand All @@ -46,37 +46,37 @@
{ "xlwingsVersion": {{ settings.xlwings_version|tojson }} }
</script>
<!-- prettier-ignore-end -->
<script src="{{ settings.static_url_path }}/js/auth.js"></script>
<script src="{{ url_for('static', path='/js/auth.js') }}"></script>
{# Load Custom Functions #}
<script src="{{ settings.app_path }}/xlwings/custom-functions-code" defer></script>
<script src="{{ url_for('static', path='/xlwings/custom-functions-code') }}" defer></script>
{# Bootstrap with the xlwings theme #}
{% if settings.enable_bootstrap %}
<link
rel="stylesheet"
href="{{ settings.static_url_path }}/vendor/bootstrap-xlwings/dist/bootstrap-xlwings.min.css" />
<script src="{{ settings.static_url_path }}/vendor/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="{{ settings.static_url_path }}/js/core/bootstrap-customizations.js" defer></script>
href="{{ url_for('static', path='/vendor/bootstrap-xlwings/dist/bootstrap-xlwings.min.css') }}" />
<script src="{{ url_for('static', path='/vendor/bootstrap/dist/js/bootstrap.bundle.min.js') }}"></script>
<script src="{{ url_for('static', path='/js/core/bootstrap-customizations.js') }}" defer></script>
{% endif %}
{# Examples #}
{% if settings.enable_examples %}
<script src="{{ settings.static_url_path }}/js/core/examples.js" defer></script>
<script src="{{ url_for('static', path='/js/core/examples.js') }}" defer></script>
{% endif %}
{# Own #}
<link rel="stylesheet" href="{{ settings.static_url_path }}/css/core.css" />
<link rel="stylesheet" href="{{ settings.static_url_path }}/css/style.css" />
<link rel="stylesheet" href="{{ url_for('static', path='/css/core.css') }}" />
<link rel="stylesheet" href="{{ url_for('static', path='/css/style.css') }}" />
{% if settings.enable_socketio %}
<script src="{{ settings.static_url_path }}/js/core/socketio-handlers.js" defer></script>
<script src="{{ url_for('static', path='/js/core/socketio-handlers.js') }}" defer></script>
{% endif %}
<script src="{{ settings.app_path }}/xlwings/custom-scripts-sheet-buttons" defer></script>
<script src="{{ settings.static_url_path }}/js/core/sheet-buttons.js" defer></script>
<script src="{{ settings.static_url_path }}/js/main.js" defer></script>
<script src="{{ settings.static_url_path }}/js/ribbon.js" defer></script>
<script src="{{ url_for('static', path='/js/core/sheet-buttons.js') }}" defer></script>
<script src="{{ url_for('static', path='/js/main.js') }}" defer></script>
<script src="{{ url_for('static', path='/js/ribbon.js') }}" defer></script>
{% if settings.environment == "dev" and settings.enable_socketio %}
<script src="{{ settings.static_url_path }}/js/core/hotreload.js" defer></script>
<script src="{{ url_for('static', path='/js/core/hotreload.js') }}" defer></script>
{% endif %}
{# Alpine.js CSP build (must come after alpinejs-csp-boilerplate.js and custom code such as main.js) #}
{% if settings.enable_alpinejs_csp %}
<script src="{{ settings.static_url_path }}/vendor/@alpinejs/csp/dist/cdn.min.js" defer></script>
<script src="{{ url_for('static', path='/vendor/@alpinejs/csp/dist/cdn.min.js') }}" defer></script>
{% endif %}
{% endblock head %}
{% block extra_head %}
Expand Down

0 comments on commit 96d5f8d

Please sign in to comment.