Skip to content

Instantly share code, notes, and snippets.

@fatso83
Last active July 31, 2016 10:06
Show Gist options
  • Save fatso83/e403f5ee2500487088ab0598e49a7d91 to your computer and use it in GitHub Desktop.
Save fatso83/e403f5ee2500487088ab0598e49a7d91 to your computer and use it in GitHub Desktop.
Example of automatically adding collections to _config.yml
require "set"
require "pathname"
require "yaml"
docs_folder = "resources/main-project-repo/docs/"
config = YAML.load_file "_config.yml"
version_folders = Pathname.new(docs_folder).children.select do |c|
c.directory?
end
doc_versions = version_folders.collect { |pn| pn.basename.to_s }
# Add unique new collections to existing
if config["collections"]
collections = doc_versions.concat(config["collections"])
else
collections = doc_versions
end
config["collections"] = Set.new(collections).to_a
print config
File.open("_config.yml", 'wb') { |f| YAML.dump(config, f) }
# Now do the actual build
jekyll build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment