Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,29 @@ module.exports = {
minimize: true,
runtimeChunk: 'single',
splitChunks: {
chunks:'all',
chunks: 'all',
maxSize: 244000,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
priority: 10,
},
common: {
name: 'common',
minChunks: 2,
chunks: 'all',
priority: 5,
reuseExistingChunk: true,
},
data: {
test: /[\\/]src[\\/]data[\\/]/,
name: 'data',
chunks: 'all',
priority: 15,
},
},
},
},
output: {
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"dotenv-expand": "4.2.0",
"front-matter": "^2.3.0",
"fs-extra": "3.0.1",
"gh-pages": "^2.0.1",
"history": "^4.7.2",
"html-truncate": "^1.2.2",
"lodash.foreach": "^4.5.0",
Expand All @@ -44,12 +43,10 @@
"start-js": "NODE_OPTIONS=--openssl-legacy-provider node scripts/start.js",
"start": "npm-run-all -p watch-css start-js",
"serve-build": "yarn run serve -s build",
"build-js": "NODE_OPTIONS=--openssl-legacy-provider node scripts/build.js",
"build-js": "NODE_OPTIONS=\"--openssl-legacy-provider --max-old-space-size=4096\" node scripts/build.js",
"build": "npm-run-all build-css build-js && cp build/index.html build/404.html",
"watch-css": "npm run build-css -- --watch",
"build-css": "sass --load-path ./src --load-path ./node_modules src/:src/ --no-source-map",
"predeploy": "yarn run build",
"deploy": "gh-pages -b master -d build",
"lint": "eslint src",
"test": "node scripts/test.js --env=jsdom",
"storybook": "start-storybook -p 9001 -c .storybook"
Expand Down
137 changes: 71 additions & 66 deletions src/Router/Router.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { Component } from 'react'
import React, { Component, Suspense } from 'react'
import { BrowserRouter, Redirect, Route, Switch } from 'react-router-dom'

import App from 'components/App'
import BlogIndex from 'pages/BlogIndex'
import BlogShow from 'pages/BlogShow'
import Downloads from 'pages/Downloads'
import Home from 'pages/Home'
import NotFound from 'pages/NotFound'
import osqueryVersionsData from 'data/osquery_metadata'
import Schema from 'pages/Schema'

const Home = React.lazy(() => import('pages/Home'))
const BlogIndex = React.lazy(() => import('pages/BlogIndex'))
const BlogShow = React.lazy(() => import('pages/BlogShow'))
const Downloads = React.lazy(() => import('pages/Downloads'))
const Schema = React.lazy(() => import('pages/Schema'))
const NotFound = React.lazy(() => import('pages/NotFound'))

const currentOsqueryVersion = osqueryVersionsData.current_version

Expand All @@ -17,65 +18,69 @@ class Router extends Component {
return (
<BrowserRouter>
<App>
<Switch>
<Route exact path={`${process.env.PUBLIC_URL}/`} component={Home} />
<Route
exact
path={`${process.env.PUBLIC_URL}/blog/official-news`}
render={props => <BlogIndex {...props} blogType="official-news" />}
/>
<Route
exact
path={`${process.env.PUBLIC_URL}/blog/community-articles`}
render={props => <BlogIndex {...props} blogType="community-articles" />}
/>
<Redirect
exact
from={`${process.env.PUBLIC_URL}/blog`}
to={`${process.env.PUBLIC_URL}/blog/official-news`}
/>
<Route path={`${process.env.PUBLIC_URL}/blog/:blog_title`} component={BlogShow} />
<Redirect
exact
from={`${process.env.PUBLIC_URL}/news`}
to={`${process.env.PUBLIC_URL}/blog/official-news`}
/>
<Redirect
exact
from={`${process.env.PUBLIC_URL}/community`}
to={`${process.env.PUBLIC_URL}/blog/community-articles`}
/>
<Redirect exact from={`${process.env.PUBLIC_URL}/docs/tables`} to="/schema" />
<Route
path={`${process.env.PUBLIC_URL}/downloads/:release_type/:osquery_version`}
component={Downloads}
/>
<Redirect
from={`${process.env.PUBLIC_URL}/downloads`}
to={`${process.env.PUBLIC_URL}/downloads/official/${currentOsqueryVersion}`}
/>
<Route
exact
path={`${process.env.PUBLIC_URL}/schema/:schemaVersion`}
component={Schema}
/>
<Route
from={`${process.env.PUBLIC_URL}/schema/`}
render={({ location }) => (
// This render function is a redirect that preserves the search
// and hash params. This allows linking directly to tables
// without knowing the version number in advance.
<Redirect
to={{
pathname: `${process.env.PUBLIC_URL}/schema/${currentOsqueryVersion}/`,
search: location.search,
hash: location.hash,
}}
/>
)}
/>
<Route component={NotFound} />
</Switch>
<Suspense
fallback={<div style={{ padding: '20px', textAlign: 'center' }}>Loading...</div>}
>
<Switch>
<Route exact path={`${process.env.PUBLIC_URL}/`} component={Home} />
<Route
exact
path={`${process.env.PUBLIC_URL}/blog/official-news`}
render={props => <BlogIndex {...props} blogType="official-news" />}
/>
<Route
exact
path={`${process.env.PUBLIC_URL}/blog/community-articles`}
render={props => <BlogIndex {...props} blogType="community-articles" />}
/>
<Redirect
exact
from={`${process.env.PUBLIC_URL}/blog`}
to={`${process.env.PUBLIC_URL}/blog/official-news`}
/>
<Route path={`${process.env.PUBLIC_URL}/blog/:blog_title`} component={BlogShow} />
<Redirect
exact
from={`${process.env.PUBLIC_URL}/news`}
to={`${process.env.PUBLIC_URL}/blog/official-news`}
/>
<Redirect
exact
from={`${process.env.PUBLIC_URL}/community`}
to={`${process.env.PUBLIC_URL}/blog/community-articles`}
/>
<Redirect exact from={`${process.env.PUBLIC_URL}/docs/tables`} to="/schema" />
<Route
path={`${process.env.PUBLIC_URL}/downloads/:release_type/:osquery_version`}
component={Downloads}
/>
<Redirect
from={`${process.env.PUBLIC_URL}/downloads`}
to={`${process.env.PUBLIC_URL}/downloads/official/${currentOsqueryVersion}`}
/>
<Route
exact
path={`${process.env.PUBLIC_URL}/schema/:schemaVersion`}
component={Schema}
/>
<Route
from={`${process.env.PUBLIC_URL}/schema/`}
render={({ location }) => (
// This render function is a redirect that preserves the search
// and hash params. This allows linking directly to tables
// without knowing the version number in advance.
<Redirect
to={{
pathname: `${process.env.PUBLIC_URL}/schema/${currentOsqueryVersion}/`,
search: location.search,
hash: location.hash,
}}
/>
)}
/>
<Route component={NotFound} />
</Switch>
</Suspense>
</App>
</BrowserRouter>
)
Expand Down
12 changes: 9 additions & 3 deletions src/pages/BlogIndex/BlogIndex.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { Component } from 'react'
import showdown from 'showdown'
import { withRouter } from 'react-router'
import { Link } from 'react-router-dom'
import truncate from 'html-truncate'
Expand All @@ -18,7 +17,14 @@ class BlogIndex extends Component {
constructor(props) {
super(props)

this.converter = new showdown.Converter()
this.converter = null
this.initShowdown()
}

async initShowdown() {
const showdown = await import('showdown')
this.converter = new showdown.default.Converter()
this.forceUpdate()
}

onToggleBlogType = blogType => () =>
Expand Down Expand Up @@ -55,7 +61,7 @@ class BlogIndex extends Component {

{activeBlogPosts.map((blogPost, idx) => {
const { attributes, body } = blogPost
const html = truncate(converter.makeHtml(body), 400)
const html = converter ? truncate(converter.makeHtml(body), 400) : 'Loading...'
const blogPath = `${process.env.PUBLIC_URL}/blog/${attributes.slugifiedTitle}`
const isLastPost = idx === activeBlogPosts.length - 1

Expand Down
14 changes: 11 additions & 3 deletions src/pages/BlogShow/BlogShow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { Component } from 'react'
import forEach from 'lodash.foreach'
import showdown from 'showdown'
import { withRouter } from 'react-router'

import BlogPost from 'components/BlogPost'
Expand All @@ -15,25 +14,34 @@ class BlogShow extends Component {
constructor(props) {
super(props)

this.converter = new showdown.Converter({ tables: true })
this.converter = null

this.state = {
blogPost: undefined,
blogTitle: props.match.params.blog_title,
}
}

componentDidMount() {
async componentDidMount() {
const { blogTitle } = this.state

const blogPost = blogPosts.find(post => post.attributes.slugifiedTitle === blogTitle)

if (blogPost) {
const showdown = await import('showdown')
this.converter = new showdown.default.Converter({ tables: true })
}

this.setState({ blogPost })
}

get htmlWithImages() {
const { body } = this.state.blogPost

if (!this.converter) {
return 'Loading...'
}

let html = this.converter.makeHtml(body)

forEach(images, (path, name) => {
Expand Down
Loading
Loading