Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

Fix public docs to remove github URL

Philb044b3eb042f
diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs
index 4ac2444f..48146792 100644
--- a/docs/astro.config.mjs
+++ b/docs/astro.config.mjs
@@ -60,8 +60,9 @@ export default defineConfig({
starlightOpenAPI([
{
base: 'en/api',
- schema:
- 'https://raw.githubusercontent.com/sysadminsmedia/homebox/refs/heads/main/docs/public/api/openapi-3.0.json',
+ // Load the schema from this docs site so relative server URLs
+ // (e.g. /api) resolve against the current host.
+ schema: './public/api/openapi-3.0.json',
},
]),
starlightSidebarTopics(
diff --git a/docs/src/components/theme/Header.astro b/docs/src/components/theme/Header.astro
index 98721f61..f0847441 100644
--- a/docs/src/components/theme/Header.astro
+++ b/docs/src/components/theme/Header.astro
@@ -10,3 +10,70 @@ import Default from '@astrojs/starlight/components/Header.astro';
<!-- Starlight will handle all the layout -->
</Fragment>
</Default>
+
+<script is:inline>
+ (() => {
+ const RAW_GITHUB_HOST = 'raw.githubusercontent.com';
+ const RAW_GITHUB_FALLBACK_ORIGIN = 'https://demo.homeboxsoftware.com';
+
+ const resolveOrigin = (hostname) => {
+ if (hostname === RAW_GITHUB_HOST) {
+ return RAW_GITHUB_FALLBACK_ORIGIN;
+ }
+
+ return window.location.origin;
+ };
+
+ const normalizeApiUrl = (value) => {
+ if (typeof value !== 'string' || value.length === 0) {
+ return value;
+ }
+
+ let parsed;
+ try {
+ parsed = new URL(value, window.location.origin);
+ } catch {
+ return value;
+ }
+
+ if (!parsed.pathname.startsWith('/api')) {
+ return value;
+ }
+
+ const targetOrigin = resolveOrigin(parsed.hostname);
+ return `${targetOrigin}${parsed.pathname}${parsed.search}${parsed.hash}`;
+ };
+
+ const updateElementValue = (el) => {
+ if (!(el instanceof HTMLInputElement || el instanceof HTMLOptionElement)) {
+ return;
+ }
+
+ const normalized = normalizeApiUrl(el.value);
+ if (normalized === el.value) {
+ return;
+ }
+
+ el.value = normalized;
+ el.dispatchEvent(new Event('input', { bubbles: true }));
+ el.dispatchEvent(new Event('change', { bubbles: true }));
+ };
+
+ const applyApiUrlGuard = () => {
+ if (!window.location.pathname.includes('/api')) {
+ return;
+ }
+
+ for (const el of document.querySelectorAll('input, option')) {
+ updateElementValue(el);
+ }
+ };
+
+ const observer = new MutationObserver(applyApiUrlGuard);
+
+ window.addEventListener('load', () => {
+ applyApiUrlGuard();
+ observer.observe(document.body, { childList: true, subtree: true });
+ });
+ })();
+</script>