-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Some minor styling tweaks in mobile (lesser padding) - Lazily load the routes to keep package size small - Prepare for markdown-powered documentation pages in the secret `/manual` route. This also is the reason for the `config-overrides.js` file being pulled in; CRA by default wants to load `.md` files using `file-loader`, but that would require a client-side http request to load in the markdown file. I want the markdown file to be baked into the page so the resulting react component can be built synchronously.
- Loading branch information
Showing
16 changed files
with
5,609 additions
and
3,460 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = (webpackConfig) => { | ||
const { rules } = webpackConfig.module | ||
|
||
// I want to be able to import markdown files as strings, to avoid fetching them dynamically. To accomplish | ||
// this, I need to override the default webpack config and load .md files using `raw-loader`, rather than the | ||
// previously-used `file-loader`. | ||
rules.push({ | ||
test: /\.md$/, | ||
use: 'raw-loader' | ||
}) | ||
const catchall = rules[rules.length - 2] | ||
const fileLoaderConfig = catchall.oneOf.find(({ loader }) => loader?.includes('file-loader')) | ||
fileLoaderConfig.exclude.push(/\.md$/) | ||
|
||
return webpackConfig | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
declare module 'remark-react' { | ||
import { Plugin } from 'unified' | ||
|
||
type RemarkReactOptions = any | ||
interface RemarkReact extends Plugin<[RemarkReactOptions?]> {} | ||
|
||
declare const remarkReact: RemarkReact | ||
export = remarkReact | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
declare module 'remark-slug' { | ||
import { Plugin } from 'unified' | ||
|
||
type RemarkSlugOptions = any | ||
interface RemarkSlug extends Plugin<[RemarkSlugOptions?]> {} | ||
|
||
declare const remarkSlug: RemarkSlug | ||
export = remarkSlug | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react' | ||
import unified from 'unified' | ||
import parse from 'remark-parse' | ||
import remarkSlug from 'remark-slug' | ||
import remark2react from 'remark-react' | ||
import Code from './Code' | ||
|
||
export function renderMarkdownToReact(markdown: string) { | ||
const markdownResult: any = unified() | ||
.use(parse) | ||
.use(remarkSlug) | ||
.use(remark2react, { | ||
remarkReactComponents: { code: Code }, | ||
sanitize: { clobberPrefix: '' } | ||
}) | ||
.processSync(markdown) | ||
return markdownResult.result | ||
} | ||
|
||
interface Props { | ||
contents: string | ||
} | ||
|
||
export default function MarkdownArticle({ contents }: Props) { | ||
const rendered = renderMarkdownToReact(contents) | ||
|
||
return ( | ||
<div style={{ display: 'flex', flexDirection: 'row' }}> | ||
<div style={{ flex: 1 }}> | ||
{rendered} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.