Skip to content

Commit 07d8dd9

Browse files
authored
feat: add docs (#119)
1 parent 98ed5a3 commit 07d8dd9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+5234
-45
lines changed

assets/tailwind.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414
"../lib/*_web.ex",
1515
"../lib/*_web/**/*.*ex",
1616
"./svelte/**/*.svelte",
17+
"../priv/content/**/*.md",
1718
],
1819
theme: {
1920
container: {

config/config.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ config :algora,
1616
redirects: [
1717
{"/tv", "https://tv.algora.io"},
1818
{"/discord", "https://discord.gg/9RXD2nqbnG"},
19+
{"/docs/bounties/payments", "/docs/payments"},
1920
{"/sdk", "https://github.com/algora-io/sdk"},
2021
{"/healthcare", "https://blog.algora.io/post/healthcare"},
2122
{"/podcast", "https://www.youtube.com/@algora-io/podcasts"},

lib/algora/bot_templates/bot_templates.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defmodule Algora.BotTemplates do
1010
### Steps to solve:
1111
1. **Start working**: Comment `/attempt #${ISSUE_NUMBER}` with your implementation plan
1212
2. **Submit work**: Create a pull request including `/claim #${ISSUE_NUMBER}` in the PR body to claim the bounty
13-
3. **Receive payment**: 100% of the bounty is received 2-5 days post-reward. [Make sure you are eligible for payouts](https://docs.algora.io/bounties/payments#supported-countries-regions)
13+
3. **Receive payment**: 100% of the bounty is received 2-5 days post-reward. [Make sure you are eligible for payouts](https://algora.io/docs/payments#supported-countries-regions)
1414
1515
Thank you for contributing to ${REPO_FULL_NAME}!
1616
${ATTEMPTS}

lib/algora/content.ex

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Algora.Content do
55

66
alias Algora.Markdown
77

8-
defstruct [:slug, :title, :date, :tags, :authors, :content]
8+
defstruct [:slug, :title, :date, :tags, :authors, :content, :path]
99

1010
defp base_path, do: Path.join([:code.priv_dir(:algora), "content"])
1111

@@ -38,6 +38,57 @@ defmodule Algora.Content do
3838
|> Enum.sort_by(& &1.date, :desc)
3939
end
4040

41+
def list_content_rec(directory) do
42+
list_content_rec_helper([base_path(), directory], directory)
43+
end
44+
45+
defp list_content_rec_helper(path, root_dir) do
46+
case File.ls(Path.join(path)) do
47+
{:ok, entries} ->
48+
entries
49+
|> Enum.reduce(%{files: [], dirs: %{}}, fn entry, acc ->
50+
full_path = Path.join(path ++ [entry])
51+
52+
cond do
53+
File.dir?(full_path) ->
54+
nested_content = list_content_rec_helper(path ++ [entry], root_dir)
55+
put_in(acc, [:dirs, entry], nested_content)
56+
57+
String.ends_with?(entry, ".md") ->
58+
# Get the path relative to base_path
59+
relative_path =
60+
full_path
61+
|> Path.relative_to(base_path())
62+
|> Path.rootname(".md")
63+
64+
path_segments =
65+
relative_path
66+
|> Path.split()
67+
|> Enum.drop(1)
68+
69+
directory = Path.dirname(relative_path)
70+
slug = Path.basename(relative_path)
71+
72+
case load_content(directory, slug) do
73+
{:ok, content} ->
74+
content_with_path = Map.put(content, :path, path_segments)
75+
Map.update!(acc, :files, &[content_with_path | &1])
76+
77+
_ ->
78+
acc
79+
end
80+
81+
true ->
82+
acc
83+
end
84+
end)
85+
|> Map.update!(:files, &Enum.sort_by(&1, fn file -> file.date end, :desc))
86+
87+
{:error, _} ->
88+
%{files: [], dirs: %{}}
89+
end
90+
end
91+
4192
def format_date(date_string) when is_binary(date_string) do
4293
case Date.from_iso8601(date_string) do
4394
{:ok, date} -> Calendar.strftime(date, "%B %d, %Y")

lib/algora_web/constants.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ defmodule AlgoraWeb.Constants do
1515
calendar_url: "https://cal.com/ioannisflo",
1616
github_repo_url: "https://github.com/algora-io/console",
1717
github_repo_api_url: "https://api.github.com/repos/algora-io/console",
18-
docs_url: "https://docs.algora.io",
19-
docs_supported_countries_url: "https://docs.algora.io/bounties/payments#supported-countries-regions",
18+
docs_url: ~p"/docs",
19+
docs_supported_countries_url: ~p"/docs/payments",
2020
demo_url: "https://www.youtube.com/watch?v=Ts5GhlEROrs",
2121
sdk_url: ~p"/sdk",
2222
privacy_url: ~p"/legal/privacy",
2323
terms_url: ~p"/legal/terms",
2424
blog_url: "https://blog.algora.io",
25-
contact_url: "https://docs.algora.io/contact",
25+
contact_url: ~p"/docs/contact",
2626
algora_tv_url: "https://algora.tv",
2727
tel_formatted: "+1 (650) 420-2207",
2828
tel: "+16504202207"

lib/algora_web/endpoint.ex

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ defmodule AlgoraWeb.Endpoint do
44
# The session will be stored in the cookie and signed,
55
# this means its contents can be read but not tampered with.
66
# Set :encryption_salt if you would also like to encrypt it.
7+
alias AlgoraWeb.Plugs.CanonicalHostPlug
8+
79
@session_options [
810
store: :cookie,
911
key: "_algora_key",
@@ -60,13 +62,18 @@ defmodule AlgoraWeb.Endpoint do
6062
# Legacy tRPC endpoint
6163
defp canonical_host(%{path_info: ["api", "trpc" | _]} = conn, _opts), do: conn
6264

63-
defp canonical_host(conn, _opts) do
65+
defp canonical_host(%{host: "docs.algora.io"} = conn, _opts),
66+
do: redirect_to_canonical_host(conn, Path.join(["/docs", conn.request_path]))
67+
68+
defp canonical_host(conn, _opts), do: redirect_to_canonical_host(conn, conn.request_path)
69+
70+
defp redirect_to_canonical_host(conn, path) do
6471
:algora
6572
|> Application.get_env(:canonical_host)
6673
|> case do
6774
host when is_binary(host) ->
68-
opts = PlugCanonicalHost.init(canonical_host: host)
69-
PlugCanonicalHost.call(conn, opts)
75+
opts = CanonicalHostPlug.init(canonical_host: host, path: path)
76+
CanonicalHostPlug.call(conn, opts)
7077

7178
_ ->
7279
conn

0 commit comments

Comments
 (0)