@@ -22,7 +22,7 @@ export function useCanonicalURL(path?: string) {
2222 return `${ cleanUrl } ${ basePath } `
2323}
2424
25- export function useEnhancedSeoMeta ( options : {
25+ interface SeoMetaOptions {
2626 title ?: string
2727 description ?: string
2828 image ?: string
@@ -34,19 +34,33 @@ export function useEnhancedSeoMeta(options: {
3434 modifiedTime ?: string
3535 tags ?: string [ ]
3636 path ?: string
37- } ) {
38- const appConfig = useAppConfig ( )
39- const canonicalUrl = useCanonicalURL ( options . path )
37+ }
4038
39+ interface AppConfig {
40+ site : {
41+ title : string
42+ desc : string
43+ ogImage ?: string
44+ lang : string
45+ author : string
46+ }
47+ socials ?: Social [ ]
48+ }
49+
50+ function buildBaseSeoMeta (
51+ options : SeoMetaOptions ,
52+ appConfig : AppConfig ,
53+ canonicalUrl : string ,
54+ ) : SeoMetaData {
4155 const metaTitle = options . title ?? appConfig . site . title
4256 const metaDescription = options . description ?? appConfig . site . desc
4357 const metaImage = options . image ?? `/${ appConfig . site . ogImage } `
44-
45- // Default image dimensions for better social media preview
4658 const imageWidth = options . imageWidth ?? 1200
4759 const imageHeight = options . imageHeight ?? 630
4860
49- const seoMeta : SeoMetaData = {
61+ const twitterHandle = appConfig . socials ?. find ( ( s : Social ) => s . name === 'Twitter' ) ?. href ?. split ( '/' ) . pop ( )
62+
63+ return {
5064 author : options . author ?? appConfig . site . author ,
5165 description : metaDescription ,
5266 ogDescription : metaDescription ,
@@ -64,29 +78,42 @@ export function useEnhancedSeoMeta(options: {
6478 twitterDescription : metaDescription ,
6579 twitterImage : metaImage ,
6680 twitterImageAlt : metaTitle ,
67- twitterSite : appConfig . socials ?. find ( ( s : Social ) => s . name === 'Twitter' ) ?. href ?. split ( '/' ) . pop ( ) ,
81+ twitterSite : twitterHandle ,
6882 twitterTitle : metaTitle ,
6983 }
84+ }
7085
71- if ( canonicalUrl !== '' && canonicalUrl . length > 0 ) {
86+ function addArticleMeta ( seoMeta : SeoMetaData , options : SeoMetaOptions ) : void {
87+ if ( options . type !== 'article' )
88+ return
89+
90+ if ( options . author != null )
91+ seoMeta . articleAuthor = [ options . author ]
92+ if ( options . publishedTime != null )
93+ seoMeta . articlePublishedTime = options . publishedTime
94+ if ( options . modifiedTime != null )
95+ seoMeta . articleModifiedTime = options . modifiedTime
96+ if ( options . tags != null && options . tags . length > 0 )
97+ seoMeta . articleTag = options . tags
98+ seoMeta . articleSection = 'Technology'
99+ }
100+
101+ export function useEnhancedSeoMeta ( options : SeoMetaOptions ) {
102+ const appConfig = useAppConfig ( )
103+ const canonicalUrl = useCanonicalURL ( options . path )
104+
105+ const seoMeta = buildBaseSeoMeta ( options , appConfig , canonicalUrl )
106+
107+ const hasCanonicalUrl = canonicalUrl !== '' && canonicalUrl . length > 0
108+ if ( hasCanonicalUrl ) {
72109 seoMeta . canonical = canonicalUrl
73110 }
74111
75- if ( options . type === 'article' ) {
76- if ( options . author != null )
77- seoMeta . articleAuthor = [ options . author ]
78- if ( options . publishedTime != null )
79- seoMeta . articlePublishedTime = options . publishedTime
80- if ( options . modifiedTime != null )
81- seoMeta . articleModifiedTime = options . modifiedTime
82- if ( options . tags != null && options . tags . length > 0 )
83- seoMeta . articleTag = options . tags
84- seoMeta . articleSection = 'Technology'
85- }
112+ addArticleMeta ( seoMeta , options )
86113
87114 useSeoMeta ( seoMeta )
88115
89- if ( canonicalUrl !== '' && canonicalUrl . length > 0 ) {
116+ if ( hasCanonicalUrl ) {
90117 useHead ( {
91118 link : [
92119 { href : canonicalUrl , rel : 'canonical' } ,
0 commit comments