|
1 |
| -import hljs from 'highlight.js'; |
2 |
| -import Choices from 'choices.js'; |
| 1 | +import hljs from 'highlight.js' |
| 2 | +import Choices from 'choices.js' |
3 | 3 |
|
4 | 4 | // Create a multiselect element.
|
5 | 5 | window.choices = (element) => {
|
6 | 6 | return new Choices(element, { maxItemCount: 3, removeItemButton: true });
|
7 |
| -}; |
| 7 | +} |
8 | 8 |
|
9 | 9 | // Syntax highlight code blocks.
|
10 | 10 | window.highlightCode = (element) => {
|
11 | 11 | element.querySelectorAll('pre code').forEach((block) => {
|
12 | 12 | hljs.highlightBlock(block);
|
13 |
| - }); |
14 |
| -}; |
| 13 | + }) |
| 14 | +} |
15 | 15 |
|
16 | 16 | // Create Capitalize string
|
17 |
| -window.capitalize = (string) => string.replace(/^\w/, (c) => c.toUpperCase()); |
| 17 | +window.capitalize = (string) => string.replace(/^\w/, (c) => c.toUpperCase()) |
18 | 18 |
|
19 | 19 | // Create a snake case string
|
20 |
| -window.snakeCase = (string) => string && string.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g).map(s => s.toLowerCase()).join('_'); |
| 20 | +window.snakeCase = (string) => string && string.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g).map(s => s.toLowerCase()).join('_') |
21 | 21 |
|
22 | 22 | // Share a content to social Media
|
23 | 23 | const share = function () {
|
@@ -65,3 +65,31 @@ const share = function () {
|
65 | 65 | }
|
66 | 66 |
|
67 | 67 | share()
|
| 68 | + |
| 69 | +// Get all p tag of a content and get the 8th to add a link element with affiliate link |
| 70 | +const addAffiliateLink = function () { |
| 71 | + let articleContent = document.getElementById('content') |
| 72 | + |
| 73 | + if (! articleContent) { |
| 74 | + return; |
| 75 | + } |
| 76 | + |
| 77 | + let pTags = document.getElementById('content').querySelectorAll('p') |
| 78 | + let i = 0 |
| 79 | + pTags.forEach((p) => { |
| 80 | + if (i === 7) { |
| 81 | + let a = document.createElement('a') |
| 82 | + a.setAttribute('href', 'https://www.digitalocean.com/?refcode=d6dca1691fb4&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge') |
| 83 | + a.setAttribute('target', '_blank') |
| 84 | + a.classList.add('relative', 'affiliate', 'block', 'w-full', 'mb-6', 'overflow-hidden', 'rounded-lg', 'cursor-pointer') |
| 85 | + a.innerHTML = ` |
| 86 | + <img src="/images/affiliate-link.jpg" class="w-full rounded-t-lg" alt="Affiliate link" /> |
| 87 | + <span class="block w-full h-auto px-3 py-2 font-bold text-center text-white uppercase text-xs bg-gradient-to-r from-green-500 via-indigo-600 to-blue-500">Obtenez le code gratuit en créant votre serveur 🚀</span> |
| 88 | + ` |
| 89 | + p.parentNode.insertBefore(a, p.nextSibling) |
| 90 | + } |
| 91 | + i++ |
| 92 | + }) |
| 93 | +} |
| 94 | + |
| 95 | +addAffiliateLink() |
0 commit comments