Skip to content

Commit ae610d7

Browse files
authored
Always show an ad even if there are no page subheadings (#299)
See the 'sidebar' section for pages that show the following examples: - A page with no headings, and no ad - A page with no headings, but there is an ad - A page with headings, but there's no ad - A page with both headings and an ad
1 parent 356e625 commit ae610d7

File tree

6 files changed

+63
-5
lines changed

6 files changed

+63
-5
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
= Page with ad and subheadings
2+
:page-ad-icon: mortarboard
3+
:page-ad-title: Free, Hands-on training with Neo4j GraphAcademy
4+
:page-ad-description: We're here to guide you on a fun and engaging journey to mastering Neo4j with free, hands-on courses.
5+
:page-ad-link: https://graphacademy.neo4j.com/?ref=promo-generic
6+
:page-ad-underline-role: button
7+
:page-ad-underline: Enroll now
8+
9+
10+
== Section 1
11+
This page has subheadings, so `toc-menu` is generated.
12+
13+
== Section 2
14+
This page also has an ad, which should be displayed below the page contents.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
= Page with subheadings but no ad
2+
3+
4+
== Section 1
5+
This page has subheadings, so page contents is displayed.
6+
7+
== Section 2
8+
There is no ad for this page.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
= Page with ad and no subheadings
2+
:page-ad-icon: mortarboard
3+
:page-ad-title: Free, Hands-on training with Neo4j GraphAcademy
4+
:page-ad-description: We're here to guide you on a fun and engaging journey to mastering Neo4j with free, hands-on courses.
5+
:page-ad-link: https://graphacademy.neo4j.com/?ref=promo-generic
6+
:page-ad-underline-role: button
7+
:page-ad-underline: Enroll now
8+
9+
This page has no subheadings.
10+
11+
But we still want the `toc-ad` to be displayed.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
= Page with no subheadings and no ad
2+
3+
This page has no subheadings.
4+
5+
It has no ad to display so there should be no `<aside class="toc sidebar">...</aside>` in the HTML.

preview-src/ui-model.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ page:
164164
- content: warning
165165
url: banner-warning.html
166166
urlType: internal
167+
- content: Sidebar
168+
items:
169+
- content: No headings, no ad
170+
url: sidebar-no-headings-no-ad.html
171+
urlType: internal
172+
- content: No headings, with ad
173+
url: sidebar-no-headings-ad.html
174+
urlType: internal
175+
- content: Headings, no ad
176+
url: sidebar-headings-no-ad.html
177+
urlType: internal
178+
- content: Headings, with ad
179+
url: sidebar-headings-ad.html
180+
urlType: internal
167181
- content: Labels
168182
url: labels.html
169183
urlType: internal

src/js/02-on-this-page.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,19 @@
1111
var article = document.querySelector('article.doc')
1212
var selectors = document.querySelector('.nav-container .selectors')
1313
var selectorsHeight = selectors ? selectors.getBoundingClientRect().height : 0
14-
var headings
1514
var headingSelector = []
1615
for (var l = 0; l <= levels; l++) headingSelector.push(l ? '.sect' + l + '>h' + (l + 1) + '[id]' : 'h1[id].sect0')
17-
if (!(headings = find(headingSelector.join(','), article)).length) return sidebar.parentNode.removeChild(sidebar) // remove sidebar if there are no headings
16+
var headings = find(headingSelector.join(','), article)
17+
18+
var menu = sidebar.querySelector('.toc-menu-placeholder')
19+
if (!menu) (menu = document.createElement('div')).className = 'toc-menu-placeholder'
20+
var ad = document.querySelector('.toc-ad')
21+
22+
// display an ad or nothing if there are no headings
23+
if (!(headings.length)) {
24+
if (!ad) return sidebar.parentNode.removeChild(sidebar) // remove sidebar if there is no ad
25+
return menu.parentNode.removeChild(menu) // remove toc menu if there are no headings but still display ad
26+
}
1827

1928
var lastActiveFragment
2029
var links = {}
@@ -29,9 +38,6 @@
2938
return accum
3039
}, document.createElement('ul'))
3140

32-
var menu = sidebar.querySelector('.toc-menu-placeholder')
33-
if (!menu) (menu = document.createElement('div')).className = 'toc-menu-placeholder'
34-
3541
if (document.querySelector('body.has-banner')) {
3642
document.querySelector('.toc-menu').style.top = 'calc(var(--toc-top) + var(--banner-height))'
3743
}

0 commit comments

Comments
 (0)