-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (41 loc) · 1.73 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function SEOhelper() {
const colorLogDanger = "background:#FF2C30;color:white;margin:10px 0;padding:15px;border-radius:4px"
const colorLogWarning = "background:#F46F52;color:white;margin:10px 0;padding:15px;border-radius:4px"
const colorLogSuccess = "background:#68DB57;color:#070707;margin:10px 0;padding:15px;border-radius:4px;font-weight:bolder"
// Title page
const titlePage = document.title
if (!titlePage)
console.log("%c The page has no title!", colorLogDanger)
else
var titlePass = "ok"
// Description page
const descriptionPage = document.querySelector("meta[name='description']")
if (!descriptionPage)
console.log("%cMeta 'description' does not exist!", colorLogDanger)
else if (descriptionPage.content === "")
console.log("%cYour meta 'description' is empty!", colorLogDanger)
else
var descriptionPass = "ok"
// Heading
const heading = document.querySelectorAll("h1")
if (heading.length > 1)
console.log(`%cYou've got ${heading.length} headers, you only need one.`, colorLogWarning)
else
var headingPass = "ok"
// Imgs
const imgPass = []
document.querySelectorAll("img").forEach(function (el) {
const imgAlt = el.getAttribute("alt")[0]
if (!imgAlt) {
const imgSrc = el.getAttribute("src")
console.log(`%c${imgSrc} does not have an alt attribute`, colorLogWarning)
imgPass.push("No Alt")
}
else
imgPass.push("ok")
})
// Sounds good
if (titlePass === "ok" && descriptionPass === "ok" && !imgPass.includes("No Alt"))
console.log('%cSounds good, nice job!', colorLogSuccess)
}
module.exports.SEOhelper = SEOhelper;