I have a few hundred posts in a blog that I’d like to transfer to Middleman. Some of these posts are tagged as private
.
I would like to set up two blog configs that build into separate directories, one including all posts and one that excludes those marked with the private
tag.
I have been able to exclude private posts from the index page using a filter
option in config.rb
:
blog.filter = Proc.new { |a| ! a.tags.include?('private') }
but they are still on the site and accessible by their URL, if known. So this alone is insufficient.
So the first part of my question therefore asks how can I always exclude pages containing the private
tag?
Taking things further, I’d like to be able to run the site (either serve
or build
) to optionally apply the private
filter. I see there are environments - development
and production
but I have so far been unable to understand how they work (I understand they’re different to v3 which means a lot of search results are now incorrect).
I did try just referring to a new private
environment and that seems to work.
if config.environment != :private
blog.filter = Proc.new { |a| ! a.tags.include?('private') }
end
and I can control that e.g. middleman -e private build
. But I don’t know if this is the right way to do this kind of thing.
I also experimended with adding a configure :private
block to set a private
option and build into a separate directory. I tried this:
configure :private do
config.private = false
set :build_dir, 'private'
end
along with this
activate :blog do |blog|
...
#unless config.private # <-- this isn't set here ?
if config.environment != :private # so I have to use this
blog.filter = Proc.new { |a| ! a.tags.include?('private') }
end
end
Both config.private = false
and set :config, false
work, so I don’t know the merits of one method over the other. But the option isn’t set before it is used despite coming first in config.rb
so I am unsure about that.
Also, although I can serve the custom environment, I cannot build it: middleman -e public build
runs a server.
The second part of my question therefore asks how do you properly implement a custom environment?
Hopefully I have missed existing documentation and can be told where to RTFM