Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Jan 15, 2025
1 parent 5dfff8b commit c792485
Show file tree
Hide file tree
Showing 12 changed files with 399 additions and 318 deletions.
8 changes: 8 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,14 @@ window.cantDecide = function() {
el.classList.add("hidden")
});

[...document.querySelectorAll(".active-quickstart")].forEach((el) => {
if(!el.classList.contains("hidden")) {
el.click();
}
});

document.getElementById("quickstart-live_view-inactive").click()

document.getElementById("show-options").classList.remove("hidden");
document.getElementById("dont-worry").classList.remove("hidden");
}
Expand Down
2 changes: 1 addition & 1 deletion assets/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const fs = require("fs")
const path = require("path")

module.exports = {
darkMode: "selector",
darkMode: "class",
content: [
"./js/**/*.js",
"../lib/*_web/**/*.*ex",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,176 +7,5 @@ defmodule AshHq.Docs.Extensions.RenderMarkdown.PostProcessors.Highlighter do

def highlight(ast, libraries, current_library, _current_module) do

Check warning on line 8 in lib/ash_hq/docs/extensions/render_markdown/post_processors/highlighter.ex

View workflow job for this annotation

GitHub Actions / OTP 26.0.2 / Elixir 1.15.4 / Ash

variable "current_library" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 8 in lib/ash_hq/docs/extensions/render_markdown/post_processors/highlighter.ex

View workflow job for this annotation

GitHub Actions / OTP 26.0.2 / Elixir 1.15.4 / Ash

variable "libraries" is unused (if the variable is not meant to be used, prefix it with an underscore)
ast
|> Floki.traverse_and_update(fn
{"a", attrs, contents} ->
{"a", rewrite_href_attr(attrs, current_library, libraries), contents}

{"pre", _, [{:keep, contents}]} ->
{:keep, ~s(<pre class="code-pre">#{contents}</pre>)}

{"pre", _, [{"code", attrs, [body]}]} when is_binary(body) ->
lexer =
find_value_class(attrs, fn class ->
case Makeup.Registry.fetch_lexer_by_name(class) do
{:ok, {lexer, opts}} -> {class, lexer, opts}
:error -> nil
end
end)

code =
case lexer do
{lang, lexer, opts} ->
render_code(lang, lexer, opts, body)

nil ->
~s(<code class="text-black dark:text-white">#{body}</code>)
end

{:keep, ~s(<pre class="code-pre">#{code}</pre>)}

{"code", attrs, [body]} when is_binary(body) ->
lexer =
find_value_class(attrs, fn class ->
case Makeup.Registry.fetch_lexer_by_name(class) do
{:ok, {lexer, opts}} -> {class, lexer, opts}
:error -> nil
end
end)

code =
case lexer do
{lang, lexer, opts} ->
render_code(lang, lexer, opts, body)

nil ->
~s(<code class="text-black dark:text-white">#{body}</code>)
end

{:keep, code}

other ->
other
end)
end

defp rewrite_href_attr(attrs, current_library, libraries) do
Enum.map(attrs, fn
{"href", value} ->
{"href", rewrite_href(value, current_library, libraries)}

other ->
other
end)
end

@doc false
def rewrite_href(value, current_library, libraries) do
uri = URI.parse(value)

case {uri, Path.split(String.trim_leading(uri.path || "", "/"))} do
{%{host: "hexdocs.pm"}, _} ->
value

{%{host: nil}, ["documentation", _type, guide]} ->
github_guide_link(value, libraries, nil, current_library, guide)

{%{host: nil}, ["documentation", _type, _subtype, guide]} ->
github_guide_link(value, libraries, nil, current_library, guide)

{%{host: nil}, [guide]} ->
github_guide_link(value, libraries, nil, current_library, guide)

_ ->
value
end
end

defp github_guide_link(value, _libraries, _owner, nil, _guide) do
value
end

defp github_guide_link(value, libraries, owner, library, guide) do
guide = String.trim_trailing(guide, ".md")

if owner do
if Enum.any?(libraries, &(&1.name == library && &1.repo_org == owner)) do
url(~p"/docs/guides/#{library}/latest/#{guide}")
else
value
end
else
if Enum.any?(libraries, &(&1.name == library)) do
url(~p"/docs/guides/#{library}/latest/#{guide}")
else
value
end
end
end

defp find_value_class(attrs, func) do
Enum.find_value(attrs, fn
{"class", classes} ->
classes
|> String.split(" ")
|> Enum.find_value(func)

_ ->
nil
end)
end

@doc false
def library_for(module, libraries) do
libraries
|> Enum.map(fn library ->
{library,
Enum.find(library.module_prefixes, fn prefix ->
prefix == module || String.starts_with?(module, prefix <> ".")
end)}
end)
|> Enum.filter(fn
{_library, nil} ->
false

_ ->
true
end)
|> Enum.sort_by(fn {_library, match} ->
-String.length(match)
end)
|> Enum.at(0)
|> case do
{library, _match} ->
library

_ ->
nil
end
end

defp render_code(lang, lexer, lexer_opts, code) do
highlighted =
code
|> unescape_html()
|> IO.iodata_to_binary()
|> Makeup.highlight_inner_html(
lexer: lexer,
lexer_options: lexer_opts,
formatter_options: [highlight_tag: "span"]
)

~s(<code class="not-prose makeup #{lang} highlight">#{highlighted}</code>)
rescue
_ ->
~s(<code class="text-black dark:text-white">#{code}</code>)
end

entities = [{"&amp;", ?&}, {"&lt;", ?<}, {"&gt;", ?>}, {"&quot;", ?"}, {"&#39;", ?'}]

for {encoded, decoded} <- entities do
defp unescape_html(unquote(encoded) <> rest), do: [unquote(decoded) | unescape_html(rest)]
end

defp unescape_html(<<c, rest::binary>>), do: [c | unescape_html(rest)]
defp unescape_html(<<>>), do: []
end
14 changes: 14 additions & 0 deletions lib/ash_hq_web/controllers/home_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ defmodule AshHqWeb.HomeController do

@url_base if Mix.env() == :dev, do: "localhost:4000/new/", else: "https://new.ash-hq.org/"

def community(conn, _) do
contributors = AshHq.Github.Contributor.in_order!()

conn
|> assign(:contributor_count, Enum.count(contributors))
|> assign(:contributors, contributors)
|> render("community.html")
end

def media(conn, _) do
conn
|> render("media.html")
end

def home(conn, _) do
app_name = app_name()

Expand Down
8 changes: 0 additions & 8 deletions lib/ash_hq_web/pages/community.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ defmodule AshHqWeb.Pages.Community do
<div class="container sm:mx-auto">
<div class="flex flex-col w-full sm:flex-row sm:pt-12 sm:mx-32 min-h-screen">
<div class="sm:w-9/12">
<head>
<meta property="og:title" content="Ash Framework Blog" />
<meta
property="og:description"
content="A declarative foundation for ambitious Elixir applications. Model your domain, derive the rest."
/>
</head>
<div class="px-4 md:px-12 max-w-5xl mx-auto mt-8 flex justify-center">
<img class="h-32 md:h-64" src="/images/ash-logo-cropped.svg" />
</div>
Expand Down
27 changes: 15 additions & 12 deletions lib/ash_hq_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,29 @@ defmodule AshHqWeb.Router do
get("/:name", AshHqWeb.NewController, :new)
end

scope "/new" do
get("/:name", AshHqWeb.NewController, :new)
if Mix.env() == :dev do
scope "/new" do
get("/:name", AshHqWeb.NewController, :new)
end
end

scope "/", AshHqWeb do
pipe_through(:browser)
get "/", HomeController, :home
get "/community", HomeController, :community
get "/media", HomeController, :media

live("/media", AppViewLive, :media)
live("/blog", AppViewLive, :blog)
live("/blog/:slug", AppViewLive, :blog)
live("/community", AppViewLive, :community)
live("/docs/", AppViewLive, :docs_dsl)
live("/docs/guides/:library/:version/*guide", AppViewLive, :docs_dsl)
live("/docs/dsl/:dsl_target", AppViewLive, :docs_dsl)
live("/docs/dsl/:library/:version", AppViewLive, :docs_dsl)
live("/docs/dsl/:library/:version/:extension", AppViewLive, :docs_dsl)
live("/docs/module/:library/:version/:module", AppViewLive, :docs_dsl)
live("/docs/mix_task/:library/:version/:mix_task", AppViewLive, :docs_dsl)
live("/docs/:library/:version", AppViewLive, :docs_dsl)
# live("/community", AppViewLive, :community)
# live("/docs/", AppViewLive, :docs_dsl)
# live("/docs/guides/:library/:version/*guide", AppViewLive, :docs_dsl)
# live("/docs/dsl/:dsl_target", AppViewLive, :docs_dsl)
# live("/docs/dsl/:library/:version", AppViewLive, :docs_dsl)
# live("/docs/dsl/:library/:version/:extension", AppViewLive, :docs_dsl)
# live("/docs/module/:library/:version/:module", AppViewLive, :docs_dsl)
# live("/docs/mix_task/:library/:version/:mix_task", AppViewLive, :docs_dsl)
# live("/docs/:library/:version", AppViewLive, :docs_dsl)

# for showing deprecated forum content
live("/forum", AppViewLive, :forum)
Expand Down
Loading

0 comments on commit c792485

Please sign in to comment.