Skip to content

Commit fab5f6e

Browse files
Merge pull request #8 from nextbitlabs/feat/add-slice-number-and-date
Add slide numbers and date
2 parents 8412c55 + c116cb0 commit fab5f6e

File tree

3 files changed

+73
-9
lines changed

3 files changed

+73
-9
lines changed

index.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ const cli = meow({
4444
${chalk.bold('OPTIONS')}
4545
4646
${chalk.bold('-n')} or ${chalk.bold('--name')} ${chalk.italic('directory_name')}
47-
Specify the name of the directory where the project is initialized. Defaults to ${chalk.underline('onepunch-presentation')}.
47+
Specify the name of the directory where the project is initialized.
48+
Defaults to ${chalk.underline('onepunch-presentation')}.
4849
4950
${chalk.bold('-i')} or ${chalk.bold('--input')} ${chalk.italic('htmlfile')}
5051
Specify the HTML file to serve or print, defaults to ${chalk.underline('index.html')}.
@@ -58,6 +59,29 @@ const cli = meow({
5859
${chalk.bold('--help')}
5960
Display the documentation.
6061
62+
${chalk.bold('FILES')}
63+
64+
File ${chalk.underline('onepunch.json')} defines config settings as key-value pairs in JSON format.
65+
The following keys are provided:
66+
67+
${chalk.bold('width')}: <Number>
68+
Describe the slide width in pixels, defaults to 960.
69+
70+
${chalk.bold('height')}: <Number>
71+
Describe the slide height in pixels, defaults to 600.
72+
73+
${chalk.bold('progress')}: <String>
74+
Describe the presentation progress. At the moment only values "line"
75+
and "none" are supported.
76+
77+
${chalk.bold('date')}: <String>
78+
Define the text content of HTML elements with data attribute
79+
data-onepunch="date", such as <span data-onepunch="date"></span>.
80+
81+
${chalk.bold('slideNumber')}: <Boolean>
82+
If true, show the slide number in HTML elements with data attribute
83+
data-onepunch="slide-number", such as <span data-onepunch="slide-number"></span>.
84+
6185
${chalk.bold('LICENSE')}
6286
6387
Copyright 2020 Nextbit <[email protected]> (https://nextbit.it/)

template/onepunch.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"width": 960,
33
"height": 600,
4-
"progress": "line"
4+
"progress": "line",
5+
"date": "",
6+
"slideNumber": false
57
}

template/src/index.js

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
};
99

1010
/*
11-
Get configuration parameters and initialize the web page;
11+
Get configuration parameters and initialize the web page.
1212
*/
1313

1414
(async function () {
@@ -18,17 +18,19 @@
1818
})();
1919

2020
/*
21-
Initialize services
21+
Initialize services.
2222
*/
2323

2424
function init(config) {
2525
addEventListeners(config);
2626
setBorders(config.width, config.height);
2727
addProgress(config);
28+
addSlideNumber(config);
29+
addDate(config);
2830
}
2931

3032
/*
31-
Add event listeners
33+
Add event listeners.
3234
*/
3335

3436
function addEventListeners(config) {
@@ -46,7 +48,7 @@
4648
}
4749

4850
/*
49-
Set article borders
51+
Set article borders.
5052
*/
5153

5254
function setBorders(width, height) {
@@ -59,7 +61,7 @@
5961
}
6062

6163
/*
62-
Change slide with arrow keys
64+
Change slide with arrow keys.
6365
*/
6466

6567
function handleOnkeydown(event) {
@@ -84,7 +86,7 @@
8486
}
8587

8688
/*
87-
Add progress to each slide based on config
89+
Add progress to each slide based on config.
8890
*/
8991

9092
function addProgress(config) {
@@ -149,10 +151,46 @@
149151
}
150152

151153
/*
152-
Return the list of slides
154+
Return the list of slides.
153155
*/
154156

155157
function getSlides() {
156158
return [...document.querySelectorAll('main > article')];
157159
}
160+
161+
/*
162+
Add slide numbers.
163+
*/
164+
165+
function addSlideNumber(config) {
166+
const slides = getSlides();
167+
slides.forEach((slide, index) => {
168+
const el = slide.querySelector('[data-onepunch="slide-number"]');
169+
if (el) {
170+
if (config.slideNumber) {
171+
el.textContent = index + 1;
172+
} else {
173+
el.style.display = 'none';
174+
}
175+
}
176+
});
177+
}
178+
179+
/*
180+
Add date.
181+
*/
182+
183+
function addDate(config) {
184+
const slides = getSlides();
185+
slides.forEach(slide => {
186+
const el = slide.querySelector('[data-onepunch="date"]');
187+
if (el) {
188+
if (config.date) {
189+
el.textContent = config.date;
190+
} else {
191+
el.style.display = 'none';
192+
}
193+
}
194+
});
195+
}
158196
})();

0 commit comments

Comments
 (0)