Skip to content

Commit ff0a664

Browse files
authored
feat(gatsby-source-wordpress): use env var to disable catch links (#36141)
* use env var to disable catch links * Update gatsby-link.md * convert to plugin option instead of env var
1 parent 7d3988c commit ff0a664

File tree

4 files changed

+65
-6
lines changed

4 files changed

+65
-6
lines changed

packages/gatsby-source-wordpress/docs/features/gatsby-link.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,29 @@ Anchor tag src's in html that are links to your WP instance are automatically re
44

55
Anchor tags in html that are relative links automatically become `gatsby-link`'s so that navigation via html links are blazing fast.
66

7+
## `gatsby-plugin-catch-links`
8+
9+
Because links in html fields are so common in WordPress, `gatsby-source-wordpress` auto-installs `gatsby-plugin-catch-links` for you. In 99% of cases this works well, but for some sites you may need to configure catch-links yourself. You can disable the automatically included version of `gatsby-plugin-catch-links` by setting the `catchLinks` plugin option to `false`. Once it's disabled you can install it yourself and configure its plugin options in your gatsby-config.js
10+
11+
Example `gatsby-config.js` file:
12+
13+
```js
14+
module.exports = {
15+
plugins: [
16+
{
17+
resolve: `gatsby-source-wordpress`,
18+
options: {
19+
catchLinks: false,
20+
},
21+
},
22+
{
23+
resolve: `gatsby-plugin-catch-links`,
24+
options: {
25+
// add the options you need here.
26+
},
27+
},
28+
],
29+
}
30+
```
31+
732
:point_left: [Back to Features](./index.md)

packages/gatsby-source-wordpress/docs/plugin-options.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
- [searchAndReplace](#searchandreplace)
4343
- [searchAndReplace[].search](#searchandreplacesearch)
4444
- [searchAndReplace[].replace](#searchandreplacereplace)
45+
- [catchLinks](#catchlinks)
4546
- [html](#html)
4647
- [html.useGatsbyImage](#htmlusegatsbyimage)
4748
- [html.gatsbyImageOptions](#htmlgatsbyimageoptions)
@@ -870,6 +871,24 @@ The replacement string for each regex match.
870871

871872
```
872873

874+
## catchLinks
875+
876+
Turns on/off an automatically included copy of gatsby-plugin-catch-links which is used to catch anchor tags in html fields to perform client-side routing instead of full page refreshes.
877+
878+
**Field type**: `Boolean`
879+
880+
**Default value**: `true`
881+
882+
```js
883+
{
884+
resolve: `gatsby-source-wordpress`,
885+
options: {
886+
catchLinks: false,
887+
},
888+
}
889+
890+
```
891+
873892
## html
874893

875894
Options related to html field processing.
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
module.exports = {
2-
plugins: [
3-
`gatsby-plugin-catch-links`,
4-
`gatsby-plugin-image`,
5-
`gatsby-plugin-sharp`,
6-
],
1+
module.exports = ({ catchLinks = true }) => {
2+
const plugins = [`gatsby-plugin-image`, `gatsby-plugin-sharp`]
3+
4+
if (catchLinks) {
5+
plugins.push(`gatsby-plugin-catch-links`)
6+
}
7+
8+
return {
9+
plugins,
10+
}
711
}

packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,17 @@ When using this option, be sure to gitignore the wordpress-cache directory in th
591591
],
592592
`),
593593
}),
594+
catchLinks: Joi.boolean()
595+
.default(true)
596+
.allow(null)
597+
.description(
598+
`Turns on/off an automatically included copy of gatsby-plugin-catch-links which is used to catch anchor tags in html fields to perform client-side routing instead of full page refreshes.`
599+
)
600+
.meta({
601+
example: wrapOptions(`
602+
catchLinks: false,
603+
`),
604+
}),
594605
html: Joi.object({
595606
useGatsbyImage: Joi.boolean()
596607
.default(true)

0 commit comments

Comments
 (0)