1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Docs.JSON do
6 @behaviour Pleroma.Docs.Generator
7 @external_resource "config/description.exs"
8 @raw_config Pleroma.Config.Loader.read("config/description.exs")
9 @raw_descriptions @raw_config[:pleroma][:config_description]
10 @term __MODULE__.Compiled
15 Pleroma.Web.ActivityPub.MRF.config_descriptions()
16 |> Enum.reduce(@raw_descriptions, fn description, acc -> [description | acc] end)
18 :persistent_term.put(@term, Pleroma.Docs.Generator.convert_to_strings(descriptions))
21 @spec compiled_descriptions :: Map.t()
22 def compiled_descriptions do
23 :persistent_term.get(@term)
26 @spec process(keyword()) :: {:ok, String.t()}
27 def process(descriptions) do
28 with path <- "docs/docs/generated_config.json",
29 {:ok, file} <- File.open(path, [:write, :utf8]),
30 formatted_descriptions <-
31 Pleroma.Docs.Generator.convert_to_strings(descriptions),
32 json <- Jason.encode!(formatted_descriptions),
33 :ok <- IO.write(file, json),
34 :ok <- File.close(file) do