@@ -3,28 +3,29 @@ type IndexTemplateOptions = {
33 usesMarkdown : boolean ;
44} ;
55
6- const tsxImports = `
7- import { Deck, DefaultTemplate, Slide, FlexBox, Heading, SpectacleLogo } from 'spectacle';
8- ` ;
6+ const content = {
7+ reactImports ( ) {
8+ return `
9+ import React from 'react';
10+ import { createRoot } from 'react-dom/client';
11+ import { Deck, DefaultTemplate, Slide, FlexBox, Heading, SpectacleLogo } from 'spectacle'
12+ ` ;
13+ } ,
914
10- const mdImports = `
15+ mdImports ( ) {
16+ return `
17+ import React from 'react';
18+ import { createRoot } from 'react-dom/client';
1119import { Deck, DefaultTemplate, MarkdownSlideSet } from 'spectacle';
1220import mdContent from './slides.md';
13- ` ;
14-
15- export const indexTemplate = ( options : IndexTemplateOptions ) =>
16- `import React from 'react';
17- import { createRoot } from 'react-dom/client';
18- ${ ( options . usesMarkdown ? mdImports : tsxImports ) . trim ( ) }
21+ ` ;
22+ } ,
1923
20- const Presentation = () => (
21- <Deck template={() => <DefaultTemplate />}>
22- ${ ( options . usesMarkdown
23- ? `<MarkdownSlideSet>{mdContent}</MarkdownSlideSet>`
24- : `
24+ reactBody ( name : string ) {
25+ return `
2526 <Slide>
2627 <FlexBox height="100%">
27- <Heading>${ options . name } </Heading>
28+ <Heading>${ name } </Heading>
2829 </FlexBox>
2930 </Slide>
3031 <Slide>
@@ -34,9 +35,38 @@ const Presentation = () => (
3435 </FlexBox>
3536 </Slide>
3637 `
37- ) . trim ( ) }
38+ . substring ( 1 )
39+ . trim ( ) ;
40+ } ,
41+
42+ mdBody ( ) {
43+ return `
44+ <MarkdownSlideSet>{mdContent}</MarkdownSlideSet>
45+ `
46+ . substring ( 1 )
47+ . trim ( ) ;
48+ }
49+ } ;
50+
51+ export const indexTemplate = ( options : IndexTemplateOptions ) =>
52+ `
53+ ${ ( ( ) => {
54+ if ( options . usesMarkdown ) {
55+ return content . mdImports ( ) ;
56+ }
57+ return content . reactImports ( ) ;
58+ } ) ( ) . trim ( ) }
59+
60+ const Presentation = () => (
61+ <Deck template={() => <DefaultTemplate />}>
62+ ${ ( ( ) => {
63+ if ( options . usesMarkdown ) {
64+ return content . mdBody ( ) ;
65+ }
66+ return content . reactBody ( options . name ) ;
67+ } ) ( ) }
3868 </Deck>
3969);
4070
4171createRoot(document.getElementById('app')!).render(<Presentation />);
42- ` ;
72+ ` . trim ( ) ;
0 commit comments