1313 .media-card {
1414 min-width : 0 !important ;
1515 background : # fff !important ;
16- border : 1px solid # e1e4e8 !important ; /* Professional gray border */
16+ border : 1px solid # e1e4e8 !important ;
1717 border-radius : 8px !important ;
1818 padding : 1rem !important ;
19- box-shadow : 0 2px 4px rgba (0 , 0 , 0 , 0.1 ) !important ; /* Subtle shadow */
20- margin : 0 !important ; /* Remove margin, let grid handle spacing */
19+ box-shadow : 0 2px 4px rgba (0 , 0 , 0 , 0.1 ) !important ;
20+ margin : 0 !important ;
2121 display : block !important ;
2222 width : 100% !important ;
2323 box-sizing : border-box !important ;
24- transition : box-shadow 0.2s ease !important ; /* Smooth hover effect */
24+ transition : box-shadow 0.2s ease !important ;
2525 }
2626
2727 /* Hover effect for cards */
3535 .media-grid {
3636 display : grid !important ;
3737 grid-template-columns : repeat (auto-fit, minmax (300px , 1fr )) !important ;
38- grid-auto-rows : 10px !important ; /* Smaller row height for tighter packing */
39- gap : 12px !important ; /* Slightly smaller gap */
38+ grid-auto-rows : 10px !important ;
39+ gap : 12px !important ;
4040 align-items : start !important ;
4141 width : 100% !important ;
4242 max-width : none !important ;
8080 border-radius : 4px !important ;
8181 margin-bottom : 0.5rem !important ;
8282 }
83+
84+ /* Production debugging - remove after fixing */
85+ .debug-info {
86+ position : fixed;
87+ top : 10px ;
88+ right : 10px ;
89+ background : rgba (0 , 0 , 0 , 0.8 );
90+ color : white;
91+ padding : 10px ;
92+ font-size : 12px ;
93+ z-index : 9999 ;
94+ max-width : 300px ;
95+ }
8396</ style >
8497
8598< h1 > Media</ h1 >
8699
100+ <!-- Debug info for production -->
101+ < div class ="debug-info " id ="debug-info ">
102+ Initializing...
103+ </ div >
104+
87105< section class ="media-grid ">
88106 {% assign media_items = site.media | sort: "date" | reverse %}
89107 {% for item in media_items %}
@@ -120,39 +138,72 @@ <h3 class="archive__item-title">
120138
121139< script async src ="https://www.instagram.com/embed.js "> </ script >
122140< script >
141+ let masonryAttempts = 0 ;
142+ let lastHeights = [ ] ;
143+
144+ function updateDebug ( message ) {
145+ const debug = document . getElementById ( 'debug-info' ) ;
146+ if ( debug ) {
147+ debug . innerHTML = `Attempt ${ masonryAttempts } : ${ message } <br>Time: ${ new Date ( ) . toLocaleTimeString ( ) } ` ;
148+ }
149+ }
150+
123151function masonryLayout ( ) {
124152 const grid = document . querySelector ( '.media-grid' ) ;
125- if ( ! grid ) return ;
153+ if ( ! grid ) {
154+ updateDebug ( 'Grid not found' ) ;
155+ return ;
156+ }
126157
127158 const items = grid . querySelectorAll ( '.media-card' ) ;
128- const rowHeight = 10 ; // Match the updated CSS grid-auto-rows
129- const gap = 12 ; // Match the updated CSS gap
159+ const rowHeight = 10 ;
160+ const gap = 12 ;
161+
162+ masonryAttempts ++ ;
130163
131- // First, reset all items to auto height
164+ // Reset all items
132165 items . forEach ( item => {
133166 item . style . gridRowEnd = 'auto' ;
134167 } ) ;
135168
136- // Force browser to recalculate layout
169+ // Force reflow
137170 grid . offsetHeight ;
138171
139- // Now calculate proper row spans for each item
140- items . forEach ( item => {
141- const rect = item . getBoundingClientRect ( ) ;
142- const itemHeight = rect . height ;
172+ // Wait a bit for content to settle, then calculate
173+ setTimeout ( ( ) => {
174+ const currentHeights = [ ] ;
143175
144- // Calculate how many grid rows this item needs
145- const rowSpan = Math . ceil ( ( itemHeight + gap ) / ( rowHeight + gap ) ) ;
176+ items . forEach ( ( item , index ) => {
177+ const rect = item . getBoundingClientRect ( ) ;
178+ const itemHeight = rect . height ;
179+ currentHeights . push ( itemHeight ) ;
180+
181+ const rowSpan = Math . ceil ( ( itemHeight + gap ) / ( rowHeight + gap ) ) ;
182+ item . style . gridRowEnd = `span ${ Math . max ( 1 , rowSpan ) } ` ;
183+ } ) ;
146184
147- // Apply the calculated row span
148- item . style . gridRowEnd = `span ${ Math . max ( 1 , rowSpan ) } ` ;
149- } ) ;
185+ // Check if heights are still changing (content still loading)
186+ const heightsChanged = JSON . stringify ( currentHeights ) !== JSON . stringify ( lastHeights ) ;
187+ lastHeights = currentHeights . slice ( ) ;
188+
189+ updateDebug ( `Heights changed: ${ heightsChanged } , Max height: ${ Math . max ( ...currentHeights ) } px` ) ;
190+
191+ // If heights are still changing and we haven't tried too many times, try again
192+ if ( heightsChanged && masonryAttempts < 20 ) {
193+ setTimeout ( masonryLayout , 1000 ) ;
194+ }
195+ } , 100 ) ;
150196}
151197
152- // Enhanced initialization with better timing
198+ // More aggressive initialization for production
153199function initMasonry ( ) {
154- // Multiple attempts with different delays to handle Instagram embeds
155- const delays = [ 50 , 200 , 500 , 1000 , 2000 , 3000 ] ;
200+ updateDebug ( 'Starting masonry initialization' ) ;
201+
202+ // Run immediately
203+ masonryLayout ( ) ;
204+
205+ // Then run at multiple intervals to catch late-loading content
206+ const delays = [ 100 , 300 , 500 , 1000 , 2000 , 3000 , 5000 , 8000 , 12000 ] ;
156207
157208 delays . forEach ( delay => {
158209 setTimeout ( ( ) => {
@@ -161,29 +212,44 @@ <h3 class="archive__item-title">
161212 } ) ;
162213}
163214
164- // Wait for Instagram embeds to load
165- window . addEventListener ( 'load' , function ( ) {
166- if ( window . instgrm && instgrm . Embeds ) {
167- instgrm . Embeds . process ( ) ;
168- }
169-
170- // Run masonry after a short delay to let embeds render
171- setTimeout ( initMasonry , 100 ) ;
215+ // Multiple event listeners to catch different loading states
216+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
217+ updateDebug ( 'DOM loaded' ) ;
218+ initMasonry ( ) ;
172219} ) ;
173220
221+ window . addEventListener ( 'load' , ( ) => {
222+ updateDebug ( 'Window loaded' ) ;
223+ setTimeout ( initMasonry , 200 ) ;
224+ } ) ;
225+
226+ // Instagram embed handling
227+ function handleInstagramEmbeds ( ) {
228+ if ( window . instgrm && window . instgrm . Embeds ) {
229+ updateDebug ( 'Processing Instagram embeds' ) ;
230+ window . instgrm . Embeds . process ( ) ;
231+ setTimeout ( masonryLayout , 1500 ) ; // Give embeds time to render
232+ }
233+ }
234+
235+ // Try to process Instagram embeds multiple times
236+ setTimeout ( handleInstagramEmbeds , 1000 ) ;
237+ setTimeout ( handleInstagramEmbeds , 3000 ) ;
238+ setTimeout ( handleInstagramEmbeds , 6000 ) ;
239+
174240// Handle window resize
175241window . addEventListener ( 'resize' , function ( ) {
176242 clearTimeout ( window . resizeTimer ) ;
177- window . resizeTimer = setTimeout ( masonryLayout , 300 ) ;
243+ window . resizeTimer = setTimeout ( ( ) => {
244+ updateDebug ( 'Window resized' ) ;
245+ masonryLayout ( ) ;
246+ } , 300 ) ;
178247} ) ;
179248
180- // Initial load
181- document . addEventListener ( 'DOMContentLoaded' , initMasonry ) ;
182-
183- // Also try to run masonry when Instagram embeds finish loading
184- if ( window . instgrm ) {
185- window . instgrm . Embeds . process ( ) . then ( ( ) => {
186- setTimeout ( masonryLayout , 500 ) ;
187- } ) ;
188- }
249+ // Keep checking for new content periodically
250+ setInterval ( ( ) => {
251+ if ( masonryAttempts < 50 ) { // Don't run forever
252+ masonryLayout ( ) ;
253+ }
254+ } , 5000 ) ;
189255</ script >
0 commit comments