Skip to content

Commit e8d11f7

Browse files
Filmbostock
andauthored
deprecate the scripts config option (#1296)
* deprecate the scripts config option closes #1272 * only warn once; scripts, not script --------- Co-authored-by: Mike Bostock <mbostock@gmail.com>
1 parent 68d2ae7 commit e8d11f7

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

docs/config.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -162,26 +162,6 @@ An HTML fragment to add to the header. Defaults to the empty string.
162162

163163
An HTML fragment to add to the footer. Defaults to “Built with Observable.”
164164

165-
## scripts
166-
167-
Additional scripts to add to the head, such as for analytics. For example, this:
168-
169-
```js run=false
170-
export default {
171-
scripts: [{type: "module", async: true, src: "analytics.js"}]
172-
};
173-
```
174-
175-
Is equivalent to setting the **head** option:
176-
177-
```js run=false
178-
export default {
179-
head: `<script type="module" async src="analytics.js"></script>`
180-
};
181-
```
182-
183-
We recommend you use the **head** option instead of this option.
184-
185165
## base
186166

187167
The base path when serving the site. Currently this only affects the custom 404 page, if any.

src/config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export interface Config {
5050
sidebar: boolean; // defaults to true if pages isn’t empty
5151
pages: (Page | Section<Page>)[];
5252
pager: boolean; // defaults to true
53-
scripts: Script[]; // defaults to empty array
53+
scripts: Script[]; // deprecated; defaults to empty array
5454
head: string | null; // defaults to null
5555
header: string | null; // defaults to null
5656
footer: string | null; // defaults to “Built with Observable on [date].”
@@ -201,7 +201,7 @@ export function normalizeConfig(spec: ConfigSpec = {}, defaultRoot?: string, wat
201201
const pager = spec.pager === undefined ? true : Boolean(spec.pager);
202202
const toc = normalizeToc(spec.toc as any);
203203
const sidebar = spec.sidebar === undefined ? undefined : Boolean(spec.sidebar);
204-
const scripts = spec.scripts === undefined ? [] : Array.from(spec.scripts as any, normalizeScript);
204+
const scripts = spec.scripts === undefined ? [] : normalizeScripts(spec.scripts);
205205
const head = spec.head === undefined ? "" : stringOrNull(spec.head);
206206
const header = spec.header === undefined ? "" : stringOrNull(spec.header);
207207
const footer = spec.footer === undefined ? defaultFooter() : stringOrNull(spec.footer);
@@ -270,6 +270,11 @@ export function normalizeTheme(spec: unknown): string[] {
270270
return resolveTheme(typeof spec === "string" ? [spec] : spec === null ? [] : Array.from(spec as any, String));
271271
}
272272

273+
function normalizeScripts(spec: unknown): Script[] {
274+
console.warn(`${yellow("Warning:")} the ${bold("scripts")} option is deprecated; use ${bold("head")} instead.`);
275+
return Array.from(spec as any, normalizeScript);
276+
}
277+
273278
function normalizeScript(spec: unknown): Script {
274279
const script = typeof spec === "string" ? {src: spec} : (spec as ScriptSpec);
275280
const src = String(script.src);

0 commit comments

Comments
 (0)