Skip to content

Commit 4d69a1b

Browse files
authored
Full role handling (#261)
Properly handles roles with product names and versions - `label--beta-until-bolt-1.0` - `label--beta-until-1.0` Also allows for `page-product` attribute to be used in labels. If `:page-product: Neo4j`, for example, `label--new-5.22` is displayed as 'New in Neo4j 5.22'
1 parent 71b79b8 commit 4d69a1b

File tree

4 files changed

+71
-23
lines changed

4 files changed

+71
-23
lines changed

preview-src/docs-roles.adoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,36 @@
55
:page-banner-text: Lorem ipsum dolor sit est.
66
:page-banner-link: https://neo4j.com/docs
77
:page-banner-link-text: Link text
8+
:page-product: Neo4j
89
// :page-labels: fabric enterprise-edition alpha test
910

1011
[abstract]
1112
--
1213
Flags sections as Not Available on Aura, Aura DB Enterprise, Enterprise Edition, Fabric, and Deprecated
1314
--
1415

16+
This page has the `:page-product:` attribute set to `Neo4j`.
17+
By default, labels that related to a version of a product have `Neo4j` prepended to the version number.
18+
19+
For example, `label--beta-until-5.12` is displayed as `Beta until Neo4j 5.12`.
20+
21+
To override this value, include the product name in the label.
22+
For example, `label--beta-until-bolt-1.0` is displayed as `Beta until Bolt 1.0`.
23+
24+
[role=test-role]
25+
Paragraph with non-label role.
26+
27+
28+
[role=label--beta-until-bolt-1.0 label--removed-2.0]
29+
== Adding a product name to versioned labels
30+
31+
32+
[role=label--beta-until-1.0 label--dynamic-5.22 label--dynamic]
33+
[[messages-ack-failure]]
34+
=== Request message `ACK_FAILURE`
35+
36+
The request message `ACK_FAILURE` signals to the server that the client has acknowledged a previous failure and should return to a `READY` state.
37+
1538

1639
[role=label--new-5.11 label--beta-until-5.12]
1740
== Beta until

src/js/60-docs-roles.js

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ function checkWrapped () {
1515
}
1616

1717
document.addEventListener('DOMContentLoaded', function () {
18+
const contentDataset = document.querySelector('article.doc').dataset
19+
1820
var camelCased = function (str) {
1921
return str.split(/-|\./)
2022
.map((text) => text.substr(0, 1).toUpperCase() + text.substr(1))
@@ -34,32 +36,53 @@ document.addEventListener('DOMContentLoaded', function () {
3436

3537
// so if the role is a single word, we use the role as is - ie deprecated
3638
// if it is longer we test to see if it is a 'versionable' roke - ie deprecated-5.20
37-
// if it is a versionable role, and a veresion is specified, we remove the version and use the remaining text as the label class
38-
if (labelParts.length > 1) {
39-
label = (rolesData[label] && rolesData[label].labelCategory !== 'version') ? label : labelParts.slice(0, -1).join('-')
39+
// if it is a versionable role, and a version is specified, we remove the version and use the remaining text as the label class
40+
// if (labelParts.length > 1) {
41+
// label = (rolesData[label] && rolesData[label].labelCategory !== 'version') ? label : labelParts.slice(0, -1).join('-')
42+
// }
43+
44+
let dataLabel, dataProduct, dataVersion
45+
const dataExtras = []
46+
47+
// what about roles like new-bolt-5.20 if we want to use a product name in the label?
48+
while (!dataLabel && labelParts.length > 0) {
49+
const labelCandidate = labelParts.join('-')
50+
if (rolesData[labelCandidate]) {
51+
dataLabel = labelCandidate
52+
} else {
53+
dataExtras.push(labelParts.pop())
54+
}
4055
}
4156

4257
// ignore labels that are not defined in rolesData
43-
if (!rolesData[label]) {
58+
if (!dataLabel) {
4459
return
4560
}
4661

62+
if (dataExtras.length > 0) {
63+
dataVersion = dataExtras.shift()
64+
}
65+
66+
if (dataExtras.length > 0) {
67+
dataProduct = camelCased(dataExtras.join(' '))
68+
}
69+
4770
var labelDetails = {
48-
class: label,
49-
role: label,
50-
text: rolesData[label].displayText || '',
71+
class: dataLabel,
72+
role: dataLabel,
73+
text: rolesData[dataLabel].displayText || '',
74+
joinText: dataVersion ? rolesData[dataLabel].joinText || 'in' : '',
5175
data: {
52-
labelCategory: rolesData[label].labelCategory || '',
53-
product: rolesData[label].product || '',
54-
function: rolesData[label].function || '',
76+
product: dataVersion ? dataProduct || rolesData[dataLabel].product || contentDataset.product || '' : '',
77+
version: dataVersion || '',
78+
function: rolesData[dataLabel].function || '',
79+
event: rolesData[dataLabel].labelCategory === 'version' ? dataLabel : '',
5580
},
5681
}
5782

58-
// get version number for version labels
59-
if ((rolesData[label].labelCategory === 'version' || rolesData[label].versionText) && labelParts[1]) {
60-
labelDetails.data.version = labelParts.pop()
61-
const joinText = rolesData[label].versionText ? rolesData[label].versionText : 'in'
62-
labelDetails.text = [labelDetails.text, joinText, labelDetails.data.version].join(' ')
83+
// update label text for versioned labels
84+
if ((rolesData[dataLabel].labelCategory === 'version' || (rolesData[dataLabel].joinText && dataVersion))) {
85+
labelDetails.text = [labelDetails.text, labelDetails.joinText, labelDetails.data.product, labelDetails.data.version].join(' ')
6386
}
6487

6588
return labelDetails
@@ -104,9 +127,9 @@ document.addEventListener('DOMContentLoaded', function () {
104127
const labelSpan = createElement('span', `label content-label label--${labelDetails.class}`)
105128

106129
// add dataset to the label
107-
if (labelDetails.data.version) labelSpan.dataset.version = labelDetails.data.version
108-
if (labelDetails.data.product !== '') labelSpan.dataset.product = labelDetails.data.product
109-
if (labelDetails.data.function !== '') labelSpan.dataset.function = labelDetails.data.function
130+
for (var d in labelDetails.data) {
131+
if (labelDetails.data[d] !== '') labelSpan.dataset[d] = labelDetails.data[d]
132+
}
110133

111134
labelSpan.appendChild(document.createTextNode(labelDetails.text))
112135

@@ -125,8 +148,10 @@ document.addEventListener('DOMContentLoaded', function () {
125148
label.classList.add('header-label')
126149
}
127150
labelsDiv.append(label)
128-
const contentLabel = Array.from(label.classList).find((c) => c.startsWith('label--')).replace('label--', '')
129-
roleDiv.dataset[camelCased(contentLabel)] = contentLabel
151+
152+
for (var d in label.dataset) {
153+
roleDiv.dataset[d] = label.dataset[d]
154+
}
130155
}
131156

132157
if (roleDiv.nodeName === 'H1' || headings.includes(roleDiv.firstElementChild.nodeName)) {

src/js/data/rolesData.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
"dynamic":{
131131
"labelCategory": "function",
132132
"displayText": "Dynamic",
133-
"versionText": "since"
133+
"joinText": "since"
134134
},
135135
"alpha":{
136136
"labelCategory": "version",
@@ -144,7 +144,7 @@
144144
"description": "The feature or function was in beta until the version specified",
145145
"labelCategory": "version",
146146
"displayText": "Beta",
147-
"versionText": "until"
147+
"joinText": "until"
148148
},
149149
"deprecated":{
150150
"labelCategory": "version",

src/partials/article.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div id="skip-to-content"></div>
2-
<article class="doc">
2+
<article class="doc"{{#with page.attributes.product}} data-product="{{this}}"{{/with}}>
33
{{#if (eq page.layout '404')}}
44
<h1 class="page">{{{or page.title 'Page Not Found'}}}</h1>
55
<div class="paragraph">

0 commit comments

Comments
 (0)