# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at

#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

Dir['./lib/*'].each { |f| require f }

###
# Compass
###

# Change Compass configuration
# compass_config do |config|
#   config.output_style = :compact
# end

###
# Page options, layouts, aliases and proxies
###

# Per-page layout changes:
#
# With no layout
# page "/path/to/file.html", :layout => false
#
# With alternative layout
# page "/path/to/file.html", :layout => :otherlayout
#
# A path which all have the same layout
# with_layout :admin do
#   page "/admin/*"
# end

# Proxy pages (https://middlemanapp.com/dynamic-pages/)
# proxy "/this-page-has-no-template.html", "/template-file.html", :locals => {
#  :which_fake_page => "Rendering a fake page with a local variable" }

###
# Helpers
###

# Automatic image dimensions on image_tag helper
# activate :automatic_image_sizes

# Reload the browser automatically whenever files change
# activate :livereload

# Methods defined in the helpers block are available in templates
helpers do
  # Use this for the current release.
  def current_source_release_link(version)
    "<a href=\"https://www.apache.org/dyn/closer.cgi/datafu/apache-datafu-#{version}/apache-datafu-sources-#{version}.tgz\">
     apache-datafu-#{version}</a>
     [ <a href=\"https://www.apache.org/dist/datafu/apache-datafu-#{version}/apache-datafu-sources-#{version}.tgz.asc\">
     PGP</a> ]
     [ <a href=\"https://www.apache.org/dist/datafu/apache-datafu-#{version}/apache-datafu-sources-#{version}.tgz.sha512\">
     SHA512</a> ]"
  end

  # Use this for old releases >= 1.4.0  and < current
  def archived_source_release_link(version)
    "<a href=\"https://archive.apache.org/dist/datafu/apache-datafu-#{version}/apache-datafu-sources-#{version}.tgz\">
     apache-datafu-sources-#{version}.tgz</a>
     [ <a href=\"https://archive.apache.org/dist/datafu/apache-datafu-#{version}/apache-datafu-sources-#{version}.tgz.asc\">
     PGP</a> ]
     [ <a href=\"https://archive.apache.org/dist/datafu/apache-datafu-#{version}/apache-datafu-sources-#{version}.tgz.sha512\">
     SHA512</a> ]"
  end

  def inner_text(html)
    Nokogiri.HTML(html).text.gsub(/\s+/, " ")
  end
end

set :css_dir, 'stylesheets'

set :js_dir, 'javascripts'

set :images_dir, 'images'

activate :syntax

set :markdown_engine, :redcarpet
set :markdown, :tables => true, :autolink => true, :gh_blockcode => true, :fenced_code_blocks => true, :with_toc_data => true

# Build-specific configuration
configure :build do
  # For example, change the Compass output style for deployment
  # activate :minify_css

  # Minify Javascript on build
  # activate :minify_javascript

  # Enable cache buster
  # activate :asset_hash

  # Use relative URLs
  # activate :relative_assets

  # Or use a different image path
  # set :http_prefix, "/Content/images/"
end

activate :blog do |blog|
  blog.prefix = "blog"
  blog.layout = "blog"
end

page "/", :layout => "docs"
page "/docs/*", :layout => "docs"
page "/community/*", :layout => "docs"

