You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm hosting a static site on Azure Static Web Apps, built using MkDocs-Material. The site contains a main landing page and multiple sub-sites (each built individually using mkdocs) located in subdirectories (e.g., /sub-site1/, /sub-site2/). Each sub-site has its own index.html, assets (CSS, JS, images), and content pages.
While the main landing page loads correctly, sub-site pages fail to load their CSS and JavaScript and the navigation doesn't work properly in the sub-sites either. The browser tries to load the assets from the subdirectory of the current page (e.g., /sub-site1/page1/assets/stylesheets/main.css) instead of the correct directory root for the sub-site (e.g., /sub-site1/assets/stylesheets/main.css).
Debugging Insights
Configuration:
site_url in mkdocs.yml is set to the correct sub-site URL (e.g., https://example.com/sub-site1/) and for the landing page, it is set to https://example.com/.
use_directory_urls: true is used in all builds (I have tried setting this to false as well).
The browser throws errors like NS_ERROR_CORRUPTED_CONTENT or 404s for asset files.
The asset paths in the generated HTML are relative to the current page's directory rather than the sub-site root.
If I try and look at the link to a page in a sub-site, say https://example.com/sub-site1/page1 by clicking on a link in the sub-site home page (which loads without any styles or scripts), it shows as https://example.com/page1.
Question
How can I configure MkDocs and Azure Static Web Apps so that sub-site pages correctly load their assets (CSS, JS) without attempting to fetch them relative to the current page? Is there a specific MkDocs or Azure Static Web Apps configuration I might be missing? Any insights or similar experiences would be greatly appreciated! Or if it is even possible to host a structure like this (where we have a top level site as well as sub-sites built separately as sub-folders which will be linked as paths to the domain) as a static web app?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm hosting a static site on Azure Static Web Apps, built using MkDocs-Material. The site contains a main landing page and multiple sub-sites (each built individually using mkdocs) located in subdirectories (e.g.,
/sub-site1/
,/sub-site2/
). Each sub-site has its ownindex.html
, assets (CSS, JS, images), and content pages.Here's the structure of the deployed site:
Problem
While the main landing page loads correctly, sub-site pages fail to load their CSS and JavaScript and the navigation doesn't work properly in the sub-sites either. The browser tries to load the assets from the subdirectory of the current page (e.g.,
/sub-site1/page1/assets/stylesheets/main.css
) instead of the correct directory root for the sub-site (e.g.,/sub-site1/assets/stylesheets/main.css
).Debugging Insights
site_url
inmkdocs.yml
is set to the correct sub-site URL (e.g.,https://example.com/sub-site1/
) and for the landing page, it is set tohttps://example.com/
.use_directory_urls: true
is used in all builds (I have tried setting this to false as well).staticwebapp.config.json
looks like:NS_ERROR_CORRUPTED_CONTENT
or 404s for asset files.https://example.com/sub-site1/page1
by clicking on a link in the sub-site home page (which loads without any styles or scripts), it shows ashttps://example.com/page1
.Question
How can I configure MkDocs and Azure Static Web Apps so that sub-site pages correctly load their assets (CSS, JS) without attempting to fetch them relative to the current page? Is there a specific MkDocs or Azure Static Web Apps configuration I might be missing? Any insights or similar experiences would be greatly appreciated! Or if it is even possible to host a structure like this (where we have a top level site as well as sub-sites built separately as sub-folders which will be linked as paths to the domain) as a static web app?
Beta Was this translation helpful? Give feedback.
All reactions