mirror of
https://github.com/multipleof4/ntfy.git
synced 2026-10-11 14:25:21 +00:00
Refine open API docs
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>ntfy API Reference</title>
|
||||
<link rel="icon" type="image/svg+xml" href="https://ntfy.sh/static/img/favicon.svg">
|
||||
<link rel="icon" type="image/png" href="/static/img/favicon.png">
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
@@ -70,43 +70,22 @@
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Proxy toggle checkbox */
|
||||
.proxy-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-left: 20px;
|
||||
padding: 8px 12px;
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.proxy-toggle:hover {
|
||||
background: rgba(255, 255, 255, 0.25);
|
||||
}
|
||||
|
||||
.proxy-toggle input[type="checkbox"] {
|
||||
cursor: pointer;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
.proxy-toggle label {
|
||||
color: white;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
/* Scalar container */
|
||||
#scalar-api-reference {
|
||||
width: 100%;
|
||||
min-height: calc(100vh - 100px);
|
||||
}
|
||||
|
||||
/* Hide Share and Generate SDKs menu items */
|
||||
[data-scalar-menu-item="share"],
|
||||
[data-scalar-menu-item="sdk"],
|
||||
.scalar-card-header-actions button[title="Share"],
|
||||
.scalar-card-header-actions button[title="Generate SDK"],
|
||||
button:has(> span:contains("Share")),
|
||||
button:has(> span:contains("SDK")) {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 768px) {
|
||||
.header-content {
|
||||
@@ -126,7 +105,7 @@
|
||||
<div class="header">
|
||||
<div class="header-content">
|
||||
<a href="/" style="display: flex; align-items: center; text-decoration: none;">
|
||||
<img src="https://docs.ntfy.sh/static/img/ntfy.png" width="35" height="35" alt="ntfy logo" style="margin-right: 10px;">
|
||||
<img src="/static/img/ntfy.png" width="35" height="35" alt="ntfy logo" style="margin-right: 10px;">
|
||||
</a>
|
||||
<div class="header-text">
|
||||
<h1>ntfy</h1>
|
||||
@@ -136,61 +115,16 @@
|
||||
<a href="/">Documentation Home</a>
|
||||
<a href="https://ntfy.sh">ntfy.sh</a>
|
||||
<a href="https://github.com/binwiederhier/ntfy">GitHub</a>
|
||||
<div class="proxy-toggle" title="Enable CORS proxy to make requests through Scalar's proxy server">
|
||||
<input type="checkbox" id="proxy-toggle-checkbox" checked>
|
||||
<label for="proxy-toggle-checkbox">Use CORS Proxy</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Scalar API Reference -->
|
||||
<div id="scalar-api-reference"></div>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.43.8/dist/browser/style.css" />
|
||||
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.43.8/dist/browser/standalone.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="./scalar-style.css" />
|
||||
<script src="./scalar-standalone.js"></script>
|
||||
|
||||
<script>
|
||||
// Store the Scalar instance globally so we can reinitialize it
|
||||
let scalarInstance = null;
|
||||
|
||||
// Get proxy preference from localStorage (default: true)
|
||||
function getProxyEnabled() {
|
||||
const stored = localStorage.getItem('scalar-proxy-enabled');
|
||||
return stored === null ? true : stored === 'true';
|
||||
}
|
||||
|
||||
// Save proxy preference to localStorage
|
||||
function setProxyEnabled(enabled) {
|
||||
localStorage.setItem('scalar-proxy-enabled', enabled.toString());
|
||||
}
|
||||
|
||||
// Initialize checkbox state
|
||||
function initProxyCheckbox() {
|
||||
const checkbox = document.getElementById('proxy-toggle-checkbox');
|
||||
if (checkbox) {
|
||||
checkbox.checked = getProxyEnabled();
|
||||
|
||||
// Add change listener
|
||||
checkbox.addEventListener('change', function() {
|
||||
const enabled = checkbox.checked;
|
||||
setProxyEnabled(enabled);
|
||||
// Reinitialize Scalar with new proxy setting
|
||||
reinitializeScalar();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Reinitialize Scalar with current proxy setting
|
||||
function reinitializeScalar() {
|
||||
const targetElement = document.getElementById('scalar-api-reference');
|
||||
if (targetElement) {
|
||||
// Clear the container
|
||||
targetElement.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Reinitializing API Reference...</div>';
|
||||
// Reinitialize
|
||||
setTimeout(initScalar, 100);
|
||||
}
|
||||
}
|
||||
|
||||
function initScalar() {
|
||||
const targetElement = document.getElementById('scalar-api-reference');
|
||||
|
||||
@@ -204,14 +138,25 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Get proxy setting
|
||||
const useProxy = getProxyEnabled();
|
||||
|
||||
// Build config object
|
||||
const config = {
|
||||
url: './openapi.yaml',
|
||||
layout: 'modern',
|
||||
theme: 'default',
|
||||
customCss: `
|
||||
/* Hide Share and Generate SDKs menu items in dropdowns */
|
||||
[data-testid="share-button"],
|
||||
[data-testid="sdk-button"],
|
||||
.context-menu-item:has(svg[data-icon="share"]),
|
||||
.context-menu-item:has(svg[data-icon="sdk"]),
|
||||
.dropdown-item:has(span:contains("Share")),
|
||||
.dropdown-item:has(span:contains("SDK")),
|
||||
.scalar-dropdown-item[data-action="share"],
|
||||
.scalar-dropdown-item[data-action="generate-sdk"],
|
||||
button[aria-label="Share"],
|
||||
button[aria-label="Generate SDK"] {
|
||||
display: none !important;
|
||||
}
|
||||
`,
|
||||
configuration: {
|
||||
hideSidebar: false,
|
||||
hideSearch: false,
|
||||
@@ -223,36 +168,23 @@
|
||||
darkMode: false,
|
||||
withDefaultFonts: false,
|
||||
},
|
||||
};
|
||||
|
||||
// Only add proxyUrl if enabled
|
||||
if (useProxy) {
|
||||
config.proxyUrl = 'https://proxy.scalar.com';
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const apiRef = Scalar.createApiReference('#scalar-api-reference', config);
|
||||
console.log('Scalar initialized successfully', useProxy ? 'with proxy' : 'without proxy');
|
||||
Scalar.createApiReference('#scalar-api-reference', config);
|
||||
} catch (error) {
|
||||
console.error('Error initializing Scalar:', error);
|
||||
targetElement.innerHTML = '<div style="padding: 20px; color: red;">Error loading API reference: ' + error.message + '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize checkbox first
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
initProxyCheckbox();
|
||||
initScalar();
|
||||
});
|
||||
document.addEventListener('DOMContentLoaded', initScalar);
|
||||
} else {
|
||||
initProxyCheckbox();
|
||||
setTimeout(initScalar, 100);
|
||||
}
|
||||
|
||||
// Also try on window load as fallback
|
||||
window.addEventListener('load', function() {
|
||||
initProxyCheckbox();
|
||||
setTimeout(initScalar, 200);
|
||||
});
|
||||
</script>
|
||||
+506
-742
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user