1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2024-11-02 17:17:57 +01:00
tldr/scripts/build_index.rb
Leandro Ostera e24d9800a8 refactors index building script to output JSON
also removes index.md
2015-03-04 21:10:36 -03:00

25 lines
545 B
Ruby
Executable file

#!/usr/bin/env ruby
require "json"
commands = {}
Dir["#{ENV["TLDRHOME"]}/pages/**/*.md"].each do |file|
# "./pages/osx/xsltproc.md",
file = file.split("/")
name = file.pop().gsub(".md","")
platform = file.pop()
unless commands.key?(name)
commands[name] = {
name: name,
platform: [platform]
}
else
commands[name][:platform] << platform
end
end
commands = commands.map do |k,v| v end
File.write("#{ENV["TLDRHOME"]}/pages/index.json", {commands: commands}.to_json)