Revert temp API test

This commit is contained in:
Katos
2025-03-22 16:59:30 +00:00
committed by GitHub
parent 6b938a88cf
commit 7279703d7c

View File

@@ -4,28 +4,27 @@ sidebar: false
---
<script setup lang="ts">
import { ref, onMounted, watch, onBeforeUnmount } from 'vue';
import { ref, watch, onMounted, onBeforeUnmount } from 'vue';
import { useData } from 'vitepress';
const apiSpec = ref(null);
const demoBaseUrl = "https://demo.homebox.software/api";
// Reactive key for re-rendering the elements-api component
const componentKey = ref(0);
// Fetch and patch the spec on mount
onMounted(async () => {
try {
const res = await fetch('https://cdn.jsdelivr.net/gh/sysadminsmedia/homebox@main/docs/docs/api/openapi-2.0.json');
const spec = await res.json();
// Override the host and basePath
spec.host = "demo.homebox.software";
spec.basePath = "/api";
apiSpec.value = spec;
} catch (error) {
console.error("Error fetching the OpenAPI spec:", error);
}
// Set BaseURL
const BaseURL = "https://demo.homebox.software/api";
// Access dark mode setting from VitePress
const { isDark } = useData();
const theme = ref(isDark.value ? 'dark' : 'light');
// Watch for changes to the dark mode value and force a re-render when it changes
watch(isDark, (newVal) => {
theme.value = newVal ? 'dark' : 'light';
// Increment key to force a refresh of the Stoplight component and its CSS
componentKey.value++;
});
// For navigation refresh
const componentKey = ref(0);
// Use a native hashchange listener (as before) to refresh on navigation changes
const handleHashChange = () => {
componentKey.value++;
};
@@ -37,15 +36,7 @@ onBeforeUnmount(() => {
window.removeEventListener('hashchange', handleHashChange);
});
// Handle theme changes to re-render the component
const { isDark } = useData();
const theme = ref(isDark.value ? 'dark' : 'light');
watch(isDark, (newVal) => {
theme.value = newVal ? 'dark' : 'light';
componentKey.value++;
});
// Append Stoplight Elements script and stylesheet
// Append the Stoplight Elements script and stylesheet
const elementScript = document.createElement('script');
elementScript.src = 'https://unpkg.com/@stoplight/elements/web-components.min.js';
document.head.appendChild(elementScript);
@@ -57,15 +48,13 @@ document.head.appendChild(elementStyle);
</script>
<client-only>
<!-- Render only after the spec is loaded -->
<elements-api
v-if="apiSpec"
:key="componentKey"
:apiDescription="apiSpec"
apiDescriptionUrl="https://cdn.jsdelivr.net/gh/sysadminsmedia/homebox@main/docs/docs/api/openapi-2.0.json"
router="hash"
layout="responsive"
hideSchemas="true"
:data-theme="theme"
tryItBaseUrl="https://demo.homebox.software/api"
:tryItBaseUrl="BaseURL"
/>
</client-only>