Skip to content

Commit 10a0421

Browse files
authored
chore(rebuild): re-incorporate google-analytics (#2045)
* feat(site) Add Google Analytics only for production * fix(site) Add Google Analytics only in production
1 parent c22bfbd commit 10a0421

File tree

4 files changed

+179
-7
lines changed

4 files changed

+179
-7
lines changed

DISCUSSION.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
Discussion
2+
----------
3+
4+
The following is a collection of thoughts, ideas and plans we've gone through
5+
in the last year or so. I wanted to try to get this "down on paper" to make it
6+
easier to discuss...
7+
8+
Here's the TLDR; in terms of actual blocking TODOs if we wanted to stick with
9+
this branch:
10+
11+
- [ ] Finish porting the markdown process to `remark` (may require new plugins)
12+
- [ ] Rethink external population process
13+
- [ ] Extract anchors into `_content.json` via `DirectoryTreePlugin`
14+
- [ ] Finish re-incorporating mobile sidebar
15+
- [x] Re-integrate google-analytics (Fernando)
16+
- [ ] Re-incorporate `redirects.json`
17+
- [ ] Populate page title in `server.jsx` (fernando)
18+
- [ ] Finish `Navigation` component (greg)
19+
- [x] Add custom route for landing page (greg)
20+
21+
Some of these should be fairly quick adds now that the site works. The two
22+
toughest ones are most likely the markdown parsing and external population. The
23+
thing to keep in mind with those two however is that they're going to be an
24+
issue no matter what our build system is. The following section
25+
26+
27+
## Markdown Processing
28+
29+
Whether we go with pure `webpack`, or `gatsby` it seems `remark` is the way to
30+
go and I believe __@wooorm__ (creator of `remark`) would help us out with that.
31+
This issue from `webpack-defaults` contains some discussion and alternatives
32+
though the decision was pretty clear it seems:
33+
34+
https://github.com/webpack-contrib/webpack-defaults/issues/73
35+
36+
We do have a bunch of custom `markdown` processing, however for a bunch of it
37+
`remark` plugins already exist:
38+
39+
- `remark-autolink-headings`
40+
- `remark-mermaid` (#469)
41+
- `remark-highlight.js` (though we do have a custom prism theme)
42+
43+
And here's what isn't covered yet (though probably could be with new plugins
44+
and help from __@wooorm__):
45+
46+
- Mobile table customizations
47+
- Code with links and collapsible sections (`<details>`)
48+
- Custom blockquotes (i.e. `T>`, `W>`, and `?>`)
49+
50+
I think we may want to rethink some of this though. For example, is it 100%
51+
necessary for us to support inline linking and collapsing within code? There
52+
might be other ways to lay out those sections that don't require advanced
53+
parsing behavior.
54+
55+
56+
## Markdown Formatting
57+
58+
Both `remark-lint` and `prettier` were discussed in `webpack-defaults` issue.
59+
Either are fine with me, but I think we should get something in place soon. It
60+
is a pain to have to nitpick things like two line breaks before headers. On top
61+
of that we should probably format everything at 80 characters for improved
62+
readability. Both `remark` and `prettier` are capable of rewriting the file
63+
with standardized formatting so we just need to pick one.
64+
65+
66+
## External Content Population
67+
68+
Jeremy and I discussed this a while back and I agree with his suggestion re
69+
using a steady prefix for all external documents that we can easily
70+
`.gitignore`, e.g. an underscore `_`. I've done this before on other projects
71+
and it has worked really well. This approach removes the need for many of the
72+
`.gitignore` entries as well as the need for a `generated` folder. I think
73+
it'll also make the i18n folks happier as they can simply remove the `_` from
74+
their `.gitignore` and we don't have to maintain a separate `translation`
75+
branch.
76+
77+
I could be missing something here, but -- if not -- I think we should go this
78+
direction. I did this on the `rebuild` branch but haven't started pulling in
79+
external files yet (or updated the `npm run fetch` script).
80+
81+
82+
## `/src` Directory
83+
84+
I'm a fan of having the most simplistic structure possible.
85+
86+
__/assets__
87+
88+
Unless there's any that are used in multiple places, I think we can just move
89+
each to the `/components/***` directory where they're used. Depending on build
90+
process, we could also create `/src/content/images` for any images used within
91+
the actual content of the site.
92+
93+
> __@jeremenichelli__ noted that it can be useful to have a single location for
94+
> `assets` so they're a little easier to find.
95+
96+
__/styles__
97+
98+
On the `rebuild` branch I created a simple `Markdown` component that isolates
99+
all the markdown styling to a single location and makes it much easier to use.
100+
With that done, all that's left in `src/styles` is the base styling which
101+
should probably just go in `Site` component's directory. We would have to put
102+
the `/partials` somewhere and start inlining `/icons` as discussed.
103+
104+
__/utilities__
105+
106+
The `markdown.js` file will be obsolete once we've ported to `remark`. Ideally,
107+
the `highlight.js` utility will also be replaced by a simpler `remark-***`
108+
plugin. If `test-local-storage.js` is all that's left, maybe we just scrap this
109+
folder and move that utility to the one place it's used (`NotificationBar`).
110+
111+
112+
## Build Process
113+
114+
I __was__ able to get the `StaticSiteGeneratorPlugin` working and it __did__
115+
significantly improve build speed. That said, it still has it's quirks and
116+
there's a few things we'd still need to resolve if we went this direction
117+
(marked by `TODO`s). The biggest of these is
118+
119+
- Getting dynamic `import()` statements to work with the plugin.
120+
- Getting the `CommonsChunkPlugin` to work.
121+
122+
Essentially, I was planning on:
123+
124+
- Generating a bunch of HTML pages for initial load and SEO.
125+
- Generating `.js` chunks containing code for lazy loading in SPA mode.
126+
127+
This is similar to Gatsby and other PWA generators in the sense that the site
128+
would be built fully (meaning an actual html file for every page), but then
129+
turn into an SPA as soon as you loaded a single page.
130+
131+
> __@jeremenichelli__ noted that whatever we end up with, it should be simple
132+
> and easy to understand for contributors. I think this makes a lot of sense,
133+
> and if we can't keep the `rebuild` branch fairly simple, then `gatsby` is
134+
> probably a better way to go as it would do many of the same things for us
135+
> without as much overhead. We'd lose some control over the nitty-gritty bits
136+
> but we'd be passing over a lot of work over to `gatsby`.
137+
138+
__UPDATE__
139+
140+
This is now working via dual configs exported as an array from
141+
`webpack.prod.js`. The site is now a both a statically generated site as well
142+
as an SPA (once you've entered any given page). The last key piece of the build
143+
process (besides figuring out markdown parsing) would be to incorporate an
144+
Service Worker making the site a full PWA (and knocking out that issue).
145+
146+
147+
## Versioning & Releases
148+
149+
I'm a huge fan of `standard-version` and have been following the
150+
[conventionalcommits][1] spec very closely, even when merging MRs. We haven't
151+
really started versioning this repo or generating changelogs but we should be
152+
able to do so fairly easily if we keep following the convention and use the
153+
`standard-version` utility.
154+
155+
I think the flow should look something like this:
156+
157+
- Any pushes to `master` are still continually deployed.
158+
- If a new minor or major comes along in the core repo...
159+
- Make sure content reflects the changes in the new version.
160+
- Run `standard-version --release-as [webpack release version]`.
161+
162+
Then the git tags can be used to archive the last of every major version and
163+
allow a version changing interface (e.g. a dropdown) to look at the content
164+
from major to major. We can also customize the changelog generation to include
165+
info on `docs(...)` commits (by default it only does `fix`, `feat` and
166+
`BREAKING CHANGE`).
167+
168+
169+
[1]: http://conventionalcommits.org/

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"react-banner": "^1.0.0-rc.0",
114114
"react-document-title": "^2.0.3",
115115
"react-dom": "^16.2.0",
116+
"react-g-analytics": "0.4.2",
116117
"react-hot-loader": "^4.0.0-beta.12",
117118
"react-router": "^4.2.0",
118119
"react-router-dom": "^4.2.2",

src/index.jsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React from 'react';
33
import ReactDOM from 'react-dom';
44
import { BrowserRouter, Route } from 'react-router-dom';
5+
import AnalyticsRouter from 'react-g-analytics';
56

67
// Import Components
78
import Site from './components/Site/Site';
@@ -12,10 +13,8 @@ import { FindInContent } from './utilities/content-utils';
1213
// Import Content Tree
1314
import Content from './_content.json';
1415

15-
// TODO: Re-integrate <GoogleAnalytics analyticsId="UA-46921629-2" />
16-
// Consider `react-g-analytics` package
17-
18-
const render = process.NODE_ENV === 'production' ? ReactDOM.hydrate : ReactDOM.render;
16+
const Router = process.env.NODE_ENV === 'production' ? AnalyticsRouter : BrowserRouter;
17+
const render = process.env.NODE_ENV === 'production' ? ReactDOM.hydrate : ReactDOM.render;
1918

2019
// Client Side Rendering
2120
if ( window.document !== undefined ) {
@@ -26,7 +25,7 @@ if ( window.document !== undefined ) {
2625

2726
import(`./content/${entryPath}`).then(entryModule => {
2827
render((
29-
<BrowserRouter>
28+
<Router id="UA-46921629-2">
3029
<Route
3130
path="/"
3231
render={ props => (
@@ -39,7 +38,7 @@ if ( window.document !== undefined ) {
3938
} else return import(`./content/${path}`);
4039
}} />
4140
)} />
42-
</BrowserRouter>
41+
</Router>
4342
), document.getElementById('root'));
4443
});
4544
}

webpack.dev.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ module.exports = env => merge(common(env), {
2121
}),
2222
new webpack.optimize.CommonsChunkPlugin({
2323
name: 'vendor',
24-
chunks: [ 'index' ]
24+
chunks: ['index']
25+
}),
26+
new webpack.DefinePlugin({
27+
'process.env.NODE_ENV': JSON.stringify('development')
2528
})
2629
],
2730
devServer: {

0 commit comments

Comments
 (0)