@@ -9,58 +9,46 @@ component extends="app.Controllers.Controller" {
99 }
1010
1111 // Function to list all blogs
12- public void function index () {
13- // Detect HTMX request
14- // var isHtmx = structKeyExists(getHttpRequestData().headers, "HX-Request");
12+ public void function index () {}
1513
16- // Detect filters via category/tag or year/month
17- var isFiltered = (
18- structKeyExists (params , " year" ) && structKeyExists (params , " month" )
19- );
2014
21- // If filtered or HTMX, just call the blogs partial and return
22- if (isFiltered ) {
23- blogs ();
24- return ;
25- }
26-
27- // Otherwise, allow default layout-wrapped view to render (index.cfm)
28- }
15+ public void function blogs () {
16+ try {
17+ var blogModel = model (" Blog" ); // Load model
2918
19+ // --- Filter by category or tag ---
20+ if (structKeyExists (params , " filterType" ) && structKeyExists (params , " filterValue" )) {
21+ // Normalize value (e.g., convert "design-ui" to "design.ui")
22+ params .filterValue = replace (params .filterValue , " -" , " ." , " all" );
3023
31- public void function blogs () {
32- var blogModel = model ( " Blog " ); // Load model
33-
34- // --- Filter by category or tag ---
35- if ( structKeyExists ( params , " filterType " ) && structKeyExists ( params , " filterValue " )) {
36- // Normalize value (e.g. convert "design-ui" to "design.ui")
37- params . filterValue = replace (params .filterValue , " - " , " . " , " all " );
38-
39- switch ( lcase ( params . filterType )) {
40- case " category " :
41- blogs = getBlogsByCategory ( params . filterValue ) ;
42- break ;
43- case " tag " :
44- blogs = getAllByTag ( params . filterValue );
45- break ;
46- default :
47- blogs = getAllBlogs (); // fallback in case of unknown filterType
48- }
24+ // If filterType is a year and filterValue is a month (numeric), handle as archive
25+ if ( isNumeric ( params . filterType ) && isNumeric ( params . filterValue )) {
26+ blogs = getBlogsByMonthYear ( params . filterType , params . filterValue );
27+ } else {
28+ switch ( lcase ( params . filterType )) {
29+ case " category " :
30+ blogs = getBlogsByCategory (params .filterValue );
31+ break ;
32+ case " tag " :
33+ blogs = getAllByTag ( params . filterValue );
34+ break ;
35+ default :
36+ blogs = getAllBlogs (); // fallback in case of unknown filterType
37+ }
38+ }
39+ } else {
40+ blogs = getAllBlogs (); // default listing
41+ }
4942
50- // --- Filter by archive year/month ---
51- } else if (structKeyExists (params , " year" ) && structKeyExists (params , " month" )) {
52- if (isNumeric (params .year ) && isNumeric (params .month )) {
53- blogs = getBlogsByMonthYear (params .year , params .month );
54- } else {
55- blogs = getAllBlogs (); // fallback in case of invalid input
56- }
43+ renderPartial (partial = " partials/blogList" );
44+ } catch (any e ) {
45+ // Log or handle error gracefully
46+ // logError("Error in blogs(): #e.message# | #e.detail#");
5747
58- // --- Default blog listing ---
59- } else {
60- blogs = getAllBlogs ( );
48+ // Optionally show fallback
49+ blogs = getAllBlogs (); // fallback content
50+ renderPartial ( partial = " partials/blogList " );
6151 }
62-
63- renderPartial (partial = " partials/blogList" );
6452 }
6553
6654 // Function to load categories for the blog list
0 commit comments