File size: 2,005 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# Stats App
Odyssey Stats is built to refresh the Stats experience in Jetpack. The counterpart of the project is in [here](https://github.com/Automattic/jetpack/tree/trunk/projects/packages/stats-admin).
## Hiarachy
```
.
βββ src/
βββ components/ β stats app only components. For now there is only a layout component.
βββ page-middleware/ β page.js integration with React and everything
βββ app.js β entry point
βββ routes.js β page.js routes
```
## Routing
It utilizes the [hashbang (#!) in page.js](https://github.com/visionmedia/page.js), however it doesn't work out of the box, because we are using hardcoded paths in Calypso, so some tricks are done in Jetpack to intecept the anchor clicks and covert them to hashbangs.
```
$("#wpcom").on('click', 'a', function (e) {
const link = e && e.currentTarget && e.currentTarget.attributes && e.currentTarget.attributes.href && e.currentTarget.attributes.href.value;
if( link && ! link.startsWith( 'http' ) ) {
location.hash = `#!${link}`;
return false;
}
});
```
## Gridicon
The `Gridicon` in `@automattic/components` leverages `<use>` to load SVG sprites and has issues when loading from CDN (i.e. other than the main domain). So we had to replace with one that doesn't load the SVG sprite file - `packages/components/src/gridicon/no-asset.tsx` - and then in Jetpack, we load it separately:
```
$.get("https://widgets.wp.com/odyssey-stats/common/gridicons-506499ddac13811fee8e.svg", function(data) {
var div = document.createElement("div");
div.innerHTML = new XMLSerializer().serializeToString(data.documentElement);
div.style = 'display: none';
document.body.insertBefore(div, document.body.childNodes[0]);
});
```
## Building
### Production
```bash
cd apps/stats
yarn build
```
### Development
```bash
STATS_PACKAGE_PATH=/path/to/jetpack/projects/packages/stats-admin yarn dev
```
## Uploading to CDN
The path is `widgets.wp.com/odyssey-stats`.
|