|
1 | 1 | # Semantic Content
|
2 | 2 |
|
| 3 | +<style> |
| 4 | +article figure { |
| 5 | + display: flex; |
| 6 | + flex-direction: column; |
| 7 | + text-align: center; |
| 8 | + align-items: center; |
| 9 | +} |
| 10 | +</style> |
| 11 | + |
| 12 | +<script type=module> |
| 13 | +import * as DOMTesting from "https://cdn.skypack.dev/@testing-library/dom"; |
| 14 | +window.DOMTesting = DOMTesting; |
| 15 | + |
| 16 | +function* surroundingSourceElements(el) { |
| 17 | + let prev = el; |
| 18 | + while (prev = prev.previousElementSibling) { |
| 19 | + if (prev.matches('h1, h2, h3, h4')) break; |
| 20 | + if (prev.matches('pre.language-html')) yield { type: 'html', code: prev.textContent }; |
| 21 | + if (prev.matches('pre.language-javascript')) yield { type: 'javascript', code: prev.textContent }; |
| 22 | + } |
| 23 | + |
| 24 | + let next = el; |
| 25 | + while (next = next.nextElementSibling) { |
| 26 | + if (next.matches('h1, h2, h3, h4')) break; |
| 27 | + if (next.matches('pre.language-html')) yield { type: 'html', code: next.textContent }; |
| 28 | + if (next.matches('pre.language-javascript')) yield { type: 'javascript', code: next.textContent }; |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +const outputEls = document.querySelectorAll('article output'); |
| 33 | +console.log(outputEls); |
| 34 | + |
| 35 | +for (const outputEl of outputEls.values()) { |
| 36 | + const div = outputEl.appendChild(document.createElement('div')); |
| 37 | + div.classList.add('p-4'); |
| 38 | + |
| 39 | + console.log('outputEl', outputEl); |
| 40 | + const sources = surroundingSourceElements(outputEl); |
| 41 | + for (const source of sources) { |
| 42 | + const { type, code } = source; |
| 43 | + |
| 44 | + console.log('source', source); |
| 45 | + |
| 46 | + if (type === 'html') { |
| 47 | + div.innerHTML = code; |
| 48 | + } |
| 49 | + |
| 50 | + if (type === 'javascript') { |
| 51 | + const screen = DOMTesting.within(div); |
| 52 | + const testFunction = new Function('screen', `return ${code}`); |
| 53 | + testFunction(screen).style.border = '2px solid red'; |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | +//const htmlSourceElements = document.querySelector('article pre.language-html'); |
| 58 | +</script> |
| 59 | + |
3 | 60 | <table class="text-left table-fixed">
|
4 | 61 | <caption class="text-3xl pb-4 text-left">Content roles cheatsheet</caption>
|
5 | 62 | <thead>
|
@@ -36,18 +93,94 @@ A crawler service that visits your website on behalf of a search engine like Goo
|
36 | 93 |
|
37 | 94 | Semantic HTML elements allow meaning and structure to be determined.
|
38 | 95 |
|
39 |
| -More coming soon… |
| 96 | +The better these crawlers can understand, and the more meaning they can infer, the higher they will rank you. |
| 97 | + |
| 98 | +A web page that is just made of `<div>` and `<span>` elements means that the only content they have to use is the text. Which is a lossy and messy process. Better to provide precise and rich elements instead. |
40 | 99 |
|
41 | 100 | ## Headings
|
42 | 101 |
|
| 102 | +```html |
| 103 | +<h1>One Thousand and One Nights</h1> |
| 104 | +``` |
| 105 | + |
| 106 | +<output></output> |
| 107 | + |
| 108 | +```javascript |
| 109 | +screen.getByRole('heading'); |
| 110 | +``` |
| 111 | + |
43 | 112 | ## Lists
|
44 | 113 |
|
| 114 | +```html |
| 115 | +<ul> |
| 116 | + <li>First |
| 117 | + <li>Second |
| 118 | + <li>Third |
| 119 | +</ul> |
| 120 | +``` |
| 121 | + |
| 122 | +<output></output> |
| 123 | + |
| 124 | +```javascript |
| 125 | +screen.getByRole('list'); |
| 126 | +``` |
| 127 | + |
45 | 128 | ## Term & Definition
|
46 | 129 |
|
| 130 | +```html |
| 131 | +<dl> |
| 132 | + <dt>Name</dt> |
| 133 | + <dd>The Lion King</dd> |
| 134 | + |
| 135 | + <dt>Year Released</dt> |
| 136 | + <dd>1994</dd> |
| 137 | + |
| 138 | + <dt>Runtime</dt> |
| 139 | + <dd>88 min</dd> |
| 140 | +</dl> |
| 141 | +``` |
| 142 | + |
| 143 | +<output></output> |
| 144 | + |
47 | 145 | ## Images
|
48 | 146 |
|
| 147 | +```html |
| 148 | +<img |
| 149 | + alt="The HTML 5 logo" |
| 150 | + src= "https://unpkg.com/[email protected]/images/svg/html5.svg" |
| 151 | + width=200 |
| 152 | +> |
| 153 | +``` |
| 154 | + |
| 155 | +<output></output> |
| 156 | + |
| 157 | +```javascript |
| 158 | +screen.getByRole('img', { name: /logo/ }); |
| 159 | +``` |
| 160 | + |
49 | 161 | ## Figure
|
50 | 162 |
|
| 163 | +```html |
| 164 | +<figure> |
| 165 | + <img |
| 166 | + src= "https://unpkg.com/[email protected]/images/svg/html5.svg" |
| 167 | + width=200 |
| 168 | + > |
| 169 | + <figcaption>The HTML 5 logo</figcaption> |
| 170 | +</figure> |
| 171 | +``` |
| 172 | + |
| 173 | +<output></output> |
| 174 | + |
| 175 | +```javascript |
| 176 | +screen.getByRole('figure'); |
| 177 | +``` |
| 178 | + |
51 | 179 | ## Details & Summary
|
52 | 180 |
|
53 | 181 | ## Separator
|
| 182 | + |
| 183 | +<script type=module> |
| 184 | + import * as DOM from "https://cdn.skypack.dev/@testing-library/dom"; |
| 185 | + console.log("DOM", Object.keys(DOM), DOM.screen); |
| 186 | +</script> |
0 commit comments