Custom JavaScript
Add JavaScript to your site to enable dynamic functionality, telemetry, and more.
Add a site-wide script
Section titled “Add a site-wide script”To add a script to your entire site, use the head property in your astro.config.ts file to add the script to your site’s <head> element.
First, create a new JavaScript file in your project’s public directory:
console.log('Hello from my global script!');Next, add the script to your site’s <head> in your astro.config.ts file:
import { defineConfig } from "astro/config";import { stainlessDocs } from "@stainless-api/docs";
export default defineConfig({ integrations: [ stainlessDocs({ title: "My Docs", head: [ { tag: "script", attrs: { src: "global.js", }, }, ], }), ],});Your script will now be run every time any page of your site loads.
We recommend keeping your JavaScript in separate files, as outlined above, but you can provide JavaScript directly in astro.config.ts if you wish.
import { defineConfig } from "astro/config";import { stainlessDocs } from "@stainless-api/docs";
export default defineConfig({ integrations: [ stainlessDocs({ title: "My Docs", head: [ { tag: "script", content: `console.log('Hello from my inline script!');`, }, ], }), ],});Add JavaScript to a specific page
Section titled “Add JavaScript to a specific page”Stainless Docs is built on top of Astro, so you can add scripts to individual pages of your site using the approach in Astro’s client-side scripts documentation.