replace.astro 805 Bytes
---
import { createMatcher } from './html.ts'
import External from './external.astro'
import type { SlotHandler, Replacements } from './astro.ts'

interface Props {
  site?: string,
  page?: string,
  url?: string,
  html?: string,
  debug?: number,
  xpath?: string,
  replacements?: Replacements,
  adjustments?: any,
}

const { props } = Astro
const { debug = 0, replacements = {}, ...rest } = props

const replacers = Object.entries(replacements).map(([ selector, handler ]) => [ createMatcher(selector), handler ])

const slotHandler: SlotHandler = (slotName, node, special) => {
  return Astro.slots.render(slotName, [ node, { slotHandler, replacers, special } ] )
}
const nextDebug = debug ? debug - 1 : 0
---
<External {...rest} debug={nextDebug} replacers={replacers} slotHandler={slotHandler}/>