-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
chore(rebuild): improve static html utilization #2108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
skipjack
merged 6 commits into
rebuild-static-html-fix
from
rebuild-static-html-fix-addition
May 6, 2018
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b103357
chore(rebuild): preload entry page to avoid flash during retrieval
skipjack 7b7f59b
refactor: move sorting/filtering to top-level using new plugin options
skipjack 1261b51
chore: remove obsolete todo
skipjack a5bd68e
refactor(site): finish content-utils thus simplifying the `Site` comp…
skipjack 1d104bf
refactor(splash): rename variable for clarity
skipjack b7ce481
chore(rebuild): address minor feedback
skipjack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,24 +1,45 @@ | ||
// Import External Dependencies | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { BrowserRouter, Route } from 'react-router-dom'; | ||
|
||
// Import Components | ||
import Site from './components/Site/Site'; | ||
|
||
// Import Utilities | ||
import { FindInContent } from './utilities/content-utils'; | ||
|
||
// Import Content Tree | ||
import Content from './_content.json'; | ||
|
||
// TODO: Re-integrate <GoogleAnalytics analyticsId="UA-46921629-2" /> | ||
// Consider `react-g-analytics` package | ||
|
||
const render = process.NODE_ENV === 'production' ? ReactDOM.hydrate : ReactDOM.render; | ||
|
||
// Client Side Rendering | ||
if ( window.document !== undefined ) { | ||
render(( | ||
<BrowserRouter> | ||
<Route | ||
path="/" | ||
render={ props => ( | ||
<Site | ||
{ ...props } | ||
import={ path => import(`./content/${path}`) } /> | ||
)} /> | ||
</BrowserRouter> | ||
), document.getElementById('root')); | ||
let { pathname } = window.location; | ||
let trimmed = pathname.replace(/(.+)\/$/, '$1'); | ||
let entryPage = FindInContent(Content, item => item.url === trimmed); | ||
let entryPath = entryPage.path.replace('src/content/', ''); | ||
|
||
import(`./content/${entryPath}`).then(entryModule => { | ||
render(( | ||
<BrowserRouter> | ||
<Route | ||
path="/" | ||
render={ props => ( | ||
<Site | ||
{ ...props } | ||
import={ path => { | ||
if ( path === entryPath ) { | ||
return entryModule.default || entryModule; | ||
|
||
} else return import(`./content/${path}`); | ||
}} /> | ||
)} /> | ||
</BrowserRouter> | ||
), document.getElementById('root')); | ||
}); | ||
} |
This file contains hidden or 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 hidden or 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,69 @@ | ||
/** | ||
* Walk the given tree of content | ||
* | ||
* @param {object} tree - Any node in the content tree | ||
* @param {function} callback - Run on every descendant as well as the given `tree` | ||
*/ | ||
export const WalkContent = (tree, callback) => { | ||
callback(tree); | ||
|
||
if ( tree.children ) { | ||
tree.children.forEach(child => { | ||
WalkContent(child, callback); | ||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* Deep flatten the given `tree`s child nodes | ||
* | ||
* @param {object} tree - Any node in the content tree | ||
* @return {array} - A flattened list of leaf node descendants | ||
*/ | ||
export const FlattenContent = tree => { | ||
if ( tree.children ) { | ||
return tree.children.reduce((flat, item) => { | ||
return flat.concat( | ||
Array.isArray(item.children) ? FlattenContent(item) : item | ||
); | ||
}, []); | ||
|
||
} else return []; | ||
}; | ||
|
||
/** | ||
* Find an item within the given `tree` | ||
* | ||
* @param {object} tree - Any node in the content tree | ||
* @param {function} test - A callback to find any leaf node in the given `tree` | ||
* @return {object} - The first leaf node that passes the `test` | ||
*/ | ||
export const FindInContent = (tree, test) => { | ||
let list = FlattenContent(tree); | ||
|
||
return list.find(test); | ||
}; | ||
|
||
/** | ||
* Get top-level sections | ||
* | ||
* @param {object} tree - Any node in the content tree | ||
* @return {array} - Immediate children of the given `tree` that are directories | ||
*/ | ||
export const ExtractSections = tree => { | ||
return tree.children.filter(item => ( | ||
item.type === 'directory' | ||
)); | ||
}; | ||
|
||
/** | ||
* Get all markdown pages | ||
* | ||
* @param {object} tree - Any node in the content tree | ||
* @return {array} - All markdown descendants of the given `tree` | ||
*/ | ||
export const ExtractPages = tree => { | ||
return FlattenContent(tree).filter(item => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return item.extension === '.md'; | ||
}); | ||
}; |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
item => item.type === 'directory'