@@ -19,7 +19,11 @@ const { JSDOM } = jsdom;
1919const fs = require ( 'fs' ) ;
2020const ensureDir = require ( './ensureDir' ) ;
2121
22- const fetch = import ( 'node-fetch' ) ;
22+ const wwwSelectors = {
23+ content : '[class^="Layout"] > *, [class*=" Layout"] > *' ,
24+ header : 'nav, [class^="Header"], [class*=" Header"]' ,
25+ footer : 'footer, [class^="Footer"], [class*=" Footer"], #footer' ,
26+ } ;
2327
2428const baseHtml = async mode => {
2529 // Support a blank template for completely local dev
@@ -38,13 +42,13 @@ const baseHtml = async mode => {
3842
3943 // Support developing a tool for WWW
4044 if ( mode === 'www' ) {
41- const res = await fetch . then ( ( { default : run } ) => run ( 'https://www.digitalocean.com' ) ) ;
45+ const res = await fetch ( 'https://www.digitalocean.com' ) ;
4246 return await res . text ( ) ;
4347 }
4448
4549 // Default to a tool for Community tooling
4650 if ( mode === 'community' ) {
47- const res = await fetch . then ( ( { default : run } ) => run ( 'https://www.digitalocean.com/community' ) ) ;
51+ const res = await fetch ( 'https://www.digitalocean.com/community' ) ;
4852 return await res . text ( ) ;
4953 }
5054
@@ -105,17 +109,22 @@ module.exports = async () => {
105109 document . head . insertBefore ( charset , document . head . firstChild ) ;
106110 }
107111
112+ let contentAnchor ;
108113 if ( mode === 'www' || mode === 'community' ) {
109114 // Remove nav log in + sign up buttons
110- document . querySelectorAll ( 'nav li' ) . forEach ( node => {
115+ document . querySelectorAll ( 'header li' ) . forEach ( node => {
111116 if ( node . textContent . toLowerCase ( ) . includes ( 'log in' ) ) node . remove ( ) ;
112117 if ( node . textContent . toLowerCase ( ) . includes ( 'sign up' ) ) node . remove ( ) ;
113118 } ) ;
114119
115120 // Remove www + community content
116- document . querySelectorAll ( 'div[class^="Layout"] > *' ) . forEach ( node => {
117- if ( node . querySelector ( 'nav, [class^="Header"], [class*=" Header"]' ) ) return ;
118- if ( node . querySelector ( 'footer, [class^="Footer"], [class*=" Footer"]' ) ) return ;
121+ document . querySelectorAll ( wwwSelectors . content ) . forEach ( node => {
122+ if ( node . querySelector ( wwwSelectors . header ) ) return ;
123+ if ( node . querySelector ( wwwSelectors . footer ) ) return ;
124+
125+ // If this is the first content node on the page,
126+ // we'll inject the content block where it is
127+ if ( ! contentAnchor ) contentAnchor = node . previousElementSibling ;
119128 node . remove ( ) ;
120129 } ) ;
121130 }
@@ -127,7 +136,7 @@ module.exports = async () => {
127136 document . querySelector ( 'body > .app' ) . appendChild ( content ) ;
128137 }
129138 if ( mode === 'www' || mode === 'community' ) {
130- document . querySelector ( 'nav' ) . parentElement . insertAdjacentElement ( 'afterend' , content ) ;
139+ contentAnchor . insertAdjacentElement ( 'afterend' , content ) ;
131140 }
132141
133142 // Inject the title block
0 commit comments