Margin is an open annotation layer for the internet. Powered by the AT Protocol. margin.at
extension web atproto comments
fork

Configure Feed

Select the types of activity you want to include in your feed.

better handling for annotations/highlights/quotes that are really long in OG images

+61 -31
+61 -31
backend/internal/api/og.go
··· 835 835 contentWidth := width - (padding * 2) 836 836 837 837 if text != "" { 838 - if len(text) > 300 { 839 - text = text[:297] + "..." 838 + textLen := len(text) 839 + textSize := 32 840 + textLineHeight := 42 841 + maxTextLines := 6 842 + 843 + if textLen > 200 { 844 + textSize = 28 845 + textLineHeight = 36 846 + maxTextLines = 7 840 847 } 841 - lines := wrapTextToWidth(text, contentWidth, 32) 842 - for i, line := range lines { 843 - if i >= 6 { 844 - break 848 + 849 + lines := wrapTextToWidth(text, contentWidth, textSize) 850 + numLines := min(len(lines), maxTextLines) 851 + 852 + for i := 0; i < numLines; i++ { 853 + line := lines[i] 854 + if i == numLines-1 && len(lines) > numLines { 855 + line += "..." 845 856 } 846 - drawText(img, line, padding, yPos+(i*42), textPrimary, 32, false) 857 + drawText(img, line, padding, yPos+(i*textLineHeight), textPrimary, float64(textSize), false) 847 858 } 848 - yPos += (len(lines) * 42) + 40 859 + yPos += (numLines * textLineHeight) + 40 849 860 } 850 861 851 862 if quote != "" { 852 - if len(quote) > 100 { 853 - quote = quote[:97] + "..." 863 + quoteLen := len(quote) 864 + quoteSize := 24 865 + quoteLineHeight := 32 866 + maxQuoteLines := 2 867 + 868 + if quoteLen > 150 { 869 + quoteSize = 20 870 + quoteLineHeight = 28 871 + maxQuoteLines = 3 854 872 } 855 873 856 - lines := wrapTextToWidth(quote, contentWidth-30, 24) 857 - numLines := min(len(lines), 2) 858 - barHeight := numLines*32 + 10 874 + lines := wrapTextToWidth(quote, contentWidth-30, quoteSize) 875 + numLines := min(len(lines), maxQuoteLines) 876 + barHeight := numLines*quoteLineHeight + 10 859 877 860 878 draw.Draw(img, image.Rect(padding, yPos, padding+6, yPos+barHeight), &image.Uniform{accent}, image.Point{}, draw.Src) 861 879 862 - for i, line := range lines { 863 - if i >= 2 { 864 - break 880 + for i := 0; i < numLines; i++ { 881 + line := lines[i] 882 + isLast := i == numLines-1 883 + if isLast && len(lines) > numLines { 884 + line += "..." 865 885 } 866 - drawText(img, "\""+line+"\"", padding+24, yPos+28+(i*32), textTertiary, 24, true) 886 + drawText(img, "\""+line+"\"", padding+24, yPos+28+(i*quoteLineHeight), textTertiary, float64(quoteSize), true) 867 887 } 868 - yPos += 30 + (numLines * 32) + 30 888 + yPos += 30 + (numLines * quoteLineHeight) + 30 869 889 } 870 890 871 891 drawText(img, source, padding, 580, textTertiary, 20, false) ··· 1156 1176 drawText(img, author, avatarX+avatarSize+24, avatarY+42, textSecondary, 28, false) 1157 1177 1158 1178 contentWidth := width - (padding * 2) 1159 - yPos := 240 1160 - 1179 + yPos := 220 1161 1180 if quote != "" { 1162 - if len(quote) > 200 { 1163 - quote = quote[:197] + "..." 1164 - } 1181 + quoteLen := len(quote) 1182 + fontSize := 42.0 1183 + lineHeight := 56 1184 + maxLines := 4 1165 1185 1166 - barHeight := 0 1186 + if quoteLen > 200 { 1187 + fontSize = 32.0 1188 + lineHeight = 44 1189 + maxLines = 6 1190 + } else if quoteLen > 100 { 1191 + fontSize = 36.0 1192 + lineHeight = 48 1193 + maxLines = 5 1194 + } 1167 1195 1168 - lines := wrapTextToWidth(quote, contentWidth-40, 42) 1169 - barHeight = len(lines) * 56 1196 + lines := wrapTextToWidth(quote, contentWidth-40, int(fontSize)) 1197 + numLines := min(len(lines), maxLines) 1198 + barHeight := numLines * lineHeight 1170 1199 1171 1200 draw.Draw(img, image.Rect(padding, yPos, padding+8, yPos+barHeight), &image.Uniform{accent}, image.Point{}, draw.Src) 1172 1201 1173 - for i, line := range lines { 1174 - if i >= 5 { 1175 - break 1202 + for i := 0; i < numLines; i++ { 1203 + line := lines[i] 1204 + if i == numLines-1 && len(lines) > numLines { 1205 + line += "..." 1176 1206 } 1177 - drawText(img, line, padding+40, yPos+42+(i*56), textPrimary, 42, false) 1207 + drawText(img, line, padding+40, yPos+42+(i*lineHeight), textPrimary, fontSize, false) 1178 1208 } 1179 - yPos += barHeight + 60 1209 + yPos += barHeight + 40 1180 1210 } 1181 1211 1182 1212 draw.Draw(img, image.Rect(padding, yPos, width-padding, yPos+1), &image.Uniform{border}, image.Point{}, draw.Src)