@@ -19,7 +19,7 @@ function getBreadcrumbs(article) {
19
19
*/
20
20
function dropIrrelevantSections ( article ) {
21
21
article . find ( [
22
- '.chapter:has(#what-s-next)' , '.chapter:has(#next-step)' ,
22
+ '.chapter:has(#what-s-next)' , '.chapter:has(#next-step)' , '.chapter:has(#next-steps)' ,
23
23
'.chapter:has(#learn-more)' , '.chapter:has(#leave-feedback)'
24
24
] . join ( ', ' ) ) . remove ( ) ;
25
25
}
@@ -39,6 +39,45 @@ function replaceMedia(article, pageUrl) {
39
39
}
40
40
}
41
41
42
+ /**
43
+ * @param {import('cheerio').Element } node
44
+ */
45
+ function cloneAttrsString ( node ) {
46
+ return Object . entries ( ( node . attribs || { } ) ) . map ( ( [ key , value ] ) => {
47
+ const val = typeof value === 'string' ? `="${ value } "` : '' ;
48
+ return `${ key } ${ val } ` ;
49
+ } ) . join ( ' ' ) ;
50
+ }
51
+
52
+ /**
53
+ * @param {import('cheerio').Cheerio } article
54
+ * @param {string } selector
55
+ * @param {($node: import('cheerio').Cheerio<Element>, attrs: string, content: string) => string } cb
56
+ */
57
+ function replaceNode ( article , selector , cb ) {
58
+ const listStrong = article . find ( selector ) ;
59
+
60
+ for ( let i = 0 , length = listStrong . length ; i < length ; i ++ ) {
61
+ const $node = listStrong . eq ( i ) ;
62
+ const newNode = cb ( $node , cloneAttrsString ( listStrong [ i ] ) , $node . html ( ) ) ;
63
+ $node . replaceWith ( newNode ) ;
64
+ }
65
+ }
66
+
67
+ /**
68
+ * @param {import('cheerio').Cheerio } article
69
+ * @returns {void }
70
+ */
71
+ function replaceWRSSemantic ( article ) {
72
+ replaceNode ( article , 'span.control' , ( $node , attrs , content ) => (
73
+ `<b ${ attrs } >${ content } </b>`
74
+ ) ) ;
75
+
76
+ replaceNode ( article , 'div.code-block' , ( $node , attrs , content ) => (
77
+ `<code ${ attrs } >${ content } </code>`
78
+ ) ) ;
79
+ }
80
+
42
81
/**
43
82
* @param {import('cheerio').Cheerio } article
44
83
* @returns {void }
@@ -158,10 +197,11 @@ async function docs($, url, data) {
158
197
159
198
/** @type {import('cheerio').Cheerio } */
160
199
const $article = $ ( 'article.article' ) ;
161
- const pageUrl = new URL ( $ ( 'link[rel="canonical "]' ) . attr ( 'href ' ) ) ;
200
+ const pageUrl = new URL ( $ ( 'meta[property="og:url "]' ) . attr ( 'content ' ) ) ;
162
201
163
202
dropUiElements ( $article ) ;
164
203
dropIrrelevantSections ( $article ) ;
204
+ replaceWRSSemantic ( $article ) ;
165
205
replaceMedia ( $article , pageUrl . toString ( ) ) ;
166
206
167
207
const breadcrumbs = getBreadcrumbs ( $body ) ;
0 commit comments