(spec: ConfigSpec = {}, defaultRoot?: string, watchPath?: string)
| 247 | const configCache = new WeakMap<ConfigSpec, Config>(); |
| 248 | |
| 249 | export function normalizeConfig(spec: ConfigSpec = {}, defaultRoot?: string, watchPath?: string): Config { |
| 250 | const cachedConfig = configCache.get(spec); |
| 251 | if (cachedConfig) return cachedConfig; |
| 252 | const root = spec.root === undefined ? findDefaultRoot(defaultRoot) : String(spec.root); |
| 253 | const output = spec.output === undefined ? "dist" : String(spec.output); |
| 254 | const base = spec.base === undefined ? "/" : normalizeBase(spec.base); |
| 255 | const style = |
| 256 | spec.style === null |
| 257 | ? null |
| 258 | : spec.style !== undefined |
| 259 | ? {path: String(spec.style)} |
| 260 | : {theme: normalizeTheme(spec.theme === undefined ? "default" : spec.theme)}; |
| 261 | const globalStylesheets = |
| 262 | spec.globalStylesheets === undefined |
| 263 | ? defaultGlobalStylesheets() |
| 264 | : normalizeGlobalStylesheets(spec.globalStylesheets); |
| 265 | const md = createMarkdownIt({ |
| 266 | linkify: spec.linkify === undefined ? undefined : Boolean(spec.linkify), |
| 267 | typographer: spec.typographer === undefined ? undefined : Boolean(spec.typographer), |
| 268 | quotes: spec.quotes === undefined ? undefined : (spec.quotes as any), |
| 269 | markdownIt: spec.markdownIt as any |
| 270 | }); |
| 271 | const title = spec.title === undefined ? undefined : String(spec.title); |
| 272 | const home = spec.home === undefined ? he.escape(title ?? "Home") : String(spec.home); // eslint-disable-line import/no-named-as-default-member |
| 273 | const pages = spec.pages === undefined ? undefined : normalizePages(spec.pages); |
| 274 | const pager = spec.pager === undefined ? true : Boolean(spec.pager); |
| 275 | const dynamicPaths = normalizeDynamicPaths(spec.dynamicPaths); |
| 276 | const toc = normalizeToc(spec.toc as any); |
| 277 | const sidebar = spec.sidebar === undefined ? undefined : Boolean(spec.sidebar); |
| 278 | const scripts = spec.scripts === undefined ? [] : normalizeScripts(spec.scripts); |
| 279 | const head = pageFragment(spec.head === undefined ? "" : spec.head); |
| 280 | const header = pageFragment(spec.header === undefined ? "" : spec.header); |
| 281 | const footer = pageFragment(spec.footer === undefined ? defaultFooter() : spec.footer); |
| 282 | const search = spec.search == null || spec.search === false ? null : normalizeSearch(spec.search as any); |
| 283 | const interpreters = normalizeInterpreters(spec.interpreters as any); |
| 284 | const normalizePath = getPathNormalizer(spec); |
| 285 | const duckdb = normalizeDuckDB(spec.duckdb); |
| 286 | |
| 287 | // If this path ends with a slash, then add an implicit /index to the |
| 288 | // end of the path. Otherwise, remove the .html extension (we use clean |
| 289 | // paths as the internal canonical representation; see normalizePage). |
| 290 | function normalizePagePath(pathname: string): string { |
| 291 | ({pathname} = parseRelativeUrl(pathname)); // ignore query & anchor |
| 292 | pathname = normalizePath(pathname); |
| 293 | if (pathname.endsWith("/")) pathname = join(pathname, "index"); |
| 294 | else pathname = pathname.replace(/\.html$/, ""); |
| 295 | return pathname; |
| 296 | } |
| 297 | |
| 298 | const config: Config = { |
| 299 | root, |
| 300 | output, |
| 301 | base, |
| 302 | home, |
| 303 | title, |
| 304 | sidebar: sidebar!, // see below |
| 305 | pages: pages!, // see below |
| 306 | pager, |
no test coverage detected