# Slate/Middleman configuration
# Based on slatedocs/slate with customizations for monorepo API docs

# Markdown rendering
set :markdown_engine, :redcarpet
set :markdown,
    fenced_code_blocks: true,
    smartypants: true,
    disable_indented_code_blocks: true,
    prettify: true,
    strikethrough: true,
    tables: true,
    with_toc_data: true,
    no_intra_emphasis: true

# Syntax highlighting
activate :syntax
set :haml, { ugly: true }

# Assets
set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'
set :fonts_dir, 'fonts'

# Build directory
set :build_dir, 'build'

# Relative assets for static hosting
activate :relative_assets
set :relative_links, true

# Build-specific configuration
configure :build do
  activate :minify_css
  activate :minify_javascript, ignore: [/all_.*\.js/]
  activate :asset_hash
end

# Development helpers
helpers do
  def toc_data(page_content)
    content = page_content.dup
    toc = []

    content.scan(/<h([12]).*?id="([^"]+)".*?>(.+?)<\/h\1>/m) do |level, id, text|
      toc << {
        level: level.to_i,
        id: id,
        text: text.gsub(/<[^>]+>/, '')
      }
    end

    toc
  end
end
