Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Merge branch '4.0.0' into jsx-no-bind
Browse files Browse the repository at this point in the history
* 4.0.0:
  Create `prepareSitemap` Batfish helper to improve sitemap (#427)
  Add eslint-plugin-jsx-a11y (#435)
  • Loading branch information
Katy DeCorah committed Apr 14, 2021
2 parents 8edfb44 + de93e03 commit a28153d
Show file tree
Hide file tree
Showing 23 changed files with 471 additions and 125 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ notifications:
scripts:
- npm test
- npm run build-docs
# run sitemap tests after build to assert sitemap is correct
- jest src/helpers/batfish/__tests__/sitemap.test.js
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

- Enforce use of React PureComponents to improve performance. [#414](https://github.com/mapbox/dr-ui/pull/414)
- Improve color contrast on code and anchor elements. [#434](https://github.com/mapbox/dr-ui/pull/434)
- Enable eslint-plugin-jsx-a11y. [#435](https://github.com/mapbox/dr-ui/pull/435)
- Create `prepareSitemap` Batfish helper to improve sitemap. [#427](https://github.com/mapbox/dr-ui/pull/427). See [`prepareSitemap`](https://mapbox.github.io/dr-ui/guides/batfish-helpers/#prepare-sitemap) for instructions on how to add the `dataSelector` to your Batfish configuration. You will also want to add the following to the top of any redirect files so that they will be excluded from the sitemap:

```js
/*---
hideFromSearchEngines: true
---*/
```

- 🚨The `CodeSnippet` prop `highlighter` no longer accepts an arrow function.
- Before: `highlighter={() => highlightJson}`
- After: `highlighter={highlightJson}`
Expand Down
10 changes: 9 additions & 1 deletion docs/batfish.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const path = require('path');
const {
buildNavigation,
buildFilters,
buildSplitPages
buildSplitPages,
prepareSitemap
} = require('../src/helpers/batfish/index.js');

const siteBasePath = '/dr-ui';
Expand All @@ -22,6 +23,7 @@ const addPages = [

module.exports = () => {
return {
siteOrigin: 'https://mapbox.github.io',
siteBasePath: siteBasePath,
outputDirectory: path.join(__dirname, '_site/'),
temporaryDirectory: path.join(__dirname, '_site_tmp/'),
Expand All @@ -47,10 +49,16 @@ module.exports = () => {
require('../src/plugins/make-table-scroll')
]
},
sitemap: {
// generated by the sitemapIgnore dataSelector
ignoreFile: 'docs/_site_tmp/data/sitemap-ignore.js'
},
dataSelectors: {
navigation: (data) => buildNavigation({ siteBasePath, data, addPages }),
filters: (data) => buildFilters(data),
splitPages: (data) => buildSplitPages(data),
sitemapIgnore: ({ pages }) =>
prepareSitemap({ pages, siteBasePath, docsPath: 'docs' }),
sync: (data) => {
/* syncs data to fixtures to properly test batfish selectors */
const sortBy = (key) => {
Expand Down
64 changes: 64 additions & 0 deletions docs/src/pages/guides/batfish-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ prependJs:
- "import navigation from '@mapbox/batfish/data/navigation'; // eslint-disable-line"
- "import topics from '@mapbox/batfish/data/filters'; // eslint-disable-line"
- "import splitPages from '@mapbox/batfish/data/split-pages'; // eslint-disable-line"
- "import sitemapIgnore from '@mapbox/batfish/data/sitemap-ignore'; // eslint-disable-line"
---

Dr. UI has two functions that are used in `dataSelectors` in `batfish.config.js` to help build page metadata and site hierarchy. Each data selector has tests to assert the shape of the data.
Expand Down Expand Up @@ -252,6 +253,69 @@ class PageShell extends React.Component {
{{JSON.stringify(splitPages, null,2)}}
```

## Prepare sitemap

`prepareSitemap` creates a data file that lists all files with `hideFromSearchEngines: true` or `splitPage: true` set in the page's frontMatter. Use this generated file with Batfish's [`sitemap.ignoreFile`](https://github.com/mapbox/batfish/blob/main/docs/configuration.md#sitemap) option to generate a sitemap that excludes any paths in the prepared file.

### Arguments

- `data`, object. Provided by the data selector.
- `siteBasePath`, string. The site's `siteBasePath` as defined in the Batfish config.
- `outputDirectory`, string. Batfish's `outputDirectory`. Default `_site`.
- `docsPath`, string. The directory that `batfish.config.js` lives in, if not in the root. (It's unlikely that you will use this option.)

### Set up in batfish.config.js

```js
const { prepareSitemap } = require('@mapbox/dr-ui/helpers/batfish/index.js');

module.exports = () => {
return {
sitemap: {
// generated by the sitemapIgnore dataSelector
ignoreFile: '_site_tmp/data/sitemap-ignore.js'
},
dataSelectors: {
sitemapIgnore: ({ pages }) => prepareSitemap({ pages, siteBasePath })
}
};
};
```

#### Advanced usage

For sites that generate demos, like mapbox-gl-js and mts-docs, you can exclude the assets folder:

```js
const { prepareSitemap } = require('@mapbox/dr-ui/helpers/batfish/index.js');

module.exports = () => {
return {
sitemap: {
// generated by the sitemapIgnore dataSelector
ignoreFile: '_site_tmp/data/sitemap-ignore.js'
},
dataSelectors: {
sitemapIgnore: ({ pages }) => [
...prepareSitemap({ pages, siteBasePath }),
// exclude demos generated by webpack loader
`${process.cwd()}/_site/assets/`
]
}
};
};
```

### Output

- The shape is an array of paths that should be excluded from the sitemap.

#### Sample

```json
{{JSON.stringify(sitemapIgnore, null,2)}}
```

## Troubleshooting

If data is not building as you expect:
Expand Down
4 changes: 4 additions & 0 deletions docs/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*---
hideFromSearchEngines: true
---*/

import { prefixUrl } from '@mapbox/batfish/modules/prefix-url';
import { createRedirect } from '../../../src/helpers/create-redirect';

Expand Down
Loading

0 comments on commit a28153d

Please sign in to comment.