Created
March 7, 2020 15:12
-
-
Save zookzook/88963c93c32b4d940778533a493a663b to your computer and use it in GitHub Desktop.
Module Site
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Polaris.Site do | |
| @moduledoc false | |
| alias Polaris.Page | |
| pages_paths = "hocon/**/*.conf" |> Path.wildcard() |> Enum.sort() | |
| pages = for page_path <- pages_paths do | |
| @external_resource Path.relative_to_cwd(page_path) | |
| Page.parse!(page_path) | |
| end | |
| @pages Enum.reduce(pages, %{}, fn page, map -> Map.put(map, Page.make_key(page), page) end) | |
| def all_pages() do | |
| @pages | |
| end | |
| def index() do | |
| get(Page.make_key(nil, "index.conf")) | |
| end | |
| def get(key) do | |
| all_pages()[key] | |
| end | |
| def get_urls() do | |
| all_pages() |> Map.keys() |> Enum.map(fn file -> String.replace(file, "conf", "html") end) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment