Skip to content

Commit

Permalink
Remove imageFactory
Browse files Browse the repository at this point in the history
This is because webpack was not picking up src images properly.
This should be no longer the case once
frontarm/mdx-util#37 is fixed.
  • Loading branch information
helfi92 committed Feb 22, 2019
1 parent e674ca7 commit 6b8a86f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 42 deletions.
2 changes: 1 addition & 1 deletion ui/src/views/Documentation/Image.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { PureComponent } from 'react';
import { string } from 'prop-types';
import { withStyles} from '@material-ui/core/styles';
import { withStyles } from '@material-ui/core/styles';

@withStyles(theme => ({
// Not all images sit nicely on a dark theme (e..g, images with dark text)
Expand Down
12 changes: 9 additions & 3 deletions ui/src/views/Documentation/PageMeta.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export default class PageMeta extends Component {
<ul>
{items.map(([link, text]) => (
<li key={text}>
<AnchorOrLink href={removeReadmeFromPath(link)}>{text}</AnchorOrLink>
<AnchorOrLink href={removeReadmeFromPath(link)}>
{text}
</AnchorOrLink>
</li>
))}
</ul>
Expand Down Expand Up @@ -97,15 +99,19 @@ export default class PageMeta extends Component {
})}>
{hasPreviousPage && (
<PageNavigation
to={removeReadmeFromPath(join(DOCS_PATH_PREFIX, pageInfo.prev.path))}
to={removeReadmeFromPath(
join(DOCS_PATH_PREFIX, pageInfo.prev.path)
)}
variant="prev"
aria-label="Previous Page">
{pageInfo.prev.title}
</PageNavigation>
)}
{hasNextPage && (
<PageNavigation
to={removeReadmeFromPath(join(DOCS_PATH_PREFIX, pageInfo.next.path))}
to={removeReadmeFromPath(
join(DOCS_PATH_PREFIX, pageInfo.next.path)
)}
variant="next"
aria-label="Next Page">
{pageInfo.next.title}
Expand Down
39 changes: 1 addition & 38 deletions ui/src/views/Documentation/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import { withStyles } from '@material-ui/core/styles';
import { lowerCase } from 'change-case';
import path from 'path';
import resolve from 'resolve-pathname';
import catchLinks from 'catch-links';
import 'prismjs';
Expand All @@ -24,9 +23,6 @@ import removeReadmeFromPath from '../../utils/removeReadmeFromPath';
import docsTableOfContents from '../../autogenerated/docs-table-of-contents';
import PageMeta from './PageMeta';

// This is used for images. Relative paths don't seem to work.
let absolutePath = null;

@hot(module)
@withStyles(
theme => ({
Expand All @@ -37,11 +33,6 @@ let absolutePath = null;
background: 'none',
},
},
// Not all images sit nicely on a dark theme (e..g, images with dark text)
imageWrapper: {
textAlign: 'center',
background: theme.palette.type === 'dark' ? '#ffffffcc' : 'none',
},
}),
{ withTheme: true }
)
Expand Down Expand Up @@ -113,30 +104,6 @@ export default class Documentation extends Component {
</HeaderWithAnchor>
);

imageFactory = ({ src, ...props }) => {
const { classes } = this.props;
const currentFileName = path.basename(absolutePath);
const startsWithHttp = src.startsWith('http');
const imgSrc = startsWithHttp
? src
: path.join(
absolutePath.replace(/^\/ui/, '').replace(`/${currentFileName}`, ''),
src
);

// Some local images have black text making it hard to see
// when viewing the page with the dark theme
/* eslint-disable jsx-a11y/alt-text */
return startsWithHttp ? (
<img {...props} src={imgSrc} />
) : (
<div className={classes.imageWrapper}>
<img {...props} src={imgSrc} />
</div>
);
/* eslint-enable jsx-a11y/alt-text */
};

findChildFromRootNode(node) {
const currentPath = window.location.pathname.replace(
`${DOCS_PATH_PREFIX}/`,
Expand Down Expand Up @@ -185,19 +152,15 @@ export default class Documentation extends Component {
h4: this.headingFactory('h4'),
h5: this.headingFactory('h5'),
h6: this.headingFactory('h6'),
img: this.imageFactory,
};
}

async load() {
try {
const { params } = this.props.match;
const pathname = params.path || 'README';
const { loader, path } = readDocFile(`${pathname}.md`);
const { loader } = readDocFile(`${pathname}.md`);
const { default: Page } = await loader;

absolutePath = path;

const pageInfo = this.getPageInfo();

this.setState({ Page, pageInfo, error: null });
Expand Down

0 comments on commit 6b8a86f

Please sign in to comment.