-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvictorhugo.html
1573 lines (1267 loc) · 63.9 KB
/
victorhugo.html
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{{ if .Site.IsServer }}
{{ if .Params.Victor_Hugo }}
{{ if .Params.focus_keyword }}
<!-- Victor Hugo the SEO tool -->
<!-- jQuery impwort -->
{{ if or (eq .Params.Victor_Hugo_clean "true") (eq .site.Params.Victor_Hugo_clean "true") }}{{ else }}
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
{{ end }}
<script>
window.addEventListener('DOMContentLoaded', function(){
// VICTOR HUGO
// By Javier Cabrera
// https://github.com/doncabreraphone/victorhugo
// READABILITY SCORE by Ahava
// https://www.simoahava.com/analytics/calculate-readability-scores-for-content/
// from this github https://github.com/sahava/readability-score-javascript
// Many thanks, Simo!
// readabilityFunction("{{ .Content }}");
function readabilityFunction(text){
/* To speed the script up, you can set a sampling rate in words. For example, if you set
* sampleLimit to 1000, only the first 1000 words will be parsed from the input text.
* Set to 0 to never sample.
*/
var sampleLimit = 1000;
// Manual rewrite of the textstat Python library (https://github.com/shivam5992/textstat/)
/*
* Regular expression to identify a sentence. No, it's not perfect.
* Fails e.g. with abbreviations and similar constructs mid-sentence.
*/
var sentenceRegex = new RegExp('[.?!]\\s[^a-z]', 'g');
/*
* Regular expression to identify a syllable. No, it's not perfect either.
* It's based on English, so other languages with different vowel / consonant distributions
* and syllable definitions need a rewrite.
* Inspired by https://bit.ly/2VK9dz1
*/
var syllableRegex = new RegExp('[aiouy]+e*|e(?!d$|ly).|[td]ed|le$', 'g');
// Baseline for FRE - English only
var freBase = {
base: 206.835,
sentenceLength: 1.015,
syllablesPerWord: 84.6,
syllableThreshold: 3
};
var cache = {};
var punctuation = ['!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>','?','@','[',']','^','_','`','{','|','}','~'];
var legacyRound = function(number, precision) {
var k = Math.pow(10, (precision || 0));
return Math.floor((number * k) + 0.5 * Math.sign(number)) / k;
};
var charCount = function(text) {
if (cache.charCount) return cache.charCount;
if (sampleLimit > 0) text = text.split(' ').slice(0, sampleLimit).join(' ');
text = text.replace(/\s/g, '');
return cache.charCount = text.length;
};
var removePunctuation = function(text) {
return text.split('').filter(function(c) {
return punctuation.indexOf(c) === -1;
}).join('');
};
var letterCount = function(text) {
if (sampleLimit > 0) text = text.split(' ').slice(0, sampleLimit).join(' ');
text = text.replace(/\s/g, '');
return removePunctuation(text).length;
};
var lexiconCount = function(text, useCache, ignoreSample) {
if (useCache && cache.lexiconCount) return cache.lexiconCount;
if (ignoreSample !== true && sampleLimit > 0) text = text.split(' ').slice(0, sampleLimit).join(' ');
text = removePunctuation(text);
var lexicon = text.split(' ').length;
return useCache ? cache.lexiconCount = lexicon : lexicon;
};
var getWords = function(text, useCache) {
if (useCache && cache.getWords) return cache.getWords;
if (sampleLimit > 0) text = text.split(' ').slice(0, sampleLimit).join(' ');
text = text.toLowerCase();
text = removePunctuation(text);
var words = text.split(' ');
return useCache ? cache.getWords = words : words;
}
var syllableCount = function(text, useCache) {
if (useCache && cache.syllableCount) return cache.syllableCount;
var count = 0;
var syllables = getWords(text, useCache).reduce(function(a, c) {
return a + (c.match(syllableRegex) || [1]).length;
}, 0);
return useCache ? cache.syllableCount = syllables : syllables;
};
var polySyllableCount = function(text, useCache) {
var count = 0;
getWords(text, useCache).forEach(function(word) {
var syllables = syllableCount(word);
if (syllables >= 3) {
count += 1;
}
});
return count;
};
var sentenceCount = function(text, useCache) {
if (useCache && cache.sentenceCount) return cache.sentenceCount;
if (sampleLimit > 0) text = text.split(' ').slice(0, sampleLimit).join(' ');
var ignoreCount = 0;
var sentences = text.split(sentenceRegex);
sentences.forEach(function(s) {
if (lexiconCount(s, true, false) <= 2) { ignoreCount += 1; }
});
var count = Math.max(1, sentences.length - ignoreCount);
return useCache ? cache.sentenceCount = count : count;
};
var avgSentenceLength = function(text) {
var avg = lexiconCount(text, true) / sentenceCount(text, true);
return legacyRound(avg, 2);
};
var avgSyllablesPerWord = function(text) {
var avg = syllableCount(text, true) / lexiconCount(text, true);
return legacyRound(avg, 2);
};
var avgCharactersPerWord = function(text) {
var avg = charCount(text) / lexiconCount(text, true);
return legacyRound(avg, 2);
};
var avgLettersPerWord = function(text) {
var avg = letterCount(text, true) / lexiconCount(text, true);
return legacyRound(avg, 2);
};
var avgSentencesPerWord = function(text) {
var avg = sentenceCount(text, true) / lexiconCount(text, true);
return legacyRound(avg, 2);
};
var fleschReadingEase = function(text) {
var sentenceLength = avgSentenceLength(text);
var syllablesPerWord = avgSyllablesPerWord(text);
return legacyRound(
freBase.base -
freBase.sentenceLength * sentenceLength -
freBase.syllablesPerWord * syllablesPerWord,
2
);
};
var fleschKincaidGrade = function(text) {
var sentenceLength = avgSentenceLength(text);
var syllablesPerWord = avgSyllablesPerWord(text);
return legacyRound(
0.39 * sentenceLength +
11.8 * syllablesPerWord -
15.59,
2
);
};
var smogIndex = function(text) {
var sentences = sentenceCount(text, true);
if (sentences >= 3) {
var polySyllables = polySyllableCount(text, true);
var smog = 1.043 * (Math.pow(polySyllables * (30 / sentences), 0.5)) + 3.1291;
return legacyRound(smog, 2);
}
return 0.0;
};
var colemanLiauIndex = function(text) {
var letters = legacyRound(avgLettersPerWord(text) * 100, 2);
var sentences = legacyRound(avgSentencesPerWord(text) * 100, 2);
var coleman = 0.0588 * letters - 0.296 * sentences - 15.8;
return legacyRound(coleman, 2);
};
var automatedReadabilityIndex = function(text) {
var chars = charCount(text);
var words = lexiconCount(text, true);
var sentences = sentenceCount(text, true);
var a = chars / words;
var b = words / sentences;
var readability = (
4.71 * legacyRound(a, 2) +
0.5 * legacyRound(b, 2) -
21.43
);
return legacyRound(readability, 2);
};
var linsearWriteFormula = function(text) {
var easyWord = 0;
var difficultWord = 0;
var roughTextFirst100 = text.split(' ').slice(0,100).join(' ');
var plainTextListFirst100 = getWords(text, true).slice(0,100);
plainTextListFirst100.forEach(function(word) {
if (syllableCount(word) < 3) {
easyWord += 1;
} else {
difficultWord += 1;
}
});
var number = (easyWord + difficultWord * 3) / sentenceCount(roughTextFirst100);
if (number <= 20) {
number -= 2;
}
return legacyRound(number / 2, 2);
};
var rix = function(text) {
var words = getWords(text, true);
var longCount = words.filter(function(word) {
return word.length > 6;
}).length;
var sentencesCount = sentenceCount(text, true);
return legacyRound(longCount / sentencesCount, 2);
};
var readingTime = function(text) {
var wordsPerSecond = 4.17;
// To get full reading time, ignore cache and sample
return legacyRound(lexiconCount(text, false, true) / wordsPerSecond, 2);
};
// Build textStandard
var grade = [];
var obj = {};
(function() {
// FRE
var fre = obj.fleschReadingEase = fleschReadingEase(text);
if (fre < 100 && fre >= 90) {
grade.push(5);
} else if (fre < 90 && fre >= 80) {
grade.push(6);
} else if (fre < 80 && fre >= 70) {
grade.push(7);
} else if (fre < 70 && fre >= 60) {
grade.push(8);
grade.push(9);
} else if (fre < 60 && fre >= 50) {
grade.push(10);
} else if (fre < 50 && fre >= 40) {
grade.push(11);
} else if (fre < 40 && fre >= 30) {
grade.push(12);
} else {
grade.push(13);
}
// FK
var fk = obj.fleschKincaidGrade = fleschKincaidGrade(text);
grade.push(Math.floor(fk));
grade.push(Math.ceil(fk));
// SMOG
var smog = obj.smogIndex = smogIndex(text);
grade.push(Math.floor(smog));
grade.push(Math.ceil(smog));
// CL
var cl = obj.colemanLiauIndex = colemanLiauIndex(text);
grade.push(Math.floor(cl));
grade.push(Math.ceil(cl));
// ARI
var ari = obj.automatedReadabilityIndex = automatedReadabilityIndex(text);
grade.push(Math.floor(ari));
grade.push(Math.ceil(ari));
// LWF
var lwf = obj.linsearWriteFormula = linsearWriteFormula(text);
grade.push(Math.floor(lwf));
grade.push(Math.ceil(lwf));
// RIX
var rixScore = obj.rix = rix(text);
if (rixScore >= 7.2) {
grade.push(13);
} else if (rixScore < 7.2 && rixScore >= 6.2) {
grade.push(12);
} else if (rixScore < 6.2 && rixScore >= 5.3) {
grade.push(11);
} else if (rixScore < 5.3 && rixScore >= 4.5) {
grade.push(10);
} else if (rixScore < 4.5 && rixScore >= 3.7) {
grade.push(9);
} else if (rixScore < 3.7 && rixScore >= 3.0) {
grade.push(8);
} else if (rixScore < 3.0 && rixScore >= 2.4) {
grade.push(7);
} else if (rixScore < 2.4 && rixScore >= 1.8) {
grade.push(6);
} else if (rixScore < 1.8 && rixScore >= 1.3) {
grade.push(5);
} else if (rixScore < 1.3 && rixScore >= 0.8) {
grade.push(4);
} else if (rixScore < 0.8 && rixScore >= 0.5) {
grade.push(3);
} else if (rixScore < 0.5 && rixScore >= 0.2) {
grade.push(2);
} else {
grade.push(1);
}
// Find median grade
grade = grade.sort(function(a, b) { return a - b; });
var midPoint = Math.floor(grade.length / 2);
var medianGrade = legacyRound(
grade.length % 2 ?
grade[midPoint] :
(grade[midPoint-1] + grade[midPoint]) / 2.0
);
obj.medianGrade = medianGrade;
})();
obj.readingTime = readingTime(text);
return obj;
};
/// END
// PASSIVE VOICE
// passive('{{ .Content }}').length
var irregulars = [
'awoken',
'been',
'born',
'beat',
'become',
'begun',
'bent',
'beset',
'bet',
'bid',
'bidden',
'bound',
'bitten',
'bled',
'blown',
'broken',
'bred',
'brought',
'broadcast',
'built',
'burnt',
'burst',
'bought',
'cast',
'caught',
'chosen',
'clung',
'come',
'cost',
'crept',
'cut',
'dealt',
'dug',
'dived',
'done',
'drawn',
'dreamt',
'driven',
'drunk',
'eaten',
'fallen',
'fed',
'felt',
'fought',
'found',
'fit',
'fled',
'flung',
'flown',
'forbidden',
'forgotten',
'foregone',
'forgiven',
'forsaken',
'frozen',
'gotten',
'given',
'gone',
'ground',
'grown',
'hung',
'heard',
'hidden',
'hit',
'held',
'hurt',
'kept',
'knelt',
'knit',
'known',
'laid',
'led',
'leapt',
'learnt',
'left',
'lent',
'let',
'lain',
'lighted',
'lost',
'made',
'meant',
'met',
'misspelt',
'mistaken',
'mown',
'overcome',
'overdone',
'overtaken',
'overthrown',
'paid',
'pled',
'proven',
'put',
'quit',
'read',
'rid',
'ridden',
'rung',
'risen',
'run',
'sawn',
'said',
'seen',
'sought',
'sold',
'sent',
'set',
'sewn',
'shaken',
'shaven',
'shorn',
'shed',
'shone',
'shod',
'shot',
'shown',
'shrunk',
'shut',
'sung',
'sunk',
'sat',
'slept',
'slain',
'slid',
'slung',
'slit',
'smitten',
'sown',
'spoken',
'sped',
'spent',
'spilt',
'spun',
'spit',
'split',
'spread',
'sprung',
'stood',
'stolen',
'stuck',
'stung',
'stunk',
'stridden',
'struck',
'strung',
'striven',
'sworn',
'swept',
'swollen',
'swum',
'swung',
'taken',
'taught',
'torn',
'told',
'thought',
'thrived',
'thrown',
'thrust',
'trodden',
'understood',
'upheld',
'upset',
'woken',
'worn',
'woven',
'wed',
'wept',
'wound',
'won',
'withheld',
'withstood',
'wrung',
'written'
];
var exceptions = [
'indeed',
];
var re = new RegExp('\\b(am|are|were|being|is|been|was|be)\\b\\s*([\\w]+ed|' + irregulars.join('|') + ')\\b', 'gi');
var byRe; // lazly construct
function passive(text, options) {
var r = (options && options.by) ?
(byRe || constructByRe()) : re; // not sorry
var suggestions = [];
while (match = r.exec(text)) {
if (exceptions.indexOf(match[2].toLowerCase()) === -1) {
suggestions.push({
index: match.index,
offset: match[0].length
});
}
}
return suggestions;
}
// lol
function constructByRe () {
return byRe = new RegExp(re.toString().slice(1, -3) + '\\s*by\\b', 'gi');
}
/// HELPERS
function percentage(num, per) {
return (num/100)*per;
}
// if PASSIVE VOICE
var c = "{{ .Content | plainify}}";
victorhugo__total_sentences = c.trim().split(/[\.\?\!]\s/).length;
var victorhugo__passive = passive(c).length;
var passive__1 = victorhugo__total_sentences;
var passive__2 = victorhugo__passive;
var victorhugo__passive_result = percentage(passive__1,passive__2);
if (victorhugo__passive_result >= 10) {
$("#victorhugo__passive").html( victorhugo__passive_result.toFixed(1) + "% sentences contain passive voice, which is more than the recommended maximum of 10%. Try to use their active counterparts.").addClass('fix');
} else if (victorhugo__passive_result >= 7 && victorhugo__passive_result <= 9 ) {
$("#victorhugo__passive").html( victorhugo__passive_result.toFixed(1) + "% sentences contain passive voice, which is less than the recommended maximum of 10%, but you are getting too close. There is space for improvement.").addClass('improve');
} else {
$("#victorhugo__passive").html( victorhugo__passive_result.toFixed(1) + "% sentences contain passive voice, which is less than the recommended maximum of 10%. Well done.").addClass('good').appendTo($("#victorhugo__passive").parent());
}
///
/// STOPWORDS
var stopwords = ["a", "about", "above", "after", "again", "against", "ain", "all", "am", "an", "and", "any", "are", "aren", "aren't", "as", "at", "be", "because", "been", "before", "being", "below", "between", "both", "but", "by", "can", "couldn", "couldn't", "d", "did", "didn", "didn't", "do", "does", "doesn", "doesn't", "doing", "don", "don't", "down", "during", "each", "few", "for", "from", "further", "had", "hadn", "hadn't", "has", "hasn", "hasn't", "have", "haven", "haven't", "having", "he", "her", "here", "hers", "herself", "him", "himself", "his", "how", "i", "if", "in", "into", "is", "isn", "isn't", "it", "it's", "its", "itself", "just", "ll", "m", "ma", "me", "mightn", "mightn't", "more", "most", "mustn", "mustn't", "my", "myself", "needn", "needn't", "no", "nor", "not", "now", "o", "of", "off", "on", "once", "only", "or", "other", "our", "ours", "ourselves", "out", "over", "own", "re", "s", "same", "shan", "shan't", "she", "she's", "should", "should've", "shouldn", "shouldn't", "so", "some", "such", "t", "than", "that", "that'll", "the", "their", "theirs", "them", "themselves", "then", "there", "these", "they", "this", "those", "through", "to", "too", "under", "until", "up", "ve", "very", "was", "wasn", "wasn't", "we", "were", "weren", "weren't", "what", "when", "where", "which", "while", "who", "whom", "why", "will", "with", "won", "won't", "wouldn", "wouldn't", "y", "you", "you'd", "you'll", "you're", "you've", "your", "yours", "yourself", "yourselves", "could", "he'd", "he'll", "he's", "here's", "how's", "i'd", "i'll", "i'm", "i've", "let's", "ought", "she'd", "she'll", "that's", "there's", "they'd", "they'll", "they're", "they've", "we'd", "we'll", "we're", "we've", "what's", "when's", "where's", "who's", "why's", "would"]
// SLUG
var slug = "{{ .File.BaseFileName | humanize | lower }}";
// CHECK STOPWORDS IN SLUG
var stopwordFind = new RegExp('\\b('+stopwords.join('|')+')\\b');
var stopwordFound = stopwordFind.test(slug);
if (stopwordFound) {
$("#stopword").html("The slug for this page contains <a href='http://en.wikipedia.org/wiki/Stop_words'>stop words</a>, consider removing them. ").addClass('improve');
} else {
$("#stopword").html("The slug for this page looks good.").addClass('good').appendTo($("#stopword").parent());
}
var focusKeyword = "{{ .Params.focus_keyword | lower }}";
if (focusKeyword != "") {
$("#focusKeyword").html("Keyword was set for this page. You are good to go.").addClass('good').appendTo($("#focusKeyword").parent());
} else {
$("#focusKeyword").html("No focus keyword was set for this page. If you do not set a focus keyword, no score can be calculated.").addClass('improve');
}
if (focusKeyword != ""){
$("#stopword").show();
// CHECK KEYWORD IN SLUG
// It can also be a keyphrase, but not tested
var res = focusKeyword.match(/\b\w+?\b/g)
// getting words from second string
.reduce(function(a, b) {
return a || new RegExp('\\b' + b + '\\b', 'i').test(slug);
//checking string in first string
}, false);
// also set initial value as false since no strings are matched now
if (res) {
$("#slug").html("The focus keyword appears in the URL of this page.").addClass('good').appendTo($("#slug").parent());
} else {
$("#slug").html("The focus keyword does not appear in slug. Consider renaming this page.").addClass('improve');
}
} else {
$("#stopword").hide();
}
// META DESCRIPTION
var victorhugo__meta_description = $("meta[name='description'").attr("content");
if (victorhugo__meta_description){
if(victorhugo__meta_description === "") {
$("#meta__description").text( "No meta description has been specified. Search engines will display copy from the page instead." ).addClass('fix');
} else if(victorhugo__meta_description.length < 5) {
$("#meta__description").text( "The meta description is under 120 characters long. However, up to 320 characters are available." ).addClass('improve');
} else if(victorhugo__meta_description.length >= 125 && victorhugo__meta_description.length <= 320 ) {
$("#meta__description").text( "The meta description has a nice length." ).addClass("good").appendTo($("#meta__description").parent());
} else if(victorhugo__meta_description.length >= 320) {
$("#meta__description").text( "The meta description is over 320 characters. Reducing the length will ensure the entire description will be visible.").addClass('fix');
}
} else {
$("#meta__description").html( "The meta description is not set. Please add a <a href='https://github.com/doncabreraphone/victorhugo/blob/master/misc/hugo-seo-snippets.md'>meta description</a> to your post.").addClass('fix');
}
// CONTENT
var victorhugo__content = "{{ .Content | lower }}";
var victorhugo__rawcontent = victorhugo__content;
victorhugo__content = victorhugo__content.split(' ');
if(victorhugo__content === "") {
$("#victorhugo__content").text( "This page has no content. Please add some." ).addClass('fix');
} else if(victorhugo__content.length >= 1 && victorhugo__content.length <= 200 ) {
$("#victorhugo__content").text( "The text contains " + victorhugo__content.length + " words. This is far below the recommended minimum of 300 words. Add more content that is relevant for the topic. ").addClass('fix');
} else if(victorhugo__content.length >= 200 && victorhugo__content.length <= 290 ) {
$("#victorhugo__content").text( "The text contains under " + victorhugo__content.length + " words long. This is slightly below the recommended minimum of 300 words. Add a bit more copy ").addClass('improve');
} else if(victorhugo__content.length >= 301) {
$("#victorhugo__content").text( "The text is over 300 words. This is more than or equal to the recommended minimum of 300 words.").addClass('good').appendTo($("#victorhugo__content").parent());
}
// FIRST PARAGRAPH
// The focus keyword doesn't appear in the first paragraph of the copy. Make sure the topic is clear immediately
victorhugo__firstParagraph = $(victorhugo__rawcontent).first('p').first().text();
var victorhugo__firstParagraph_check = focusKeyword.match(/\b\w+?\b/g)
.reduce(function(a, b) {
return a || new RegExp('\\b' + b + '\\b', 'i').test(victorhugo__firstParagraph);
}, false);
if (victorhugo__firstParagraph_check) {
$("#victorhugo__firstParagraph").html("The focus keyword appears in the first paragraph of the copy. Well done. This adds visibility. ").addClass('good').appendTo($("#victorhugo__firstParagraph").parent());
} else {
$("#victorhugo__firstParagraph").html("The focus keyword doesn't appear in the first paragraph of the copy. Make sure the topic is clear immediately. ").addClass('fix');
};
// SUBHEADINGS
// Checks if there is a subheading in the tex
// returns true if there is
// checks if the subheading contains focus keywords
var victorhugo__subheadings = victorhugo__rawcontent.indexOf('<h2>') >= 0; // true
if( victorhugo__subheadings ) {
var a= $(victorhugo__rawcontent).filter('h2').text().split(' ');
var b= focusKeyword.split(' ');
var unique = $.grep(a, function(element) {
return $.inArray(element, b) == -1;
});
var index = $.grep(a, function(element) {
if($.inArray(element,b)>=0)
{
return a
}
});
// console.log(index.length);
if (index.length > 0 && index.length <= 1 ) {
$("#victorhugo__subheadings").html("The focus keyword appears only in 1 subheadings in your copy. Try to use it in at least one more subheading.").addClass('improve');
} else if (index.length >= 2 ) {
$("#victorhugo__subheadings").html("The focus keyword appears in more than one subheadings in your copy, which is optimal.").addClass('good').appendTo($("#victorhugo__subheadings").parent());
} else {
$("#victorhugo__subheadings").html("You have not used the focus keyword in any subheading (such as an H2) in your copy.").addClass('improve');
}
} else {
$("#victorhugo__subheadings").html("The text does not contain any subheadings. Add at least one subheading. ").addClass('fix');
}
// TITLE
// The focus keyword 'Welcome' does not appear in the SEO title.
victorhugo__title = "{{ .Page.Title }}";
if (victorhugo__title) {
var victorhugo__title_check = focusKeyword.match(/\b\w+?\b/g)
.reduce(function(a, b) {
return a || new RegExp('\\b' + b + '\\b', 'i').test(victorhugo__title);
}, false);
if (victorhugo__title_check) {
$("#victorhugo__title").html("The focus keyword appears in the title. ").addClass('good').appendTo($("#victorhugo__title").parent());
} else {
$("#victorhugo__title").html("The focus keyword '" + focusKeyword + "' does not appear in the SEO title.").addClass('fix');
}
} else {
$("#victorhugo__title").html("Please add a title to the page.").addClass('fix');
}
// CONTENT KEYWORD DENSITY
// The focus keyword doesn't appear in the first paragraph of the copy. Make sure the topic is clear immediately
var victorhugo__density = $(victorhugo__rawcontent).not('img').text();
var victorhugo__density_check = focusKeyword.match(/\b\w+?\b/g).reduce(function(a, b) {
return a || new RegExp('\\b' + b + '\\b', 'i').test(victorhugo__density);
}, false);
if (victorhugo__density_check) {
// get the density
var victorhugo__focusKeyword = focusKeyword.split(' ');
var victorhugo__density_amount = 0;
var victorhugo__densityWords = victorhugo__rawcontent.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g," ").toLowerCase().split(' ');
$.each(victorhugo__densityWords, function(index, victorhugo__densityWords) {
if ($.inArray(victorhugo__densityWords, victorhugo__focusKeyword) != -1) {
++victorhugo__density_amount;
}
});
var density__1 = victorhugo__density_amount;
var density__2 = victorhugo__densityWords.length;
// console.log(density__1 + " x " + density__2);
var victorhugo__density_result = density__1 * 100 / density__2;
if (!isFinite(victorhugo__density_result)) victorhugo__density_result = 0;
// console.log(victorhugo__density_result.toFixed(1) + "%");
victorhugo__density_result = victorhugo__density_result;
var victorhugo__density_calc;
if (victorhugo__density_result >= 0.1 && victorhugo__density_result <= 0.2) {
victorhugo__density_calc = "good, but you can do better";
$("#victorhugo__density").addClass('improve');
} else if (victorhugo__density_result > 0.2) {
victorhugo__density_calc = "great";
$("#victorhugo__density").addClass('good').appendTo($("#victorhugo__density").parent());
} else {
victorhugo__density_calc = "bad";
$("#victorhugo__density").addClass('fix');
}
$("#victorhugo__density").html("The keyword density is " + victorhugo__density_result.toFixed(1) + "%, which is " + victorhugo__density_calc + "; the focus keyword was found " + victorhugo__density_amount + " times (including subheadings).");
} else {
$("#victorhugo__density").html("The keyword density is 0%, which is too low; the focus keyword was found 0 times (including subheadings).").addClass('fix');
}
// Check for LINKS
var hugoLinks = $(victorhugo__rawcontent).find('a[href], area[href], base[href], link[href]').length;
if (hugoLinks == "0") {
$("#victorhugo__content_links").text( "No links appear in this page, consider adding some (outbound and internal)." ).addClass('fix');
} else if (hugoLinks <= "2") {
$("#victorhugo__content_links").text( "This page has just " + hugoLinks + " link(s). You can do better!" ).addClass('improve');
} else {
$("#victorhugo__content_links").text( "This page has " + hugoLinks + " link(s). That's more than enough!" ).addClass('good').appendTo($("#victorhugo__content_links").parent());
}
// Check for IMGS
var hugoIMGS = $(victorhugo__rawcontent).find('img').length;
if (hugoIMGS == "0") {
$("#victorhugo__content_imgs").text( "No images appear in this page, consider adding some as appropriate." ).addClass('fix');
} else if (hugoIMGS == "1") {
$("#victorhugo__content_imgs").text( "This page has just one image. You can do better!" ).addClass('improve')
} else if (hugoIMGS <= 2) {
$("#victorhugo__content_imgs").text( "This page has the right amount of images. You can add more if you like." ).addClass("good").appendTo($("#victorhugo__content_imgs").parent());
var re = 0;
$($(victorhugo__rawcontent).find('img')).each(function(){
// $(this).is(':contains("Replace Me")')
if($(this).attr('alt')) {
var attr = $(this).attr('alt');
var attr_res = focusKeyword.match(/\b\w+?\b/g)
.reduce(function(a, b) {
return a || new RegExp('\\b' + b + '\\b', 'i').test(attr);
}, false);
if (attr_res){
re = re +1;
}
}
});
if (re == hugoIMGS) {
$("#victorhugo__content_imgs").text( "The images on this page contain alt attributes with the focus keyword." ).addClass("good").appendTo($("#victorhugo__content_imgs").parent());
} else if (re == 0) {
$("#victorhugo__content_imgs").text( "The images in this page are missing the alt attributes." ).addClass("improve").prependTo($("#victorhugo__content_imgs").parent());
} else {
$("#victorhugo__content_imgs").text( "Some of the images on this page do not have alt attributes containing the focus keyword." ).addClass("improve").prependTo($("#victorhugo__content_imgs").parent());
}
}
// GOOGLE SNIPPET
///////////////////////////////////////
$("#victorhugo #snippet_msg").hide();
if (victorhugo__title && victorhugo__meta_description) {
$("#victorhugo .snippet__desc").html(victorhugo__meta_description);
} else {
// We show the error msg
$("#victorhugo #snippet_msg").show();
$("#victorhugo .snippet_wrap").hide();
}
var victorhugo__snippet__title = "{{ .Params.Title }}";
victorhugo__snippet__title = victorhugo__snippet__title.substring(0,57);
$(".snippet__title").html(victorhugo__snippet__title);
/// READABILITY SCORE
var victorhugo__readability = readabilityFunction("{{ .Content }}").fleschReadingEase;
if ( victorhugo__readability >= 60 ) {
$("#victorhugo__readability").html( "The copy scores '" + victorhugo__readability.toFixed(1) +"' in the '<a href='https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests' target='_blank'>Flesch Reading Ease test</a>', which is considered ok to read. Well done! " ).addClass("good").appendTo($("#victorhugo__readability").parent());
} else if ( victorhugo__readability >= 45 && victorhugo__readability < 60 ) {
$("#victorhugo__readability").html( "The copy scores '" + victorhugo__readability.toFixed(1) +"' in the <a href='https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests' target='_blank'>Flesch Reading Ease test</a>, which is considered fairly difficult to read. Try to make shorter sentences to improve readability." ).addClass("improve");
} else if ( victorhugo__readability < 45 ) {
$("#victorhugo__readability").html( "The copy scores '" + victorhugo__readability.toFixed(1) +"' in the <a href='https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests' target='_blank'>Flesch Reading Ease test</a>, which is considered extremely difficult to read. Try to make shorter sentences to improve readability. This needs improvement." ).addClass("fix");
}
// TIME READING SCORE
var victorhugo__readingTime = readabilityFunction("{{ .Content }}").readingTime;
// SVG CIRCLES
(function() {
document.querySelectorAll('#victorhugo__audit .circular-progress').forEach((progress) => {
// First we set the score
var victorhugo__seoScoreCircle = $('#victorhugo__seoScore_circle');
var victorhugo__readingCircle = $('#victorhugo__readingTime_circle ');
victorhugo__readingPercent = Math.round( ( victorhugo__readingTime * 100 / 270 ) );
victorhugo__readingCircle.attr("data-percentage", victorhugo__readingPercent);
/// SEO SCORE
/// Has to be calcualted at the end since we went through every other factor
var victorhugo__seoScore = $('#victorhugo__list .good').length;
victorhugo__seoScorePercent = Math.round( ( victorhugo__seoScore * 100 / 13 ) );
if (victorhugo__seoScore >= 0) {
victorhugo__seoScoreCircle.attr("data-percentage", victorhugo__seoScorePercent);
}
// Now we start the animation
const percentage = progress.dataset.percentage;
const circle = progress.querySelector('.circle');
if (percentage >= 100) {
progress.querySelector('#victorhugo__audit .percentage').innerHTML = `100`;
circle.setAttribute('stroke-dasharray', `100, 100`);
} else {
progress.querySelector('#victorhugo__audit .percentage').innerHTML = `${percentage}`;
circle.setAttribute('stroke-dasharray', `${percentage}, 100`);
}
circle.classList.add('-play');
if (percentage >= 70) {
circle.setAttribute("style", "stroke: #8fd739;");
} else if (percentage < 70 && percentage >= 45) {
circle.setAttribute("style", "stroke: #ffd636;");
} else if (percentage < 45) {
circle.setAttribute("style", "stroke: #f45a5a;");
}
});
})();
// OPEN CLOSE DRAWER
$("#victorhugo__close").on('click', function (e) {
e.stopPropagation();
e.preventDefault();
$('#victorhugo').removeClass("victorhugo__open");
$('#victorhugo').addClass("victorhugo__close");
$('#victorhugo__open').show();
});
$("#victorhugo__open").on('click', function (e) {
e.stopPropagation();
e.preventDefault();
$('#victorhugo').removeClass("victorhugo__close");
$('#victorhugo').addClass("victorhugo__open");
});
var victorhugo__snippet_tw_img = $("meta[name='twitter:image']").attr("content");
var victorhugo__snippet_tw_link = '<svg style="position:relative; width:18px; margin-left: 9px; margin-right: -4px;" viewBox="0 0 24 24" class="r-4qtqp9 r-yyyyoo r-1xvli5t r-dnmrzs r-bnwqim r-1plcrui r-lrvibr"><g><path d="M11.96 14.945c-.067 0-.136-.01-.203-.027-1.13-.318-2.097-.986-2.795-1.932-.832-1.125-1.176-2.508-.968-3.893s.942-2.605 2.068-3.438l3.53-2.608c2.322-1.716 5.61-1.224 7.33 1.1.83 1.127 1.175 2.51.967 3.895s-.943 2.605-2.07 3.438l-1.48 1.094c-.333.246-.804.175-1.05-.158-.246-.334-.176-.804.158-1.05l1.48-1.095c.803-.592 1.327-1.463 1.476-2.45.148-.988-.098-1.975-.69-2.778-1.225-1.656-3.572-2.01-5.23-.784l-3.53 2.608c-.802.593-1.326 1.464-1.475 2.45-.15.99.097 1.975.69 2.778.498.675 1.187 1.15 1.992 1.377.4.114.633.528.52.928-.092.33-.394.547-.722.547z"></path><path d="M7.27 22.054c-1.61 0-3.197-.735-4.225-2.125-.832-1.127-1.176-2.51-.968-3.894s.943-2.605 2.07-3.438l1.478-1.094c.334-.245.805-.175 1.05.158s.177.804-.157 1.05l-1.48 1.095c-.803.593-1.326 1.464-1.475 2.45-.148.99.097 1.975.69 2.778 1.225 1.657 3.57 2.01 5.23.785l3.528-2.608c1.658-1.225 2.01-3.57.785-5.23-.498-.674-1.187-1.15-1.992-1.376-.4-.113-.633-.527-.52-.927.112-.4.528-.63.926-.522 1.13.318 2.096.986 2.794 1.932 1.717 2.324 1.224 5.612-1.1 7.33l-3.53 2.608c-.933.693-2.023 1.026-3.105 1.026z"></path></g></svg>'
$(".snippet__tw_img").html("<img src='" + victorhugo__snippet_tw_img + "' style='width: 100%; border:1px solid #777777; border-top-left-radius: 12px;border-top-right-radius: 12px;'><div id='victorhugo__tw_preview'><span><b>" + victorhugo__title + "</b></span><span>" + victorhugo__meta_description +"</span><span style='color:#888888'>" + victorhugo__snippet_tw_link + "yourwebsite.com</span></div>");
});
</script>
<style>
#victorhugo {
overflow-y: auto;
box-shadow: 0 0 25px #ccc;
position: fixed;
height: 100vh;
left: 0;
width: 520px;
z-index: 10000;
background: #fff;
padding: 18px 25px;
font-family: Arial, Helvetica, sans-serif !important;
color: #444;