%% -*- erlang -*-
%% The docs `rebar3 hex publish' builds with ex_doc. ex_doc reads the extras,
%% and names the source files, relative to the directory rebar3 runs in: the
%% umbrella's root or this application's. The paths are built from where
%% this file is, so that publishing works from either. Source links point at
%% main, since a release has no tag. rebar3_ex_doc warns that it does not
%% know `source_url_pattern'; it passes it on, and ex_doc uses it.
Dir = filename:dirname(filename:absname(SCRIPT)),
{ok, Cwd} = file:get_cwd(),
Prefix = case filename:absname(Cwd) =:= Dir of
             true -> "apps/" ++ filename:basename(Dir) ++ "/";
             false -> ""
         end,
Repo = "https://github.com/benoitc/wasm_storage",
Extra = fun(File) -> list_to_binary(filename:join(Dir, File)) end,
CONFIG ++ [{ex_doc, [
    {source_url, list_to_binary(Repo)},
    {source_url_pattern,
     list_to_binary(Repo ++ "/blob/main/" ++ Prefix ++ "%{path}#L%{line}")},
    {main, <<"readme">>},
    {extras, [Extra("README.md"), Extra("CHANGELOG.md")]},
    {groups_for_modules,
     [{"API", [wasm_sqlite]},
      {"Internals", [wasm_sqlite_db, wasm_sqlite_proto]}]}
]}].
