Skip to content

Commit f21a934

Browse files
committed
use slug for category
1 parent 23195f9 commit f21a934

File tree

3 files changed

+59
-42
lines changed

3 files changed

+59
-42
lines changed

src/components/design-library-list/default.json

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"Call to Action": {
2+
"call-to-action": {
33
"heading_placeholder": "Transform Your Business Today",
44
"description_placeholder": "Unlock your full potential with our cutting-edge solutions. We empower businesses of all sizes to achieve their goals through innovative technology and unparalleled support.",
55
"kicker_placeholder": "Seize the Opportunity",
@@ -8,7 +8,7 @@
88
"item-1_placeholder": "Streamline your operations and boost efficiency.",
99
"item-2_placeholder": "Gain actionable insights with advanced analytics."
1010
},
11-
"Card": {
11+
"card": {
1212
"heading_placeholder": "Unlock Your Full Potential",
1313
"long-description_placeholder": "At XYZ Company, we partner for your growth. Our solutions leverage cutting-edge technology, provide expert guidance, and ensure seamless integration for measurable results. We empower you with the tools and support to confidently navigate challenges, building your success on innovation and reliability.",
1414
"description_placeholder": "Discover how our comprehensive solutions empower your journey.",
@@ -34,7 +34,7 @@
3434
"c-subtitle-6_placeholder": "Scalable and Adaptable",
3535
"c-description-6_placeholder": "Invest in solutions built for tomorrow, with the flexibility to grow and evolve with your needs."
3636
},
37-
"Carousel": {
37+
"carousel": {
3838
"subheading_placeholder": "Learn and Grow",
3939
"heading_placeholder": "Explore Our Featured Resources",
4040
"description_placeholder": "Get inspired, sharpen your skills, and stay ahead with curated content from our team and industry experts.",
@@ -49,7 +49,7 @@
4949
"title-4_placeholder": "Marketing Trends You Can't Ignore",
5050
"text-4_placeholder": "Stay updated with actionable insights from today's digital landscape."
5151
},
52-
"Contact": {
52+
"contact": {
5353
"heading_placeholder": "Get in Touch With Us",
5454
"kicker_placeholder": "Contact Us",
5555
"description_placeholder": "Whether you have questions, need support, or want to explore opportunities—our team is just a message away.",
@@ -62,7 +62,7 @@
6262
"text-3_placeholder": "Discuss your goals with our sales team and discover how our solutions can meet your business needs.",
6363
"cta_placeholder": "Contact Us"
6464
},
65-
"FAQ": {
65+
"faq": {
6666
"heading_placeholder": "Frequently Asked Questions (FAQs)",
6767
"description_placeholder": "Find answers to the most common questions about [Your Product/Service]. If you can't find what you're looking for here, please contact us.",
6868
"kicker_placeholder": "Quick Answers to Your Top Questions",
@@ -91,7 +91,7 @@
9191
"question-8_placeholder": "How can I provide feedback?",
9292
"answer-8_placeholder": "We highly value your feedback as it helps us improve. You can provide feedback through several methods: Use the feedback form on our website, or email your suggestions or comments to [email protected]. You can also participate in surveys. We review all feedback submitted."
9393
},
94-
"Featured Product": {
94+
"featured-product": {
9595
"kicker_placeholder": "Discover Innovation",
9696
"product-name-1_placeholder": "Smart Lamp",
9797
"product-description-1_placeholder": "An intelligent lamp that adapts to your mood and environment with customizable ambiance and smart home integration.",
@@ -114,7 +114,7 @@
114114
"btn-1_placeholder": "Buy now",
115115
"btn-2_placeholder": "Add to Favorites"
116116
},
117-
"Footer": {
117+
"footer": {
118118
"heading_placeholder": "Contact us",
119119
"kicker_placeholder": "Stay connected",
120120
"company-description_placeholder": "InnovateCo creates cutting-edge solutions for modern living.",
@@ -142,7 +142,7 @@
142142
"link-11_placeholder": "Contact Us",
143143
"link-12_placeholder": "Shipping & Returns"
144144
},
145-
"Gallery": {
145+
"gallery": {
146146
"heading_placeholder": "Nature's Grand Canvas",
147147
"description_placeholder": "Explore breathtaking landscapes and the serene beauty of our planet. Each image unveils a unique story from the heart of nature.",
148148
"kicker_placeholder": "Earth's Masterpieces",
@@ -177,15 +177,15 @@
177177
"img-title-8_placeholder": "Lago di Limides Mirror",
178178
"img-description-8_placeholder": "The still, clear waters of Lago di Limides flawlessly reflect the cloudy sky and distant, mist-shrouded Dolomites, framed by pine trees along the shore."
179179
},
180-
"Header": {
180+
"header": {
181181
"company_placeholder": "InnovateCo",
182182
"link-1_placeholder": "About",
183183
"link-2_placeholder": "Products",
184184
"link-3_placeholder": "Blog",
185185
"link-4_placeholder": "Support",
186186
"btn_placeholder": "Login"
187187
},
188-
"Hero": {
188+
"hero": {
189189
"heading_placeholder": "Elevate Your Digital Future",
190190
"long-description_placeholder": "At XYZ Company, we don't just build products; we forge partnerships. Our dedicated team works tirelessly to understand your unique challenges, crafting tailored strategies for sustainable growth. From concept to execution, we ensure a seamless and transformative experience.",
191191
"description_placeholder": "Driving global business growth through innovative solutions and unparalleled expertise.",
@@ -202,7 +202,7 @@
202202
"metric-3_placeholder": "20",
203203
"metric-label-3_placeholder": "Years of Expertise"
204204
},
205-
"List": {
205+
"list": {
206206
"heading_placeholder": "Solutions for Your Growth",
207207
"long-description_placeholder": "We offer tailored solutions designed to meet your unique needs, from initial consultation to ongoing support. Our team of experts is dedicated to delivering high-quality results and ensuring your satisfaction.",
208208
"description_placeholder": "Here's a glimpse into the comprehensive services we provide to help you succeed. ",
@@ -223,21 +223,21 @@
223223
"title-6_placeholder": "Operational Efficiency",
224224
"item-6_placeholder": "Streamline your processes and boost productivity with our operational efficiency consulting."
225225
},
226-
"Logo Farm": {
226+
"logo-farm": {
227227
"heading_placeholder": "Trusted by Industry Leaders",
228228
"description_placeholder": "We're proud to collaborate with a diverse range of companies that trust us to deliver exceptional results. Our partnerships are built on mutual success and shared innovation, driving progress across various sectors.",
229229
"kicker_placeholder": "Our Valued Partners",
230230
"btn_placeholder": "Learn More"
231231
},
232-
"Maps": {
232+
"map": {
233233
"heading_placeholder": "Find us",
234234
"description_placeholder": "Our main office is conveniently located and easily accessible for all your inquiries.",
235235
"location-1_placeholder": "Main Office",
236236
"location-2_placeholder": "Downtown Location",
237237
"location-3_placeholder": "Headquarters Annex",
238238
"location-4_placeholder": "Northside Hub"
239239
},
240-
"Media and Text": {
240+
"media-and-text": {
241241
"long-subheading_placeholder": "Revolutionizing how we interact with the world.",
242242
"heading_placeholder": "Future of Connectivity",
243243
"long-description_placeholder": "Discover seamless integration and enhanced experiences designed to elevate your daily life. Our innovations transcend traditional boundaries, creating a more interconnected and intuitive world for everyone.",
@@ -257,7 +257,7 @@
257257
"title-6_placeholder": "Dedicated Support",
258258
"text-6_placeholder": "Our expert team is always ready to assist you. Enjoy comprehensive support and resources designed to ensure your success."
259259
},
260-
"Post Loop": {
260+
"post-loop": {
261261
"heading_placeholder": "Our Latest Insights",
262262
"post-btn_placeholder": "Read more",
263263
"btn_placeholder": "View all",
@@ -293,7 +293,7 @@
293293
}
294294
]
295295
},
296-
"Pricing Table": {
296+
"pricing-table": {
297297
"heading_placeholder": "Our Pricing Plans",
298298
"description_placeholder": "Choose the perfect plan to fit your needs, from individuals to large organizations. All plans include dedicated support and a commitment to your success.",
299299
"btn-1_placeholder": "Get Started",
@@ -335,15 +335,15 @@
335335
"plan-description-5_placeholder": "Tailored for large organizations with unique demands.",
336336
"plan-5-details_placeholder": "For customized solutions including specialized features, dedicated infrastructure, and personalized support, please contact us to discuss an Enterprise plan."
337337
},
338-
"Quote": {
338+
"quote": {
339339
"text-1_placeholder": "The journey of a thousand miles begins with a single step.",
340340
"name-1_placeholder": "A. B. Johnson",
341341
"position-1_placeholder": "Thought Leader",
342342
"text-2_placeholder": "Innovation distinguishes between a leader and a follower.",
343343
"name-2_placeholder": "C. D. Williams",
344344
"position-2_placeholder": "Forward Thinker"
345345
},
346-
"Service Menu": {
346+
"service-menu": {
347347
"heading_placeholder": "Our Signature Menu",
348348
"description_placeholder": "Crafted with fresh ingredients and bold flavors—perfect for any time of day.",
349349
"category-1_placeholder": "Customer Favorites",
@@ -362,7 +362,7 @@
362362
"title-6_placeholder": "Breakfast Burrito",
363363
"text-6_placeholder": "Fluffy eggs, chorizo, potatoes, and cheese wrapped in a warm tortilla."
364364
},
365-
"Stats": {
365+
"stats": {
366366
"heading_placeholder": "Trusted by Teams, Loved by Customers",
367367
"description_placeholder": "Our impact speaks for itself—from satisfied clients to successful projects delivered across industries.",
368368
"kicker_placeholder": "By the Numbers",
@@ -372,7 +372,7 @@
372372
"stat-title-3_placeholder": "Websites",
373373
"stat-title-4_placeholder": "New Users"
374374
},
375-
"Table of Contents": {
375+
"table-of-contents": {
376376
"heading_placeholder": "Table of Contents",
377377
"subtitle-1_placeholder": "Setting Up Your Account",
378378
"subtitle-2_placeholder": "Navigating the Interface",
@@ -389,7 +389,7 @@
389389
"title-5_placeholder": "Frequently Asked Questions",
390390
"title-6_placeholder": "Glossary of Terms"
391391
},
392-
"Tabs": {
392+
"tabs": {
393393
"tab-1_placeholder": "All",
394394
"tab-2_placeholder": "News",
395395
"tab-3_placeholder": "Trending",
@@ -400,7 +400,7 @@
400400
"title-2_placeholder": "Unlocking Your Potential",
401401
"text-2_placeholder": "Discover the tools and resources designed to help you achieve your goals. We believe in providing comprehensive support and personalized guidance, enabling you to navigate challenges and seize opportunities with confidence."
402402
},
403-
"Team Members": {
403+
"team-members": {
404404
"heading_placeholder": "Meet Our Team",
405405
"description_placeholder": "We're a passionate group dedicated to innovation and excellence. Get to know the individuals who drive our success.",
406406
"name-1_placeholder": "Eleanor Vance",
@@ -422,7 +422,7 @@
422422
"position-6_placeholder": "Senior Software Engineer",
423423
"text-6_placeholder": " a key architect behind our robust software solutions"
424424
},
425-
"Text": {
425+
"text": {
426426
"heading_placeholder": "Innovating for a Sustainable Future",
427427
"long-subtitle_placeholder": "Pioneering Global Solutions for a Greener Tomorrow's Challenges",
428428
"long-description-1_placeholder": "We invest in cutting-edge research to create tangible solutions for environmental challenges, integrating sustainable practices across our operations. Our holistic approach aims for long-term benefits for the planet and its inhabitants. True innovation stems from understanding ecological principles and technological advancement.",
@@ -443,7 +443,7 @@
443443
"title-6_placeholder": "Environmental Education",
444444
"text-6_placeholder": "Empowering communities with knowledge to adopt sustainable lifestyles."
445445
},
446-
"Testimonials": {
446+
"testimonial": {
447447
"heading_placeholder": "What Our Clients Say",
448448
"description_placeholder": "Here's a look at what people are saying about working with us. We're proud to have helped so many achieve their goals.",
449449
"kicker_placeholder": "Testimonials",
@@ -466,7 +466,7 @@
466466
"position-6_placeholder": "Real Estate Broker",
467467
"text-6_placeholder": "XYZ Company gave me the edge. Their innovative digital advertising brought consistent, qualified leads, directly leading to more property sales."
468468
},
469-
"Timeline": {
469+
"timeline": {
470470
"heading_placeholder": "Our Journey Through Time",
471471
"kicker_placeholder": "A Legacy of Progress",
472472
"description_placeholder": "Explore the key milestones that have shaped our story, from our humble beginnings to our latest achievements.",
@@ -485,7 +485,7 @@
485485
"text-6_placeholder": "Hosting an event to discuss the next era of innovation."
486486

487487
},
488-
"Videos": {
488+
"video": {
489489
"heading_placeholder": "Our Story",
490490
"kicker_placeholder": "See Us in Action",
491491
"description_placeholder" : "Dive deep into the heart of InnovateCo, exploring our origins, values, and the future we're building.",
@@ -499,4 +499,4 @@
499499
"title-6_placeholder": "Sustainability Efforts",
500500
"title-7_placeholder": "Future Innovations"
501501
}
502-
}
502+
}

src/components/design-library-list/use-preview-renderer.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
parseDisabledBlocks, adjustPatternSpacing,
1111
replacePlaceholders,
1212
replaceImages,
13+
getCategorySlug,
1314
} from './util'
1415

1516
/**
@@ -132,21 +133,21 @@ export const usePreviewRenderer = (
132133
}
133134

134135
if ( selectedTab === 'patterns' ) {
135-
adjustPatternSpacing( parsedBlocks[ 0 ].attributes, category, spacingSize, false )
136+
adjustPatternSpacing( parsedBlocks[ 0 ].attributes, categoriesRef.current[ 0 ], spacingSize, false )
136137
}
137138

138139
let preview = serialize( parsedBlocks )
139140

140141
// The block `wp/site-title` is a dynamic block, so we need to manually replace it for the preview
141-
if ( categoriesRef.current.includes( 'Header' ) ) {
142+
if ( categoriesRef.current.includes( 'header' ) ) {
142143
preview = preview.replace( /<!--\s*wp:site-title(?:\s+[^\/]*?)?\/-->/g, escapeHtml( siteTitle ) )
143144
}
144-
if ( categoriesRef.current.includes( 'Tabs' ) ) {
145+
if ( categoriesRef.current.includes( 'tabs' ) ) {
145146
// Add a class for the first tab to be the active tab in the preview
146147
preview = preview.replace( '"stk-block-tabs__tab"', '"stk-block-tabs__tab stk-block-tabs__tab--active"' )
147148
}
148-
if ( categoriesRef.current.includes( 'Post Loop' ) ) {
149-
const defaultValues = DEFAULT_CONTENT[ 'Post Loop' ]
149+
if ( categoriesRef.current.includes( 'post-loop' ) ) {
150+
const defaultValues = DEFAULT_CONTENT[ 'post-loop' ]
150151
preview = addPlaceholderForPostsBlock( preview, defaultValues.posts_placeholder, defaultValues )
151152
}
152153

@@ -183,12 +184,14 @@ export const usePreviewRenderer = (
183184
const initialize = async () => {
184185
const _content = template
185186
if ( selectedTab === 'patterns' ) {
187+
const categorySlug = getCategorySlug( designId )
188+
186189
// For preview: always replace placeholders (ignore dev mode)
187-
const _contentForPreview = replacePlaceholders( _content, category, false )
190+
const _contentForPreview = replacePlaceholders( _content, categorySlug, false )
188191
// For insertion: only create separate content if dev mode is enabled
189-
const _contentForInsertion = isDesignLibraryDevMode ? replacePlaceholders( _content, category, true ) : _contentForPreview
192+
const _contentForInsertion = isDesignLibraryDevMode ? replacePlaceholders( _content, categorySlug, true ) : _contentForPreview
190193

191-
categoriesRef.current.push( category )
194+
categoriesRef.current.push( categorySlug )
192195

193196
if ( _contentForPreview.includes( 'stk-design-library__bg-target="true"' ) ) {
194197
hasBackgroundTargetRef.current = true
@@ -199,13 +202,15 @@ export const usePreviewRenderer = (
199202
} else {
200203
for ( let i = 0; i < _content.length; i++ ) {
201204
const section = _content[ i ]
202-
const design = await fetchDesign( section.id )
205+
const design = await fetchDesign( section.designId || section.id )
206+
const categorySlug = getCategorySlug( section.designId || section.id )
207+
203208
// For preview: always replace placeholders (ignore dev mode)
204-
const designContentForPreview = replacePlaceholders( design.template || design.content, design.category, false )
209+
const designContentForPreview = replacePlaceholders( design.template || design.content, categorySlug, false )
205210
// For insertion: only create separate content if dev mode is enabled
206-
const designContentForInsertion = isDesignLibraryDevMode ? replacePlaceholders( design.template || design.content, design.category, true ) : designContentForPreview
211+
const designContentForInsertion = isDesignLibraryDevMode ? replacePlaceholders( design.template || design.content, categorySlug, true ) : designContentForPreview
207212

208-
categoriesRef.current.push( design.category )
213+
categoriesRef.current.push( categorySlug )
209214

210215
let _block = cleanParse( designContentForPreview )[ 0 ]
211216
let _blockForInsertion = isDesignLibraryDevMode ? cleanParse( designContentForInsertion )[ 0 ] : null
@@ -217,9 +222,9 @@ export const usePreviewRenderer = (
217222
}
218223
}
219224

220-
adjustPatternSpacing( _block.attributes, design.category, spacingSize, false )
225+
adjustPatternSpacing( _block.attributes, categorySlug, spacingSize, false )
221226
if ( _blockForInsertion ) {
222-
adjustPatternSpacing( _blockForInsertion.attributes, design.category, spacingSize, true )
227+
adjustPatternSpacing( _blockForInsertion.attributes, categorySlug, spacingSize, true )
223228
}
224229
_parsedBlocks.push( _block )
225230
if ( _blockForInsertion ) {

src/components/design-library-list/util.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export const adjustPatternSpacing = ( attributes, category, spacingSize, isDesig
157157
// to the generatedCss attribute for preview purposes. This generatedCss will be regenerated
158158
// by the BlockCssGenerator once the pattern is actually added to the editor.
159159
let additionalCss = ''
160-
if ( ! isDesignLibraryDevMode && category !== 'Header' ) {
160+
if ( ! isDesignLibraryDevMode && category !== 'header' ) {
161161
if ( attributes.hasBackground ) {
162162
additionalCss += 'margin-bottom: 0px !important;'
163163
} else {
@@ -302,6 +302,18 @@ export const replaceImages = content => {
302302
)
303303
}
304304

305+
export const getCategorySlug = id => {
306+
if ( typeof id !== 'string' ) {
307+
return ''
308+
}
309+
if ( id.startsWith( 'section-' ) ) {
310+
// Remove 'section-' prefix and trailing dash + number
311+
return id.replace( /^section-/, '' ).replace( /-\d+$/, '' )
312+
}
313+
// Remove trailing dash + number for other ids
314+
return id.replace( /-\d+$/, '' )
315+
}
316+
305317
// Additional styles for blocks to render properly in the preview
306318
export const getAdditionalStylesForPreview = () => {
307319
let styles = ''

0 commit comments

Comments
 (0)