You can do this most straightforwardly with proxy
:
# config.rb
proxy '/parent/sub00/file0.html', '/parent/sub0/sub00/file0.html', ignore: true
proxy '/parent/sub01/file1.html', '/parent/sub0/sub01/file1.html', ignore: true
proxy '/parent/sub10/file2.html', '/parent/sub1/sub10/file2.html', ignore: true
proxy '/parent/sub11/file3.html', '/parent/sub1/sub11/file3.html', ignore: true
$ tree source build
source
└── parent
├── sub0
│ ├── sub00
│ │ └── file0.adoc
│ └── sub01
│ └── file1.adoc
└── sub1
├── sub10
│ └── file2.adoc
└── sub11
└── file3.adoc
build
└── parent
├── sub00
│ └── file0.html
├── sub01
│ └── file1.html
├── sub10
│ └── file2.html
└── sub11
└── file3.html
The sitemap and frontmatter aren’t available during configuration, though—
# config.rb
puts "#{ sitemap.resources.length } during configuration"
after_configuration { puts "#{ sitemap.resources.length } after configuration" }
ready { puts "#{ sitemap.resources.length } when ready" }
$ middleman server
== The Middleman is loading
0 during configuration
0 after configuration
4 when ready
—so you’ll probably find a custom extension most useful:
# config.rb
require 'lib/rewrites'
activate :rewrites
# lib/rewrites.rb
class Rewrites < Middleman::Extension
def manipulate_resource_list(resources)
resources.each do |resource|
basename = File.basename(resource.path)
category = resource.data.category
resource.destination_path = File.join('parent', category, basename)
end
end
end
::Middleman::Extensions.register :rewrites, Rewrites
# source/parent/sub0/sub00/file0.adoc etc. frontmatter
category: 'sub00'