Skip to content

Commit 2238f82

Browse files
committed
Update layout and improve long text handling
Improves layout and adds helper functions to clip the main text and dynamically adjust its size based on length, improving layout and appearance for varying text inputs.
1 parent a2c5fd6 commit 2238f82

File tree

2 files changed

+61
-21
lines changed

2 files changed

+61
-21
lines changed

lib/og_image_web/components/shared_components.ex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,7 @@ defmodule OgImageWeb.SharedComponents do
124124

125125
def fly_logomark(assigns) do
126126
~H"""
127-
<svg fill="currentColor" height={@height} viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
128-
<path d="m15.9746 26.7849c-4.2165 0-7.95375-1.4489-10.51715-4.0832-2.39569-2.4667-3.66541-5.8555-3.56958-9.5555.22759-8.15457 6.98345-12.429403 13.53563-12.429403 2.7551 0 5.3065.658583 7.1752 1.844043 1.8087 1.14954 2.8508 2.7062 2.8508 4.27484 0 4.25092-6.2887 4.57422-10.0379 4.76582-.3115.0119-.599.0359-.8745.0479-.3833.0239-.6708.3352-.6708.7184 0 .3592.2636.6586.6229.7065 2.5514.3473 5.007.7304 6.8757 1.5686 2.1321.958 3.2821 2.4189 3.5097 4.4784.1796 1.6405-.4552 3.4486-1.701 4.8496-1.1499 1.2933-3.33 2.814-7.199 2.814zm-.5511-24.63118c-3.0185 0-6.00117 1.01781-8.18125 2.80199-2.46757 2.01169-3.82114 4.86158-3.90499 8.23829-.08385 3.305 1.03015 6.3225 3.16232 8.5138 2.28789 2.347 5.65382 3.6522 9.48692 3.6522 3.342 0 5.1628-1.2693 6.121-2.3231 1.15-1.2932 1.4494-2.778 1.3416-3.724-.3713-3.3408-4.0367-4.0952-9.1515-4.7897-1.0661-.1437-1.8567-1.0657-1.8567-2.1314 0-1.1376.8864-2.0836 2.0244-2.1554.2755-.012.5749-.0359.8864-.0479 4.2044-.21555 8.6844-.67057 8.6844-3.34085-.024-1.97576-3.0066-4.69393-8.6126-4.69393z" />
129-
<path d="m16.5611 31.2632c-2.755 0-5.3064-.6586-7.17507-1.8441-1.80875-1.1495-2.85087-2.7062-2.85087-4.2748 0-4.2509 6.28874-4.5742 10.03794-4.7658.3115-.012.5989-.0359.8745-.0479.3833-.0239.6707-.3353.6707-.7185 0-.3592-.2635-.6585-.6228-.7064-2.5515-.3473-5.007-.7305-6.8757-1.5687-2.13215-.9579-3.28209-2.4188-3.50968-4.4784-.17967-1.6405.45519-3.44858 1.70095-4.84958 1.14993-1.28125 3.31803-2.80199 7.18713-2.80199 4.2164 0 7.9537 1.44889 10.5171 4.08325 2.3957 2.46672 3.6654 5.85542 3.5695 9.55552-.2036 8.1425-6.9594 12.4174-13.5237 12.4174zm-8.01356-18.5722c.37133 3.3408 4.03676 4.0952 9.15156 4.7897 1.0661.1437 1.8567 1.0657 1.8567 2.1314 0 1.1376-.8864 2.0836-2.0244 2.1554-.2755.012-.575.036-.8864.0479-4.2045.2156-8.6844.6706-8.6844 3.3409 0 1.9638 2.9826 4.6819 8.5886 4.6819 3.0305 0 6.0132-1.0178 8.1813-2.79 2.4675-2.0117 3.8211-4.8616 3.905-8.2383.0838-3.3049-1.0302-6.3225-3.1624-8.5138-2.2639-2.3709-5.6299-3.66412-9.463-3.66412-3.33 0-5.1627 1.2573-6.12097 2.32302-1.14993 1.2932-1.4494 2.778-1.34159 3.736z" />
130-
</svg>
127+
<svg viewBox="0 0 167 151" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2"><path d="M116.78 20.613h19.23c17.104 0 30.99 13.886 30.99 30.99v67.618c0 17.104-13.886 30.99-30.99 30.99h-1.516c-8.803-1.377-12.621-4.017-15.57-6.248L94.475 123.86a3.453 3.453 0 00-4.329 0l-7.943 6.532-22.37-18.394a3.443 3.443 0 00-4.326 0l-31.078 27.339c-6.255 5.087-10.392 4.148-13.075 3.853C4.424 137.503 0 128.874 0 119.221V51.603c0-17.104 13.886-30.99 30.993-30.99H50.18l-.035.077-.647 1.886-.201.647-.871 3.862-.12.678-.382 3.868-.051 1.062-.008.372.036 1.774.088 1.039.215 1.628.275 1.464.326 1.349.423 1.46 1.098 3.092.362.927 1.912 4.04.675 1.241 2.211 3.795.846 1.369 3.086 4.544.446.602 4.015 5.226 1.297 1.608 4.585 5.36.942 1.031 3.779 4.066 1.497 1.55 2.474 2.457-.497.415-.309.279a30.309 30.309 0 00-2.384 2.49c-.359.423-.701.86-1.025 1.31-.495.687-.938 1.41-1.324 2.164-.198.391-.375.792-.531 1.202a11.098 11.098 0 00-.718 3.267l-.014.966c.035 1.362.312 2.707.819 3.972a11.06 11.06 0 002.209 3.464 11.274 11.274 0 002.329 1.896c.731.447 1.51.816 2.319 1.096 1.76.597 3.627.809 5.476.623h.01a12.347 12.347 0 004.516-1.341 11.647 11.647 0 001.724-1.116 11.067 11.067 0 003.479-4.626c.569-1.422.848-2.941.823-4.471l-.044-.799a11.305 11.305 0 00-.749-3.078c-.17-.429-.364-.848-.58-1.257-.4-.752-.856-1.473-1.362-2.158-.232-.313-.472-.62-.72-.921a29.81 29.81 0 00-2.661-2.787l-.669-.569 1.133-1.119 4.869-5.085 1.684-1.849 2.618-2.945 1.703-1.992 2.428-2.957 1.644-2.067 2.414-3.228 1.219-1.67 1.729-2.585 1.44-2.203 2.713-4.725 1.552-3.1.045-.095 1.188-2.876c.015-.037.029-.075.04-.114l1.28-3.991.134-.582.555-3.177.108-.86.033-.527.038-1.989-.01-.371-.102-1.781-.126-1.383-.63-3.989a1.521 1.521 0 00-.037-.159l-.809-2.949-.279-.82-.364-.907zm9.141 84.321c-4.007.056-7.287 3.336-7.343 7.342.059 4.006 3.337 7.284 7.343 7.341 4.005-.058 7.284-3.335 7.345-7.341-.058-4.006-3.338-7.286-7.345-7.342z" fill="url(#_Radial1)"/><path d="M72.499 147.571l-1.296 1.09a6.802 6.802 0 01-4.253 1.55H30.993a30.867 30.867 0 01-19.639-7.021c2.683.295 6.82 1.234 13.075-3.853l31.078-27.339a3.443 3.443 0 014.326 0l22.37 18.394 7.943-6.532a3.453 3.453 0 014.329 0l24.449 20.103c2.949 2.231 6.767 4.871 15.57 6.248H118.23a6.919 6.919 0 01-3.993-1.33l-.285-.22-1.207-1.003a2.377 2.377 0 00-.32-.323 21845.256 21845.256 0 00-18.689-15.497 2.035 2.035 0 00-2.606.006s.044.052-18.386 15.491c-.09.075-.172.154-.245.236zm53.422-42.637c-4.007.056-7.287 3.336-7.343 7.342.059 4.006 3.337 7.284 7.343 7.341 4.005-.058 7.284-3.335 7.345-7.341-.058-4.006-3.338-7.286-7.345-7.342zM78.453 82.687l-2.474-2.457-1.497-1.55-3.779-4.066-.942-1.031-4.585-5.36-1.297-1.609-4.015-5.225-.446-.602-3.086-4.544-.846-1.369-2.211-3.795-.675-1.241-1.912-4.04-.362-.927-1.098-3.092-.423-1.46-.326-1.349-.275-1.465-.215-1.627-.088-1.039-.036-1.774.008-.372.051-1.062.382-3.869.12-.677.871-3.862.201-.647.647-1.886.207-.488 1.03-2.262.714-1.346.994-1.64.991-1.46.706-.928.813-.98.895-.985.767-.771 1.867-1.643 1.365-1.117c.033-.028.067-.053.102-.077l1.615-1.092 1.283-.818L65.931 3.8c.037-.023.079-.041.118-.059l3.456-1.434.319-.12 3.072-.899 1.297-.291 1.754-.352L77.11.468l1.784-.222L80.11.138 82.525.01l.946-.01 1.791.037.466.026 2.596.216 3.433.484.397.083 3.393.844.996.297 1.107.383 1.348.51 1.066.452 1.566.738.987.507 1.774 1.041.661.407 2.418 1.765.694.602 1.686 1.536.083.083 1.43 1.534.492.555 1.678 2.23.342.533 1.332 2.249.401.771.751 1.678.785 1.959.279.82.809 2.949c.015.052.027.105.037.159l.63 3.988.126 1.384.102 1.781.01.371-.038 1.989-.033.527-.108.86-.555 3.177-.134.582-1.28 3.991a1.186 1.186 0 01-.04.114l-1.188 2.876-.045.095-1.552 3.1-2.713 4.725-1.44 2.203-1.729 2.585-1.219 1.67-2.414 3.228-1.644 2.067-2.428 2.957-1.703 1.992-2.618 2.945-1.684 1.849-4.869 5.085-1.133 1.119.669.569c.946.871 1.835 1.8 2.661 2.787.248.301.488.608.72.921.506.685.962 1.406 1.362 2.158.216.407.409.828.58 1.257.389.985.651 2.026.749 3.078l.044.799c.025 1.53-.255 3.05-.823 4.471a11.057 11.057 0 01-3.479 4.625c-.541.424-1.118.796-1.724 1.117a12.347 12.347 0 01-4.516 1.341h-.01a12.996 12.996 0 01-5.476-.623 11.933 11.933 0 01-2.319-1.096 11.268 11.268 0 01-2.329-1.896 11.06 11.06 0 01-2.209-3.464 11.468 11.468 0 01-.819-3.972l.014-.966c.073-1.119.315-2.221.718-3.267.157-.411.334-.812.531-1.202.386-.755.83-1.477 1.324-2.164.323-.45.667-.887 1.025-1.31a30.309 30.309 0 012.384-2.49l.309-.279.497-.415z" fill="#24175b"/><path d="M71.203 148.661l19.927-16.817a2.035 2.035 0 012.606-.006l20.216 16.823a6.906 6.906 0 004.351 1.55H66.877a6.805 6.805 0 004.326-1.55zm12.404-60.034l.195.057c.063.03.116.075.173.114l.163.144c.402.37.793.759 1.169 1.157.265.283.523.574.771.875.315.38.61.779.879 1.194.116.183.224.368.325.561.088.167.167.34.236.515.122.305.214.627.242.954l-.006.614a3.507 3.507 0 01-1.662 2.732 4.747 4.747 0 01-2.021.665l-.759.022-.641-.056a4.964 4.964 0 01-.881-.214 4.17 4.17 0 01-.834-.391l-.5-.366a3.431 3.431 0 01-1.139-1.952 5.016 5.016 0 01-.059-.387l-.018-.586c.01-.158.034-.315.069-.472.087-.341.213-.673.372-.988.205-.396.439-.776.7-1.137.433-.586.903-1.143 1.405-1.67.324-.342.655-.673 1.001-.993l.246-.221c.171-.114.173-.114.368-.171h.206zM82.348 6.956l.079-.006v68.484l-.171-.315a191.264 191.264 0 01-6.291-12.75 136.318 136.318 0 01-4.269-10.688 84.358 84.358 0 01-2.574-8.802c-.541-2.365-.956-4.765-1.126-7.19a35.028 35.028 0 01-.059-3.108c.016-.903.053-1.804.109-2.705.09-1.418.234-2.832.442-4.235.165-1.104.368-2.205.62-3.293.2-.865.431-1.723.696-2.567.382-1.22.84-2.412 1.373-3.576.195-.419.405-.836.624-1.245 1.322-2.449 3.116-4.704 5.466-6.214a11.422 11.422 0 015.081-1.79zm8.88.173l4.607 1.314a28.193 28.193 0 016.076 3.096 24.387 24.387 0 016.533 6.517 24.618 24.618 0 012.531 4.878 28.586 28.586 0 011.761 7.898c.061.708.096 1.418.11 2.127.016.659.012 1.321-.041 1.98a22.306 22.306 0 01-.828 4.352 34.281 34.281 0 01-1.194 3.426 49.43 49.43 0 01-1.895 4.094c-1.536 2.966-3.304 5.803-5.195 8.547a133.118 133.118 0 01-7.491 9.776 185.466 185.466 0 01-8.987 9.96c2.114-3.963 4.087-8 5.915-12.102a149.96 149.96 0 002.876-6.93 108.799 108.799 0 002.679-7.792 76.327 76.327 0 001.54-5.976c.368-1.727.657-3.472.836-5.228.15-1.464.205-2.937.169-4.406a62.154 62.154 0 00-.1-2.695c-.216-3.612-.765-7.212-1.818-10.676a31.255 31.255 0 00-1.453-3.849c-1.348-2.937-3.23-5.683-5.776-7.686l-.855-.625z" fill="#fff"/><defs><radialGradient id="_Radial1" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(88.67 84.848) scale(120.977)"><stop offset="0" stop-color="#ba7bf0"/><stop offset=".45" stop-color="#996bec"/><stop offset="1" stop-color="#5046e4"/></radialGradient></defs></svg>
131128
"""
132129
end
133130
end

lib/og_image_web/controllers/image_html.ex

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,45 +122,54 @@ defmodule OgImageWeb.ImageHTML do
122122
mask: radial-gradient(ellipse 120% 100% at 30% 70%, hsla(0, 0%, 0%, 0.8), hsla(0, 0%, 0%, 0.1) 70%);
123123
"></div>
124124
125-
<!-- Logo positioned bottom left -->
126-
<div class="absolute bottom-12 left-12 z-20">
127-
<.fly_logo height="64" />
128-
</div>
129-
130125
<!-- Main content area -->
131-
<div class="flex-1 flex items-center justify-between pl-20 pr-16">
126+
<div class="flex-1 flex items-center pl-16 pr-12 pb-8">
132127
<!-- Text section -->
133-
<div class="flex-1 max-w-2xl relative z-10">
134-
<div class="mb-6">
135-
<span class="relative inline-block text-3xl font-bold text-[#1a1347] tracking-tight">
136-
Docs
128+
<div class="flex-1 pr-12 relative z-10">
129+
<!-- Logo and URL -->
130+
<div class="mb-10 flex items-center gap-4">
131+
<div class="w-16 h-16">
132+
<.fly_logomark />
133+
</div>
134+
<span class="relative inline-block text-3xl font-semibold text-[#1a1347] tracking-tight">
135+
fly.io/docs
137136
<svg
138137
viewBox="0 0 1213 73"
139138
aria-hidden="true"
140139
preserveAspectRatio="none"
141-
height="8"
142-
class="absolute -bottom-0.5 left-0 w-full h-2"
140+
height="6"
141+
class="absolute -bottom-0.5 left-0 w-full h-1.5"
143142
>
144143
<path
145-
fill="url(#underline-gradient)"
144+
fill="url(#underline-gradient-top)"
146145
d="M1213.19 35.377c2.37-13.011-22.95-10.753-31.04-14.087C1086.89 5.705 911.742 2.887 815.218 2.809c-78.003.231-155.966-1.833-233.961.481-57.545.429-114.885 6.164-172.419 7.383-121.164 5.39-242.94 10.751-362.507 32.199-12.356 3.286-25.614 4.255-37.332 9.401-29.507 22.983 27.103 20.15 39.468 17.234 357.956-47.703 362.767-46.261 636.452-50.97 121.033-2.508 241.892 6.658 428.341 19.243 4.74.404 8.98-4.032 8-8.788a942.105 942.105 0 0154.69 6.378c9.44 1.843 18.92 3.583 28.29 5.729 4.01.839 8.02-1.718 8.95-5.712v-.01z"
147146
/>
148147
<defs>
149-
<linearGradient id="underline-gradient" gradientTransform="rotate(110)">
148+
<linearGradient id="underline-gradient-top" gradientTransform="rotate(110)">
150149
<stop offset="5%" stop-color="#CA7FF8" />
151150
<stop offset="95%" stop-color="#795BE9" />
152151
</linearGradient>
153152
</defs>
154153
</svg>
155154
</span>
156155
</div>
157-
<h1 class="font-extrabold bg-gradient-to-br from-[#1a1347] via-[#2A1863] to-[#4338ca] inline-block text-transparent bg-clip-text text-[4.5rem] leading-[1.1] tracking-tight">
158-
<%= @text %>
156+
<%
157+
# Extract string from {:safe, text} tuple if needed
158+
raw_text = case @text do
159+
{:safe, text} -> text
160+
text when is_binary(text) -> text
161+
_ -> to_string(@text)
162+
end
163+
clipped_text = OgImageWeb.ImageHTML.clip_text(raw_text, 20)
164+
text_size_class = OgImageWeb.ImageHTML.get_text_size(clipped_text)
165+
%>
166+
<h1 class={"font-extrabold bg-gradient-to-br from-[#1a1347] via-[#2A1863] to-[#4338ca] inline-block text-transparent bg-clip-text leading-tight tracking-tight break-words #{text_size_class}"}>
167+
<%= clipped_text %>
159168
</h1>
160169
</div>
161170
162171
<!-- Frankie image section -->
163-
<div class="flex items-center justify-center relative">
172+
<div class="flex items-center justify-center relative flex-shrink-0">
164173
<div class="relative">
165174
<!-- Subtle glow behind frankie -->
166175
<div class="absolute inset-0 bg-purple-300/20 rounded-full blur-2xl scale-110"></div>
@@ -172,6 +181,40 @@ defmodule OgImageWeb.ImageHTML do
172181
"""
173182
end
174183

184+
# Helper function to determine text size based on length
185+
def get_text_size(text) when is_binary(text) do
186+
length = String.length(text)
187+
188+
cond do
189+
length <= 15 -> "text-[4.5rem]" # Short text: large size
190+
length <= 25 -> "text-[3.8rem]" # Medium text: medium-large size
191+
length <= 35 -> "text-[3.2rem]" # Long text: medium size
192+
length <= 50 -> "text-[2.6rem]" # Very long text: smaller size
193+
length <= 75 -> "text-[2.2rem]" # Extra long text: much smaller size
194+
true -> "text-[1.8rem]" # Super long text: smallest size
195+
end
196+
end
197+
198+
def get_text_size(_), do: "text-[4.5rem]" # Fallback for non-binary values
199+
200+
# Helper function to clip text based on word count
201+
def clip_text(text, max_words \\ 5)
202+
203+
def clip_text(text, max_words) when is_binary(text) do
204+
words = String.split(text, " ", trim: true)
205+
206+
if length(words) > max_words do
207+
words
208+
|> Enum.take(max_words)
209+
|> Enum.join(" ")
210+
|> Kernel.<>("...")
211+
else
212+
text
213+
end
214+
end
215+
216+
def clip_text(text, _), do: text # Fallback for non-binary values
217+
175218
@doc """
176219
A fallback image.
177220
"""

0 commit comments

Comments
 (0)