diff --git a/demo/scripts/slides.js b/demo/scripts/slides.js
index f8b8fb2..39af790 100644
--- a/demo/scripts/slides.js
+++ b/demo/scripts/slides.js
@@ -10,13 +10,15 @@ console.log('Reveal version', Reveal.VERSION);
console.log('Reveal instance', Reveal);
// One method per module
-function schoolSlides() {
+function schoolSlides(showType) {
const dir = '01-classics';
return [
'00_intro.md',
`${dir}/10_chapter1.md`,
`${dir}/20_transitions.md`,
- `${dir}/30_code_slides.md`,
+ !showType || showType === 'custom'
+ ? undefined
+ : `${dir}/30_code_slides.md`,
`${dir}/40_custom_bg_slides.md`,
];
}
@@ -53,17 +55,19 @@ function toolsSlides() {
];
}
-function formation() {
+function formation(showType) {
return [
//
...schoolSlides(),
- ...speakerSlides(),
- ...layoutsSlides(),
- ...helpersSlides(),
- ...toolsSlides(),
- ].map((slidePath) => {
- return { path: slidePath };
- });
+ ...(!showType || showType === 'speakers' ? speakerSlides() : []),
+ ...(!showType || showType === 'layouts' ? layoutsSlides() : []),
+ ...(!showType || showType === 'helpers' ? helpersSlides() : []),
+ ...(!showType || showType === 'tools' ? toolsSlides() : []),
+ ]
+ .filter((element) => element !== undefined)
+ .map((slidePath) => {
+ return { path: slidePath };
+ });
}
await ThemeInitializer.init({
diff --git a/src/addons/tc-data-type.spec.ts b/src/addons/tc-data-type.spec.ts
index 84c1a72..f4f781f 100644
--- a/src/addons/tc-data-type.spec.ts
+++ b/src/addons/tc-data-type.spec.ts
@@ -1,9 +1,23 @@
/**
* @vitest-environment jsdom
*/
-import { beforeEach, describe, expect, it } from 'vitest';
+import { afterAll, beforeEach, describe, expect, it } from 'vitest';
+import { getShowType, manageShowTypeContent } from './tc-data-type';
+import { DEFAULT_TYPE } from '../utils/const';
-import { manageShowTypeContent } from './tc-data-type';
+// Mock window.location
+const mockLocation = {
+ search: '',
+ href: '',
+ origin: 'http://localhost',
+ pathname: '/',
+ hash: '',
+};
+
+Object.defineProperty(window, 'location', {
+ value: mockLocation,
+ writable: true,
+});
const HTML = `
@@ -30,6 +44,34 @@ const HTML = `
`;
+describe(getShowType.name, () => {
+ afterAll(async () => {
+ window.location.search = '';
+ });
+ it('should use default type if nothing is specified', () => {
+ document.body.innerHTML = ``;
+ const type = getShowType();
+ expect(type).toBe(DEFAULT_TYPE);
+ });
+ it('should use type if specified in HTML', () => {
+ document.body.innerHTML = ``;
+ const type = getShowType();
+ expect(type).toBe('test');
+ });
+
+ it('should use type if specified in URL', () => {
+ window.location.search = 'data-type=test2';
+ document.body.innerHTML = ``;
+ const type = getShowType();
+ expect(type).toBe('test2');
+ });
+});
describe(manageShowTypeContent.name, () => {
beforeEach(async () => {
document.body.innerHTML = HTML;
diff --git a/src/addons/tc-data-type.ts b/src/addons/tc-data-type.ts
index d2e1df7..2bd0386 100644
--- a/src/addons/tc-data-type.ts
+++ b/src/addons/tc-data-type.ts
@@ -1,21 +1,27 @@
import { DEFAULT_TYPE } from '../utils/const';
import { _handle_parameter } from '../utils/helper';
-export function manageShowTypeContent(
- defaultType: string = DEFAULT_TYPE
-): void {
+export function getShowType(defaultType: string = DEFAULT_TYPE): string {
const urlParams = new URLSearchParams(window.location.search);
const slidesElement: HTMLElement =
document.querySelector('.reveal .slides')!;
- const slidesType = _handle_parameter(
+ return _handle_parameter(
urlParams,
'data-type',
slidesElement,
'data-type',
defaultType
);
+}
+
+export function manageShowTypeContent(
+ defaultType: string = DEFAULT_TYPE
+): void {
+ const slidesType = getShowType(defaultType);
if (slidesType !== 'all') {
+ const slidesElement: HTMLElement =
+ document.querySelector('.reveal .slides')!;
Array.from(slidesElement.querySelectorAll('section[data-type-show]'))
.filter(
(el) =>
diff --git a/src/theme-initializer.spec.ts b/src/theme-initializer.spec.ts
index 05460e8..8abec52 100644
--- a/src/theme-initializer.spec.ts
+++ b/src/theme-initializer.spec.ts
@@ -2,10 +2,10 @@
* @vitest-environment jsdom
*/
import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { DEFAULT_TYPE } from './utils/const';
import Reveal from 'reveal.js';
import { ThemeInitializer } from './theme-initializer';
import { render } from 'lit-html';
-
// Mocks
vi.mock('reveal.js', () => ({
default: {
@@ -56,6 +56,10 @@ vi.mock('./utils/storage-service', () => ({
]),
}));
+vi.mock('./addons/tc-data-type', () => ({
+ getShowType: vi.fn().mockImplementation(() => DEFAULT_TYPE),
+}));
+
vi.mock('./addons/tc-ui-config');
// Get a representation of this mock class
diff --git a/src/theme-initializer.ts b/src/theme-initializer.ts
index 4221563..99356fb 100644
--- a/src/theme-initializer.ts
+++ b/src/theme-initializer.ts
@@ -16,13 +16,14 @@ import { SlidePath } from './models';
import { TcCustomBackgroundOptions } from './addons/tc-custom-background';
import { TcThemeOptions } from './addons/tc-theme';
import { TcUiConfig } from './addons/tc-ui-config';
+import { getShowType } from './addons/tc-data-type';
import { getSlidesToUse } from './utils/storage-service';
/**
*
*/
export interface ThemeInitializerOptions {
- slidesFactory: () => SlidePath[]; // Function to retrieve the slides informations
+ slidesFactory: (showType?: string) => SlidePath[]; // Function to retrieve the slides informations
activeCopyClipboard?: boolean; // Default applied is true
tcMarkedOptions: TalkControlMarkedOptions; // Deal with the font icons
tcI18nOptions: TcI18nConfig; // Deal with the i18n options
@@ -50,8 +51,11 @@ export const ThemeInitializer = {
document.querySelector('.slides');
if (importSlideElement == null) return;
+ // Retrieve the data type parameter to apply to a subset of slides
+ const showType = getShowType(defaultSlidesType);
+
// Retrieve the slide path list
- const slides = slidesFactory();
+ const slides = slidesFactory(showType);
// Init the uiConfig
new TcUiConfig(