- Notifications
You must be signed in to change notification settings - Fork0
A simple vanilla JavaScript SEO library for SPAs (Single Page Applications).
oOthkOo/seo.js
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The most simple, framework agnostic and easy to use JavaScript SEO meta tag management library.
- Built in pure vanilla JavaScript with no dependencies.
- Blazing fast SEO tags update.
- Support thetag meta elements.
- Support thelink meta elements.
- Support themeta meta elements.
- Support extending by custom tag configurations
- Support tag generation white templates and tokens.
npm install @oothkoo/seo-js
<scriptsrc="dist/seo-X.X.X.min.js"type="text/javascript"></script>
name | type | default | description |
---|---|---|---|
debug | Boolean | false | Enable debug mode |
headSelector | String | 'head' | Page CSS selector |
ignoreEmptyTagValue | Boolean | true | Ignore all meta registered with no values provided |
importSeofrom'@oothkoo/seo-js'varseo=newSeo({debug:true,headSelector:'head',ignoreEmptyTagValue:true})
Register a meta configuration. You must register all metas before to use the library.
config
-Object - Configuration to use.
seo.use({name:'name',// meta configuration ameselector:'name',// dom selector (.class, #id etc..)template:'<template>{value}</template>'// html template})
Generate atag meta configuration. This configuration produces tags from this html template<{name}>{value}</{name}>
.
name
-String | Array - Tag name(s)
// Register 'title' tag and produces <title>{value}</title>seo.use(seo.tag('title'))seo.use(seo.tag(['author','section']))
Generate ameta[name=""] meta configuration. This configuration produces tags from this html template<meta name="{name}" content="{value}" />
.
name
-String | Array - Tag name(s)
// Register 'title' tag and produces <meta name="title" content="{value}" />seo.use(seo.metaName('title'))seo.use(seo.metaName(['keywords','description']))
Generate ameta[property=""] meta configuration. This configuration produces tags from this html template<meta property="{name}" content="{value}" />
.
name
-String | Array - Tag name(s)
// Register 'og:title' tag and produces <meta name="og:title" content="{value}" />seo.use(seo.metaProperty('og:title'))seo.use(seo.metaProperty(['og:site_name','og:description']))
Generate alink[rel=""] meta configuration. This configuration produces tags from this html template<link rel="{name}" href="{value}" />
.
name
-String | Array - Tag name(s)
// Register 'favicon' tag and produces <link rel="favicon" href="{value}" />seo.use(seo.link('favicon'))seo.use(seo.link(['icon','robots']))
Delete all registered SEO meta tags.
seo.clearMetas()
Delete all terms used for templating.
seo.clearTerms()
Setting a couple of terms to be used for templating.
terms
-Object - Tokens name/value list ({name: value})
// Setting terms for templatingseo.updateTerms({'title':"Seo.js - A beautiful example",'description':"Seo example page description",'website':"https://www.oothkoo.com"})
Delete all registered meta tags in current html page.
seo.clear()
Update all metas specified in current html page. Theses metas must be registered bySeo.use(config)
before calling this function.
metas
-Object - Meta name/value list ({name: value})only
-Boolean - Meta scope (default:false
)true
: Update only metas specified inmetas
argumentfalse
: Update all metas registered and overwrite if needed
// Setting terms for templatingseo.update({'title':"{title}",// Using terms 'title' for value'description':"{description}",// Using terms 'description' for value'website':"https://www.oothkoo.com"})
// When page content is loadedwindow.addEventListener('DOMContentLoaded',function(){// Initialize Seo libraryvarseo=newSeo({debug:true})// Register basic page metasseo.use(seo.tag('title'))seo.use(seo.metaName(['description','keywords']))seo.use(seo.metaLink('canonical'))// Register Open Graph page metasseo.use(seo.metaProperty(['og:type','og:site_name','og:title','og:url','og:description','og:image','og:image:width','og:image:height']))// Register Twitter page metasseo.use(seo.metaName(['twitter:card','twitter:site','twitter:creator','twitter:domain','twitter:url','twitter:image','twitter:title','twitter:description','twitter:label1','twitter:data1','twitter:label2','twitter:data2']))// Register Slack page metasseo.use(seo.metaName(['slack-app-id']))// Setting terms for templatingseo.updateTerms({'name':"SlugBay",'title':"Seo - A beautiful example",'description':"SlugBay helps you centralise and better manage all your resources, and discover new interesting material more quickly",'domain':"slugbay.com",'website':"https://www.slugbay.com",'image':"https://www.slugbay.com/pictures/opengraph.png",'username':"@slugbay"})// Update all current registered metasseo.update({'title':"{title}",'description':"{description}",'keywords':"example keyword seo js",'canonical':"{website}",'og:type':"website",'og:title':"{title}",'og:site_name':"{name}",'og:url':"{website}",'og:description':"{description}",'og:image':"{image}",'og:image:width':"640",'og:image:height':"280",'twitter:card':"summary_large_image",'twitter:site':"{username}",'twitter:creator':"{username}",'twitter:domain':"slugbay.com",'twitter:url':"{website}",'twitter:image':"{image}",'twitter:title':"{title}",'twitter:description':"{description}",'slack-app-id':"A2UTWA5PT"})})
❤️ Donations are always welcome ❤️.
Coins | Symbols | Addresses |
---|---|---|
BTC | 3B52fbzNFQTaKZxWf5GrCUsASD2UP8na4A | |
ETH | 0x1C389f1f85Cdb3C2996b83fAc87E496A80698B7C | |
SOL | F14pWhGjGLcCF8RMk4JhbK2kD49iBBwa9KFygRJo54Fm |
About
A simple vanilla JavaScript SEO library for SPAs (Single Page Applications).
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.