// Extract internal wiki-link targets from a saved (already sanitized) body.
// Internal links are anchors to /wiki/<slug> or elements carrying a
// data-wiki-slug attribute. Returns a de-duplicated array of slugs.
function extractTargets(html) {
  if (!html) return []
  const targets = new Set()
  const hrefRe = /href="\/wiki\/([a-z0-9-]+)"/g
  const dataRe = /data-wiki-slug="([a-z0-9-]+)"/g
  let m
  while ((m = hrefRe.exec(html))) targets.add(m[1])
  while ((m = dataRe.exec(html))) targets.add(m[1])
  return [...targets]
}

module.exports = { extractTargets }
