Improve doc generation

- Downloads all the mdn documentation in parallel
- Enables the `--silent` flag for curl
- Aliases the docs mix task to run update_mdn_docs first
This commit is contained in:
Mitchell Hanberg 2019-06-30 21:59:38 -04:00
parent 34203fcb0d
commit fb5147ff97
2 changed files with 24 additions and 15 deletions

View file

@ -7,23 +7,26 @@ defmodule Mix.Tasks.UpdateMdnDocs do
@shortdoc "Update the MDN documentation"
def run(_) do
(Dsl.Tags.nonvoid_elements() ++ Dsl.Tags.void_elements())
|> Enum.each(fn el ->
el = to_string(el)
|> Enum.map(fn el ->
Task.async(fn ->
el = to_string(el)
page =
if Enum.any?(["h1", "h2", "h3", "h4", "h5", "h6"], &(&1 == el)) do
"Heading_Elements"
else
el
end
page =
if Enum.any?(["h1", "h2", "h3", "h4", "h5", "h6"], &(&1 == el)) do
"Heading_Elements"
else
el
end
{doc, 0} = System.cmd("curl", [@baseurl <> page <> @params])
File.mkdir_p!("./tmp/docs/")
{doc, 0} = System.cmd("curl", ["--silent", @baseurl <> page <> @params])
File.mkdir_p!("./tmp/docs/")
path = "./tmp/docs/" <> el <> ".txt"
doc = HtmlSanitizeEx.strip_tags(doc)
path = "./tmp/docs/" <> el <> ".txt"
doc = HtmlSanitizeEx.strip_tags(doc)
File.write!(path, doc)
File.write!(path, doc)
end)
end)
|> Enum.each(&Task.await/1)
end
end

10
mix.exs
View file

@ -4,12 +4,13 @@ defmodule Dsl.MixProject do
def project do
[
app: :dsl,
name: "Dsl",
version: "0.1.0",
elixirc_paths: elixirc_paths(Mix.env()),
elixir: "~> 1.7",
start_permanent: Mix.env() == :prod,
deps: deps(),
name: "Dsl",
aliases: aliases(),
source_url: "https://github.com/mhanberg/dsl",
docs: [
main: "Dsl",
@ -32,8 +33,13 @@ defmodule Dsl.MixProject do
extra_applications: [:logger]
]
end
defp aliases do
[
docs: ["update_mdn_docs", "docs"]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:phoenix_html, "~> 2.13"},