Skip to content

Commit

Permalink
Merge branch 'release/0.1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Nov 27, 2024
2 parents b51444d + 56daeff commit 2196095
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 7 deletions.
3 changes: 2 additions & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ if config_env() == :prod do
ip: {0, 0, 0, 0, 0, 0, 0, 0},
port: port
],
secret_key_base: secret_key_base
secret_key_base: secret_key_base,
check_origin: Enum.uniq(["https://#{host}", "https://preview.opsmaru.com"])

config :opsmaru, Opsmaru.Guardian,
issuer: "instellar",
Expand Down
2 changes: 1 addition & 1 deletion lib/opsmaru/content.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule Opsmaru.Content do
to: Post.Manager,
as: :feed

defdelegate show_post(slug),
defdelegate show_post(slug, options \\ []),
to: Post.Manager,
as: :show

Expand Down
8 changes: 5 additions & 3 deletions lib/opsmaru/content/post/manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ defmodule Opsmaru.Content.Post.Manager do
|> Enum.map(&Post.parse/1)
end

@spec show(String.t()) :: %Post{}
@spec show(String.t(), Keyword.t()) :: %Post{}
@decorate cacheable(cache: Cache, key: {:posts, slug}, opts: [ttl: @ttl])
def show(slug) do
def show(slug, options \\ []) do
perspective = Keyword.get(options, :perspective, "published")

query = ~S"""
*[_type == "post" && slug.current == $slug][0]{
...,
Expand All @@ -85,7 +87,7 @@ defmodule Opsmaru.Content.Post.Manager do

%Sanity.Response{body: %{"result" => post_params}} =
query
|> Sanity.query(%{slug: slug}, perspective: "published")
|> Sanity.query(%{slug: slug}, perspective: perspective)
|> Sanity.request!(sanity_request_opts())

post = Post.parse(post_params)
Expand Down
2 changes: 1 addition & 1 deletion lib/opsmaru_web/live/blog_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule OpsmaruWeb.BlogLive do
import OpsmaruWeb.MarkdownHelper

def mount(%{"id" => slug}, _session, socket) do
post = Content.show_post(slug)
post = Content.show_post(slug, perspective: socket.assigns.perspective)

socket =
socket
Expand Down
21 changes: 21 additions & 0 deletions lib/opsmaru_web/live/hooks/perspective_hook.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule OpsmaruWeb.PerspectiveHook do
import Phoenix.Component
import Phoenix.LiveView

def on_mount(:default, _params, _session, socket) do
case get_connect_info(socket, :uri) do
%URI{host: host} ->
socket =
if host =~ "preview" do
assign_new(socket, :perspective, fn -> "raw" end)
else
assign_new(socket, :perspective, fn -> "published" end)
end

{:cont, socket}

nil ->
{:cont, assign(socket, :perspective, fn -> "published" end)}
end
end
end
1 change: 1 addition & 0 deletions lib/opsmaru_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ defmodule OpsmaruWeb.Router do

live_session :default,
on_mount: [
{OpsmaruWeb.PerspectiveHook, :default},
{OpsmaruWeb.UserHook, :current_user},
{OpsmaruWeb.NavigationHook, :main}
] do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Opsmaru.MixProject do
def project do
[
app: :opsmaru,
version: "0.1.3",
version: "0.1.4",
elixir: "~> 1.14",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down

0 comments on commit 2196095

Please sign in to comment.