Skip to content

Commit

Permalink
feat(docz-core): use html template as component
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jun 9, 2018
1 parent 2fbedd3 commit b7a2dc0
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 189 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"devDependencies": {
"del": "^3.0.0",
"lerna": "^2.11.0",
"libundler": "^1.6.4",
"libundler": "^1.7.0",
"npm-run-all": "^4.1.3",
"prettier": "^1.13.5",
"trash-cli": "^1.4.0",
Expand Down
1 change: 1 addition & 0 deletions packages/docz-core/librc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
'react-dev-utils/FileSizeReporter',
'react-dev-utils/formatWebpackMessages',
'react-dev-utils/printBuildError',
'react-dom/server',
]),
plugins: [
copy([
Expand Down
4 changes: 4 additions & 0 deletions packages/docz-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
"load-cfg": "^0.1.2-beta.0",
"lodash.get": "^4.4.2",
"prettier": "^1.13.5",
"react": "^16.4.0",
"react-dev-utils": "^5.0.1",
"react-docgen-typescript-loader": "^2.1.0",
"react-dom": "^16.4.0",
"react-hot-loader": "4.3.0",
"remark-frontmatter": "^1.2.0",
"remark-parse": "^5.0.0",
Expand Down Expand Up @@ -88,6 +90,8 @@
"@types/lodash.get": "^4.4.3",
"@types/node": "10.3.2",
"@types/prettier": "^1.13.0",
"@types/react": "^16.3.17",
"@types/react-dom": "^16.0.6",
"@types/resolve": "^0.0.8",
"@types/webpack": "^4.4.0",
"@types/webpack-chain": "^4.8.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import * as React from 'react'
import * as fs from 'fs-extra'
import * as glob from 'fast-glob'
import * as path from 'path'
import { renderToString } from 'react-dom/server'

import * as paths from './config/paths'
import { touch, compiled, readIfExist } from './utils/fs'
import { touch, compiled } from './utils/fs'

import { Entry, parseMdx } from './Entry'
import { Plugin } from './Plugin'
import { Config } from './commands/args'
import { Html } from './components/Html'

const fromTemplates = (file: string) => path.join(paths.templates, file)
const fromDocz = (file: string) => path.join(paths.docz, file)

const writeAppFiles = async (config: Config, dev: boolean): Promise<void> => {
const { plugins, title, description, theme } = config
const props = Plugin.propsOfPlugins(plugins)
const html = renderToString(<Html title={title} description={description} />)

const wrappers = props('wrapper')
const onPreRenders = props('onPreRender')
const onPostRenders = props('onPostRender')

const root = await compiled(fromTemplates('root.tpl.js'))
const js = await compiled(fromTemplates('index.tpl.js'))
const html = await compiled(fromTemplates('index.tpl.html'))
const head = await readIfExist(fromDocz('_head.html'))
const scripts = await readIfExist(fromDocz('_scripts.html'))

const rawRootJs = root({
theme,
Expand All @@ -38,16 +38,9 @@ const writeAppFiles = async (config: Config, dev: boolean): Promise<void> => {
onPostRenders,
})

const rawIndexHtml = html({
title,
description,
head: head ? head.trimRight() : '',
scripts: scripts ? scripts.trimRight() : '',
})

await touch(paths.rootJs, rawRootJs)
await touch(paths.indexJs, rawIndexJs)
await touch(paths.indexHtml, rawIndexHtml)
await touch(paths.indexHtml, `<!DOCTYPE html>${html}`)
}

const writeImports = async (map: EntryMap): Promise<void> => {
Expand Down
22 changes: 22 additions & 0 deletions packages/docz-core/src/components/Html.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from 'react'
import { SFC } from 'react'

export interface HtmlProps {
title: string
description: string
}

export const Html: SFC<HtmlProps> = ({ title, description }) => (
<html lang="en">
<head>
<meta charSet="UTF-8" />
<meta name="description" content={description} />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta httpEquiv="X-UA-Compatible" content="ie=edge" />
<title>{title}</title>
</head>
<body>
<div id="root" />
</body>
</html>
)
15 changes: 0 additions & 15 deletions packages/docz-core/templates/index.tpl.html

This file was deleted.

Loading

0 comments on commit b7a2dc0

Please sign in to comment.