Skip to content

Commit b726407

Browse files
committed
Update meta tags for blog
1 parent d640867 commit b726407

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

app/api/blog/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function get (req) {
3232
return {
3333
json: {
3434
posts,
35-
pageTitle: 'Blog — Enhance.dev',
35+
pageTitle: 'Blog',
3636
limit,
3737
offset,
3838
total,

app/api/blog/posts/$$.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export async function get (req) {
7474
},
7575
json: {
7676
post,
77-
pageTitle: `${post.frontmatter.title.replaceAll(/"/g, "'")} — Enhance Blog`,
77+
pageTitle: `${post.frontmatter.title.replaceAll(/"/g, "'")}`,
7878
pageDescription: post.frontmatter.description
7979
? post.frontmatter.description.replaceAll(/"/g, "'")
8080
: undefined,

app/head.mjs

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,38 @@ import { getStyles } from '@enhance/arc-plugin-styles'
44
/** @type {import('@enhance/types').EnhanceHeadFn} */
55
export default function Head (state) {
66
const { req, store } = state
7-
const { doc = {} } = store
7+
const {
8+
doc = {},
9+
pageTitle = '',
10+
pageDescription = '',
11+
pageImage = '',
12+
activeRoute = ''
13+
} = store
814
const { title: docTitle } = doc
915

10-
const title = docTitle ? `${docTitle} — Enhance` : 'Enhance'
16+
const title = (docTitle || pageTitle) ? `${docTitle || pageTitle} — Enhance` : 'Enhance'
17+
const description = pageDescription ? pageDescription : 'rhe HTML first full stack web framework'
18+
const ogImage = pageImage ? pageImage : '/_public/img/enhance-open-graph.png'
1119

1220
store.path = req.path || ''
1321

22+
let extraBlogMeta = []
23+
24+
if (activeRoute === 'blog') {
25+
if (store.post?.frontmatter?.author) {
26+
extraBlogMeta.push(`<meta property="article:author" content="${store.post.frontmatter.author}" />`)
27+
}
28+
if (store.post?.frontmatter?.published) {
29+
let pubDate = new Date(store.post.frontmatter.published)
30+
pubDate.setHours(13)
31+
let dateString = pubDate.toISOString().replace('Z', '-0:00')
32+
extraBlogMeta.push(`<meta property="article:published_time" content="${dateString}" />`)
33+
}
34+
if (store.post?.frontmatter?.category) {
35+
store.post.frontmatter.category.split(',').forEach(item => extraBlogMeta.push(`<meta property="article:tag" content="${item.trim()}">`))
36+
}
37+
}
38+
1439
return /* html */ `
1540
<!DOCTYPE html>
1641
<html lang='en'>
@@ -31,16 +56,39 @@ export default function Head (state) {
3156
<link rel="stylesheet" href="${arc.static('/css/docs-highlight.css')}" />
3257
<link rel="stylesheet" href="${arc.static('/bundles/docsearch-css.css')}" />
3358
34-
<meta name="image" content="/_public/img/enhance-open-graph.png" />
35-
<meta name="og:image" content="/_public/img/enhance-open-graph.png" />
3659
<meta name="og:type" content="website" />
3760
3861
<link rel="manifest" href="${arc.static('/img/favicon/site.webmanifest')}">
62+
3963
<meta http-equiv="X-UA-Compatible" content="IE=edge">
4064
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
65+
4166
${getStyles.styleTag()}
67+
4268
<title>${title}</title>
43-
<meta name='description' content='The HTML first full stack web framework.' />
69+
<meta name='description' content="${description}"/>
70+
71+
<!-- Open Graph -->
72+
<meta name="og:title" content="${title}" />
73+
<meta name="og:description" content="${description}" />
74+
<meta name="og:image" content="${ogImage}" />
75+
<meta name="og:site_name" content="Enhance" />
76+
<meta name="og:type" content="website" />
77+
78+
<meta property="og:title" content="${title}" />
79+
<meta property="og:description" content="${description}" />
80+
<meta property="og:image" content="${ogImage}" />
81+
<meta property="og:site_name" content="Enhance" />
82+
<meta property="og:type" content="website" />
83+
84+
<!-- Twitter -->
85+
<meta name="twitter:title" content="${title}" />
86+
<meta name="twitter:description" content="${description}" />
87+
<meta name="twitter:card" content="summary_large_image" />
88+
<meta name="twitter:image:src" content="${ogImage}" />
89+
90+
${extraBlogMeta.join('\n')}
91+
4492
<style>
4593
@font-face {
4694
font-family: "Montserrat";

0 commit comments

Comments
 (0)