Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Commit e3f2365

Browse files
authored
Merge pull request #28 from paiindustries/feature/blog-seo
dynamic seo for blogs detailed pages
2 parents 4cfb924 + aaa0955 commit e3f2365

1 file changed

Lines changed: 41 additions & 9 deletions

File tree

app/views/layout.cfm

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,45 @@
55
<cfset isBlog = find("/blog", pathInfo)>
66
<cfset isApi = find("/api", pathInfo)>
77
<cfset pageTitle = "CFWheels - an open source CFML framework inspired by Ruby on Rails">
8+
<cfset ogTitle = "CFWheels - an open source CFML framework inspired by Ruby on Rails">
9+
<cfset metaDescription = "Build apps quickly with an organized, Ruby on Rails-inspired structure. Get up and running in no time!">
10+
<cfset ogDescription = "Build apps quickly with an organized, Ruby on Rails-inspired structure. Get up and running in no time!">
811

912
<cfif isBlog>
10-
<cfset blogPath = listLast(pathInfo, "/")>
11-
<cfif blogPath EQ "blog">
12-
<cfset pageTitle = "Blogs | CFWheels">
13+
<cfset blogSlug = listLast(pathInfo, "/")>
14+
15+
<!--- Fetch the blog post by slug --->
16+
<cfset post = model("Blog").findOne(where="slug = '#blogSlug#'")>
17+
18+
<cfif structKeyExists(post, "id")>
19+
<cfset pageTitle = post.title & " | CFWheels">
20+
21+
<!-- Generate meta description from content -->
22+
<cfset firstP = reFind("<p[^>]*>(.*?)</p>", post.content, 1, true)>
23+
<cfif arrayLen(firstP.pos) GT 1>
24+
<cfset metaDescription = mid(post.content, firstP.pos[2], firstP.len[2])>
25+
<cfelse>
26+
<cfset cleanContent = reReplace(post.content, "<[^>]*>", "", "all")>
27+
<cfset metaDescription = left(trim(cleanContent), 160)>
28+
</cfif>
29+
30+
<cfset ogTitle = post.title>
31+
<cfset ogDescription = metaDescription>
32+
<!--- <cfset ogImage = ''> --->
1333
<cfelse>
14-
<cfset blogSlug = listLast(pathInfo, "/")>
15-
<cfset blogTitle = replace(blogSlug, "-", " ", "all")>
16-
<cfset blogTitle = reReplace(blogTitle, "\b([a-z])", "\u\1", "all")>
17-
<cfset pageTitle = blogTitle & " | CFWheels">
34+
<!-- fallback -->
35+
<cfset pageTitle = "Blog | CFWheels">
36+
<cfset metaDescription = "Explore our latest blogs on CFWheels.">
37+
<cfset ogTitle = pageTitle>
38+
<cfset ogDescription = metaDescription>
1839
</cfif>
1940
</cfif>
2041

42+
<cfif isApi>
43+
<cfset apiPath = listLast(pathInfo, "/")>
44+
<cfset pageTitle = apiPath & " | CFWheels API ">
45+
</cfif>
46+
2147
<cfif isApi>
2248
<cfset apiPath = listLast(pathInfo, "/")>
2349
<cfset pageTitle = apiPath & " | CFWheels API ">
@@ -39,8 +65,14 @@
3965
<link rel="icon" href="/images/favicon.ico" type="image/x-icon">
4066
<link rel="shortcut icon" href="/images/favicon.ico" type="image/x-icon">
4167
<meta name="keywords" content="cfwheels,cfml,ruby,framework">
42-
<meta name="description" content="Build apps quickly with an organized, Ruby on Rails-inspired structure. Get up and running in no time!">
43-
<meta property="og:title" content="ColdFusion on Wheels">
68+
<cfoutput>
69+
<meta name="description" content="#metaDescription#">
70+
<meta property="og:title" content="#ogTitle#">
71+
<meta property="og:description" content="#ogDescription#">
72+
<cfif isDefined("ogImage")>
73+
<meta property="og:image" content="#ogImage#">
74+
</cfif>
75+
</cfoutput>
4476
<meta property="og:description" content="Build apps quickly with an organized, Ruby on Rails-inspired structure. Get up and running in no time!">
4577
<meta property="og:url" content="https://wheels.dev/">
4678
<meta property="og:site_name" content="CFWheels">

0 commit comments

Comments
 (0)