File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ // Meta tag management utilities
2+ export function setMetaTag ( name : string , content : string ) : void {
3+ let el = document . querySelector ( 'meta[name=' + JSON . stringify ( name ) + ']' ) ;
4+ if ( ! el ) {
5+ el = document . createElement ( 'meta' ) ;
6+ el . setAttribute ( 'name' , name ) ;
7+ document . head . appendChild ( el ) ;
8+ }
9+ el . setAttribute ( 'content' , content ) ;
10+ }
11+
12+ export function setOgTag ( property : string , content : string ) : void {
13+ let el = document . querySelector ( 'meta[property=' + JSON . stringify ( property ) + ']' ) ;
14+ if ( ! el ) {
15+ el = document . createElement ( 'meta' ) ;
16+ el . setAttribute ( 'property' , property ) ;
17+ document . head . appendChild ( el ) ;
18+ }
19+ el . setAttribute ( 'content' , content ) ;
20+ }
21+
22+ export function setPageMeta ( title : string , description : string ) : void {
23+ document . title = title ;
24+ setMetaTag ( 'description' , description ) ;
25+ setOgTag ( 'og:title' , title ) ;
26+ setOgTag ( 'og:description' , description ) ;
27+ }
You can’t perform that action at this time.
0 commit comments