Current section

Files

Jump to
griffin_ssg lib griffin.ex
Raw

lib/griffin.ex

defmodule Griffin do
@moduledoc """
This is the documentation for the Griffin project.
By default, Griffin will scan for content in the `priv/content` directory
and output generated files to the `_site` directory.
Griffin depends on the following libraries:
* [Plug](https://hexdocs.pm/plug) - a specification and conveniences
for composable modules in between web applications
"""
use Application
@doc false
def start(_type, _args) do
children = [
{Plug.Cowboy, scheme: :http, plug: Griffin.Web.Plug, options: [port: 4000]}
]
Supervisor.start_link(children, strategy: :one_for_one, name: Griffin.Supervisor)
end
@doc false
def process_file(path) do
IO.inspect("reading from #{path}")
content = File.read!(path)
# string split crashes if the file only contains html and
# does not contain front matter annotations.
[yaml, markdown] = String.split(content, ~r/\n---\n/, parts: 2)
[metadata] = YamlElixir.read_all_from_string!(yaml, atoms: true)
html = Earmark.as_html!(markdown)
IO.inspect(html)
metadata =
metadata
|> Map.put("content", html)
|> Enum.map(fn {k,v} -> {String.to_atom(k), v} end)
|> IO.inspect(label: "metadata")
# IO.inspect(html, label: "html")
rendered =
EEx.eval_file("installer/blog/priv/layouts/default.html.eex", assigns: metadata)
unless html == "" do
output_path = Path.expand("#{path}.html")
IO.inspect("writing to #{output_path}")
File.write!(output_path, rendered)
end
:ok
end
end