ThemeManager API

The ThemeManager module handles color scheme switching and persistence.

Method / PropertyTypeDescription
ThemeManager.init()FunctionInitialize theme from localStorage or system preference. Call on DOMContentLoaded.
ThemeManager.toggle()FunctionSwitch between light and dark mode. Saves preference.
ThemeManager.apply(theme)FunctionApply a specific theme: "light" or "dark".
ThemeManager.STORAGE_KEYstringlocalStorage key used for persistence. Default: "webdocs-theme".
javascript
// Apply dark mode programmatically
ThemeManager.apply('dark');

// Toggle on button click
document.getElementById('my-toggle').addEventListener('click', () => {
  ThemeManager.toggle();
});
MethodDescription
Sidebar.init()Bind events, highlight active page link. Called automatically.
Sidebar.open()Open sidebar on mobile. Adds overlay, locks body scroll.
Sidebar.close()Close sidebar. Restores scroll. Also triggered on ESC.
Sidebar.toggle()Toggle sidebar open/closed state.

Search API

Customize the search by replacing or extending the Search.data array:

javascript
// Option 1: Add entries to the default data
Search.data.push({
  title: 'My New Page',
  desc: 'Description of the page',
  href: 'my-page.html'
});

// Option 2: Fetch from a JSON index (for large sites)
fetch('/search-index.json')
  .then(r => r.json())
  .then(data => { Search.data = data; });
FieldTypeRequiredDescription
titlestringYesPage title displayed in results
descstringYesShort description shown under title
hrefstringYesRelative URL of the page

REST API Endpoints

WebDocs can be extended with a backend. Here are the recommended endpoint patterns if you add one:

GET /api/search?q={query} Public
json
// Response:
{
  "results": [
    {
      "title": "Getting Started",
      "desc": "Install and configure your project",
      "href": "getting-started.html",
      "score": 0.95
    }
  ],
  "total": 1,
  "query": "start"
}
POST/api/feedbackAuth required
PUT/api/pages/{id}Admin only
DELETE/api/pages/{id}Admin only

Standard Response Format

json
{
  "success": true,
  "data": { /* response payload */ },
  "error": null,
  "meta": {
    "version": "2.0.0",
    "timestamp": "2026-06-25T00:00:00Z"
  }
}