Skip to content

Instantly share code, notes, and snippets.

@myobie
Created April 20, 2017 21:20
Show Gist options
  • Save myobie/08cfac28f9216f8cf99a41f410839aa4 to your computer and use it in GitHub Desktop.
Save myobie/08cfac28f9216f8cf99a41f410839aa4 to your computer and use it in GitHub Desktop.
Elixir code to generate a json file of all the svg slides in a directory
# curry the write function
write_data = &(File.write!("./assets/slides.json", &1))
Path.wildcard("./assets/slides/*.svg")
|> Enum.sort()
|> Enum.map(&Path.basename/1)
|> Enum.with_index(1)
|> Enum.map(fn {file, index} -> {file, Path.basename(file, ".svg"), index} end)
|> Enum.map(fn {file, name, index} ->
%{
number: index,
name: name,
path: "/assets/slides/#{file}"
}
end)
|> Poison.encode!()
|> write_data.()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment