Skip to content

Commit

Permalink
feat(client): enable mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Jun 16, 2019
1 parent 1db5281 commit 8781843
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 138 deletions.
35 changes: 28 additions & 7 deletions src/client/src/components/AppContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { MdMenu } from 'react-icons/md';
import { Loader } from './Loader';
import { Base } from './ContentView/Base';
import { router } from '../router';
import { createHtmlSlides } from '../utils/createHtmlSlides';
import { setup as setupWebSlides } from '../setup/webSlides';
import { ToC } from './ToC';

export class AppContainer extends React.Component {
constructor(props) {
Expand All @@ -27,10 +27,31 @@ export class AppContainer extends React.Component {
}
};

const { slides, contentsList } = createHtmlSlides(props.slides);
this.slides = slides;
{
const slidesArr = props.slides.map((s) => s.slides).flat();
const propsArr = props.slides.map((s) => s.fusumaProps).flat();

propsArr.reduce((acc, { sectionTitle }, i) => {
if (sectionTitle) {
acc.push({
title: sectionTitle,
index: i + 1
});
}
return acc;
}, (this.contentsList = []));

this.slides = slidesArr.map((slide, i) => {
const props = propsArr[i];

return {
slide: props.contents ? ToC({ list: this.contentsList }) : slide,
fusumaProps: props
};
});
}

this.params = parsedUrl.searchParams;
this.contentsList = contentsList;
this.ContentComponent = null;

this.routeMode();
Expand All @@ -42,9 +63,9 @@ export class AppContainer extends React.Component {

async componentDidMount() {
if (this.state.isSidebar) {
const {
SidebarComponent
} = await import(/* webpackChunkName: 'Sidebar', webpackPrefetch: true */ './Sidebar');
const { SidebarComponent } = await import(
/* webpackChunkName: 'Sidebar', webpackPrefetch: true */ './Sidebar'
);

this.setState({ SidebarComponent });
}
Expand Down
20 changes: 10 additions & 10 deletions src/client/src/components/ContentView/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ export class Base extends React.PureComponent {
currentIndex,
className = undefined,
// showIndex(webSlides) checks all slides so lazyload can not be used together
lazyload = !process.env.SHOW_INDEX
lazyload = !process.env.SHOW_INDEX // TODO: fix
} = this.props;
const articleClass = process.env.IS_VERTICAL ? classnames('vertical', className) : className;

return (
<article className={articleClass} id="webslides">
{slides.map((slide, i) => (
{slides.map(({ slide: Slide, fusumaProps }, i) => (
<section
key={i /* fix */}
className={slide.meta.className}
dangerouslySetInnerHTML={{
__html:
(currentIndex >= i - 5 && currentIndex <= i + 5) || !lazyload
? slide.context
: '<div />'
}}
/>
className={classnames(
'aligncenter',
fusumaProps.className,
fusumaProps.sectionTitle ? 'section-title' : undefined
)}
>
<Slide />
</section>
))}
</article>
);
Expand Down
16 changes: 16 additions & 0 deletions src/client/src/components/ToC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';

export const ToC = ({ list }) => () => (
<div class="toc size-70 aligncenter">
<ol>
{list.map(({ index, title }, i) => (
<li key={i /* fix */}>
<a href={`#slide=${index}`} title={title}>
<span class="chapter">{title}</span>
<span class="toc-page">{index}</span>
</a>
</li>
))}
</ol>
</div>
);
4 changes: 3 additions & 1 deletion src/client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import './setup/css';
// navigator.serviceWorker.register('/service-worker.js');
// }

import * as React from 'react';

(async () => {
const slidesInfo = fetchSlides(require.context(process.env.SLIDE_PATH, false, /\.md$/));
const slidesInfo = fetchSlides(require.context(process.env.SLIDE_PATH, false, /\.mdx?$/));

createBody(slidesInfo.slides);

Expand Down
68 changes: 0 additions & 68 deletions src/client/src/utils/createHtmlSlides.js

This file was deleted.

52 changes: 0 additions & 52 deletions src/client/src/utils/parseAttrs.js

This file was deleted.

0 comments on commit 8781843

Please sign in to comment.