Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

(chore) - Fix react-static docs pages build (#1428)

* (chore) - Fix react-static docs pages build

- Fix react-router plugin not outputting correct base path for static export
- Replace relative routes with absolute ones for MDX output (md-plugin@0.3.0)
- Replace sidebar links with absolute ones
- Fix basepath for Google Analytics component as per Victory docs
- Fix basepath across site
- Downgrade react-static to fix static export (otherwise HTML output is empty)

This took a while to figure out as the behaviour and exports is just very
messed up. The downgrade is needed, otherwise no static HTML will be exported.

* Fix linting

* Add missing title component

* Readd preact/compat to docs build

* Fix H3 hash slugs in sidebar search

authored by

Phil Pluckthun and committed by
GitHub
9b7fd1bf 7ab81d0c

+104 -72
+1 -1
docs/architecture.md
··· 6 6 # Architecture 7 7 8 8 `urql` is a highly customizable and flexible GraphQL client, that happens to come with some default 9 - [core behavior in the core package](./core-package.md). 9 + [core behavior in the core package](./basics/core.md). 10 10 11 11 By default, `urql` aims to provide the minimal amount of features that allow us to build an app 12 12 quickly. However, `urql` has also been designed to be a GraphQL Client
+6 -7
packages/site/package.json
··· 43 43 "react-ga": "^3.3.0", 44 44 "react-inlinesvg": "^1.2.0", 45 45 "react-is": "^17.0.1", 46 - "react-router": "^5.0.1", 47 - "react-router-dom": "^5.0.1", 46 + "react-router": "^5.2.0", 47 + "react-router-dom": "^5.2.0", 48 48 "react-router-ga": "^1.2.3", 49 49 "react-scroll": "^1.8.1", 50 - "react-static": "7.4.2", 51 - "react-static-plugin-md-pages": "^0.2.0", 50 + "react-static": "7.2.2", 51 + "react-static-plugin-md-pages": "^0.3.0", 52 52 "styled-components": "^5.2.1" 53 53 }, 54 54 "devDependencies": { ··· 56 56 "@mdx-js/mdx": "^1.5.7", 57 57 "lodash": "^4.17.19", 58 58 "react-hot-loader": "^4.12.20", 59 - "react-static-plugin-react-router": "^7.2.3", 60 - "react-static-plugin-sitemap": "^7.0.0", 61 - "react-static-plugin-styled-components": "^7.2.2", 59 + "react-static-plugin-sitemap": "7.2.2", 60 + "react-static-plugin-styled-components": "7.2.2", 62 61 "surge": "^0.21.3" 63 62 } 64 63 }
+1 -1
packages/site/plugins/preact/node.api.js
··· 1 1 export default () => ({ 2 - webpack: (config, { stage }) => { 2 + webpack: config => { 3 3 config.resolve.alias = { 4 4 ...(config.resolve.alias || {}), 5 5 react: 'preact/compat',
+45
packages/site/plugins/react-router/browser.api.js
··· 1 + /* eslint-disable react/display-name */ 2 + /* eslint-disable react-hooks/rules-of-hooks */ 3 + 4 + import React from 'react'; 5 + import { useBasepath, useStaticInfo } from 'react-static'; 6 + import { BrowserRouter, StaticRouter, withRouter } from 'react-router-dom'; 7 + 8 + const Location = withRouter(({ children, location }) => children(location)); 9 + 10 + const ReactRouterPlugin = ({ RouterProps: userRouterProps = {} }) => ({ 11 + Root: PreviousRoot => ({ children }) => { 12 + const routerProps = { basename: useBasepath() || '' }; 13 + if (routerProps.basename) routerProps.basename = `/${routerProps.basename}`; 14 + const staticInfo = useStaticInfo(); 15 + 16 + // Test for document to detect the node stage 17 + let Router; 18 + if (typeof document !== 'undefined') { 19 + // NOTE: React Router is inconsistent in how it handles base paths 20 + // This will need a trailing slash while the StaticRouter does not 21 + if (routerProps.basename) routerProps.basename += '/'; 22 + // If in the browser, just use the browser router 23 + Router = BrowserRouter; 24 + } else { 25 + Router = StaticRouter; 26 + routerProps.location = staticInfo.path; // Required 27 + routerProps.context = {}; // Required 28 + } 29 + 30 + return ( 31 + <PreviousRoot> 32 + <Router {...routerProps} {...userRouterProps}> 33 + {children} 34 + </Router> 35 + </PreviousRoot> 36 + ); 37 + }, 38 + Routes: PreviousRoutes => props => ( 39 + <Location> 40 + {location => <PreviousRoutes {...props} location={location} />} 41 + </Location> 42 + ), 43 + }); 44 + 45 + export default ReactRouterPlugin;
+2 -9
packages/site/src/components/mdx.js
··· 1 1 import React from 'react'; 2 - import * as path from 'path'; 3 2 import styled, { css } from 'styled-components'; 4 3 import { MDXProvider } from '@mdx-js/react'; 5 - import { useLocation, Link } from 'react-router-dom'; 4 + import { Link } from 'react-router-dom'; 6 5 import { useMarkdownPage } from 'react-static-plugin-md-pages'; 7 6 import Highlight, { Prism } from 'prism-react-renderer'; 8 7 import nightOwlLight from 'prism-react-renderer/themes/nightOwlLight'; 9 8 10 9 import AnchorSvg from '../assets/anchor'; 11 - import { relative } from './sidebar'; 12 10 13 11 const getLanguage = className => { 14 12 const res = className.match(/language-(\w+)/); ··· 230 228 ); 231 229 232 230 const MdLink = ({ href, children }) => { 233 - const currentPage = useMarkdownPage(); 234 - 235 231 if (!/^\w+:/.test(href) && !href.startsWith('#')) { 236 - const from = currentPage.path.replace(/\/$/, ''); 237 - const to = path.join(path.dirname(currentPage.originalPath), href); 238 - 239 - return <Link to={relative(from, to)}>{children}</Link>; 232 + return <Link to={href}>{children}</Link>; 240 233 } 241 234 242 235 return (
+4 -17
packages/site/src/components/sidebar.js
··· 5 5 import Fuse from 'fuse.js'; 6 6 import { useBasepath } from 'react-static'; 7 7 import { Link, useLocation } from 'react-router-dom'; 8 - import * as path from 'path'; 9 8 10 9 import { useMarkdownPage, useMarkdownTree } from 'react-static-plugin-md-pages'; 11 10 ··· 47 46 flex-direction: column; 48 47 padding-bottom: ${p => p.theme.spacing.lg}; 49 48 `; 50 - 51 - export const relative = (from, to) => { 52 - if (!from || !to) return null; 53 - let [toPath, hash] = to.split('#'); 54 - let pathname = path.relative(path.dirname(from), toPath); 55 - if (!pathname) 56 - pathname = path.join(path.relative(from, toPath), path.basename(toPath)); 57 - if (from.endsWith('/')) pathname = '../' + pathname + '/'; 58 - if (!pathname.endsWith('/')) pathname += '/'; 59 - if (hash) pathname += `#${hash}`; 60 - return { pathname }; 61 - }; 62 49 63 50 export const SidebarStyling = ({ children, sidebarOpen }) => { 64 51 const basepath = useBasepath() || ''; ··· 194 181 195 182 const sidebarItems = useMemo(() => { 196 183 let pathname = location.pathname.match(/docs\/?(.+)?/); 197 - 198 184 if (!pathname || !tree || !tree.children || !location) { 199 185 return null; 200 186 } 187 + 201 188 pathname = pathname[0]; 202 189 const trimmedPathname = pathname.replace(/(\/$)|(\/#.+)/, ''); 203 190 ··· 222 209 return ( 223 210 <Fragment key={page.key}> 224 211 <SidebarNavItem 225 - to={relative(pathname, page.path)} 212 + to={`/${page.path}/`} 226 213 // If there is an active filter term in place, expand all headings 227 214 isActive={() => isActive} 228 215 onClick={closeSidebar} ··· 243 230 new RegExp(`${trimmedPathname}$`, 'g') 244 231 ) 245 232 } 246 - to={relative(pathname, childPage.path)} 233 + to={`/${childPage.path}/`} 247 234 > 248 235 {childPage.matchedIndices 249 236 ? highlightText( ··· 256 243 {filterTerm 257 244 ? childPage.headings.map(heading => ( 258 245 <SidebarNavSubItem 259 - to={relative(pathname, childPage.path)} 246 + to={`/${childPage.path}/#${heading.slug}`} 260 247 key={heading.value} 261 248 nested={true} 262 249 >
+7 -1
packages/site/src/google-analytics.js
··· 1 1 import React from 'react'; 2 + import { useBasepath } from 'react-static'; 2 3 import PropTypes from 'prop-types'; 3 4 4 5 let Analytics = {}; ··· 10 11 } 11 12 12 13 const GoogleAnalytics = ({ children, ...rest }) => { 14 + const basename = `/${useBasepath() || ''}`; 13 15 if (typeof document !== 'undefined') { 14 16 // fragment doesn't like it when you try to give it attributes 15 - return <Analytics {...rest}>{children}</Analytics>; 17 + return ( 18 + <Analytics {...rest} basename={basename}> 19 + {children} 20 + </Analytics> 21 + ); 16 22 } 17 23 return <Analytics>{children}</Analytics>; 18 24 };
+7
packages/site/src/screens/docs/article.js
··· 1 1 /* eslint-disable react-hooks/rules-of-hooks */ 2 2 3 3 import React from 'react'; 4 + import { Head } from 'react-static'; 4 5 import styled from 'styled-components'; 5 6 import { useMarkdownPage } from 'react-static-plugin-md-pages'; 6 7 import { ScrollToTop } from '../../components/scroll-to-top'; ··· 79 80 const page = useMarkdownPage(); 80 81 if (!page || !page.headings) return null; 81 82 83 + const title = (page.frontmatter && page.frontmatter.title) || null; 82 84 const headings = page.headings.filter(x => x.depth > 1); 83 85 if (headings.length === 0) return null; 84 86 85 87 return ( 86 88 <> 89 + {title && ( 90 + <Head> 91 + <title>{title} | urql Documentation</title> 92 + </Head> 93 + )} 87 94 <LegendTitle>In this section</LegendTitle> 88 95 <HeadingList> 89 96 {headings.map(heading => (
+6 -6
packages/site/static.config.js
··· 3 3 import constants from './src/constants'; 4 4 import Document from './src/html'; 5 5 6 - const isStaging = process.env.REACT_STATIC_STAGING === 'true'; 7 - const basePath = 'open-source/urql'; 6 + const isStaging = process.env.REACT_STATIC_ENV === 'staging'; 7 + const isProduction = process.env.REACT_STATIC_ENV === 'production'; 8 8 9 9 export default { 10 10 plugins: [ 11 11 resolve(__dirname, 'plugins/monorepo-fix/'), 12 - resolve(__dirname, 'plugins/preact'), 12 + resolve(__dirname, 'plugins/react-router/'), 13 + (isStaging || isProduction) && resolve(__dirname, 'plugins/preact/'), 13 14 [ 14 15 'react-static-plugin-md-pages', 15 16 { ··· 21 22 22 23 'react-static-plugin-styled-components', 23 24 'react-static-plugin-sitemap', 24 - 'react-static-plugin-react-router', 25 - ], 25 + ].filter(Boolean), 26 26 27 27 paths: { 28 28 src: 'src', 29 - dist: isStaging ? `dist/${basePath}` : 'dist', 29 + dist: isStaging ? `dist/open-source/urql` : 'dist', 30 30 buildArtifacts: 'node_modules/.cache/react-static/artifacts/', 31 31 devDist: 'node_modules/.cache/react-static/dist/', 32 32 temp: 'node_modules/.cache/react-static/temp/',
+25 -30
yarn.lock
··· 1733 1733 resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.6.0.tgz#f022195afdfc942e088ee2101285a1d31c7d727f" 1734 1734 integrity sha512-cPqjjzuFWNK3BSKLm0abspP0sp/IGOli4p5I5fKFAzdS8fvjdOwDCfZqAaIiXd9lPkOWi3SUUfZof3hEb7J/uw== 1735 1735 1736 - "@reach/router@^1.3.1", "@reach/router@^1.3.3": 1736 + "@reach/router@^1.2.1", "@reach/router@^1.3.3": 1737 1737 version "1.3.4" 1738 1738 resolved "https://registry.yarnpkg.com/@reach/router/-/router-1.3.4.tgz#d2574b19370a70c80480ed91f3da840136d10f8c" 1739 1739 integrity sha512-+mtn9wjlB9NN2CNnnC/BRYtwdKBfSyyasPYraNAyvaV1occr/5NnB4CVzjEZipNHwYebQwcndGUmpFzxAUoqSA== ··· 3453 3453 resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" 3454 3454 integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg== 3455 3455 3456 - autoprefixer@^9.7.2, autoprefixer@^9.7.4: 3456 + autoprefixer@^9.6.1, autoprefixer@^9.7.2: 3457 3457 version "9.8.6" 3458 3458 resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-9.8.6.tgz#3b73594ca1bf9266320c5acf1588d74dea74210f" 3459 3459 integrity sha512-XrvP4VVHdRBCdX1S3WXVD8+RyG9qeb1D5Sn1DeLiG2xfSpzellk5k54xbUERJ3M5DggQxes39UGOTP8CFrEGbg== ··· 12329 12329 integrity sha1-t+PqQkNaTJsnWdmeDyAesZWALuE= 12330 12330 12331 12331 prism-react-renderer@^1.1.0: 12332 - version "1.1.1" 12333 - resolved "https://registry.yarnpkg.com/prism-react-renderer/-/prism-react-renderer-1.1.1.tgz#1c1be61b1eb9446a146ca7a50b7bcf36f2a70a44" 12334 - integrity sha512-MgMhSdHuHymNRqD6KM3eGS0PNqgK9q4QF5P0yoQQvpB6jNjeSAi3jcSAz0Sua/t9fa4xDOMar9HJbLa08gl9ug== 12332 + version "1.2.0" 12333 + resolved "https://registry.yarnpkg.com/prism-react-renderer/-/prism-react-renderer-1.2.0.tgz#5ad4f90c3e447069426c8a53a0eafde60909cdf4" 12334 + integrity sha512-GHqzxLYImx1iKN1jJURcuRoA/0ygCcNhfGw1IT8nPIMzarmKQ3Nc+JcG0gi8JXQzuh0C5ShE4npMIoqNin40hg== 12335 12335 12336 12336 prismjs@^1.21.0, prismjs@~1.23.0: 12337 12337 version "1.23.0" ··· 12857 12857 resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.8.3.tgz#721d4657672d400c5e3c75d063c4a85fb2d5d68f" 12858 12858 integrity sha512-X8jZHc7nCMjaCqoU+V2I0cOhNW+QMBwSUkeXnTi8IPe6zaRWfn60ZzvFDZqWPfmSJfjub7dDW1SP0jaHWLu/hg== 12859 12859 12860 - react-router-dom@^5.0.1: 12860 + react-router-dom@^5.2.0: 12861 12861 version "5.2.0" 12862 12862 resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-5.2.0.tgz#9e65a4d0c45e13289e66c7b17c7e175d0ea15662" 12863 12863 integrity sha512-gxAmfylo2QUjcwxI63RhQ5G85Qqt4voZpUXSEqCwykV0baaOTQDR1f0PmY8AELqIyVc0NEZUj0Gov5lNGcXgsA== ··· 12875 12875 resolved "https://registry.yarnpkg.com/react-router-ga/-/react-router-ga-1.2.3.tgz#3011b63554e65f50dd16df3dbcdf4ed286b74e73" 12876 12876 integrity sha512-0rNBGGI6Q1hkznbLB+bAmDTS+8w3duaJYYIbCrCwof/p7RbZuv+Lsv9enumRZXxb4oTZrY95vOvFxnsRQ4cFCg== 12877 12877 12878 - react-router@5.2.0, react-router@^5.0.1: 12878 + react-router@5.2.0, react-router@^5.2.0: 12879 12879 version "5.2.0" 12880 12880 resolved "https://registry.yarnpkg.com/react-router/-/react-router-5.2.0.tgz#424e75641ca8747fbf76e5ecca69781aa37ea293" 12881 12881 integrity sha512-smz1DUuFHRKdcJC0jobGo8cVbhO3x50tCL4icacOlcwDOEQPq4TMqwx3sY1TP+DvtTgz4nm3thuo7A+BK2U0Dw== ··· 12931 12931 dependencies: 12932 12932 object-is "^1.1.2" 12933 12933 12934 - react-static-plugin-md-pages@^0.2.0: 12935 - version "0.2.0" 12936 - resolved "https://registry.yarnpkg.com/react-static-plugin-md-pages/-/react-static-plugin-md-pages-0.2.0.tgz#5d5b70dff9fbb276da4ac76680536fa093c0da3d" 12937 - integrity sha512-PtcKa48bJSMvKQSA/8Pz8rxL9ZgTXIvci/BCT6OKunC7iQimSWLv1XvLr88a54SY7xq9/pPe+UkmJGNl5w+egg== 12934 + react-static-plugin-md-pages@^0.3.0: 12935 + version "0.3.0" 12936 + resolved "https://registry.yarnpkg.com/react-static-plugin-md-pages/-/react-static-plugin-md-pages-0.3.0.tgz#a420df0d42a43d387369f8b92d5ab7a27c319a1b" 12937 + integrity sha512-DIBa8pA4LeGU1ioueeO8Yr3F7CVjwg90nBup9A9wNeRIiRz+qkSdlw5Fu86VPkCyxjY4K+xzVbL1JfpMXCMcug== 12938 12938 dependencies: 12939 12939 "@mdx-js/mdx" "^1.5.5" 12940 12940 "@mdx-js/react" "^1.5.5" ··· 12951 12951 unist-util-visit "^2.0.2" 12952 12952 yaml "^1.7.2" 12953 12953 12954 - react-static-plugin-react-router@^7.2.3: 12955 - version "7.5.0" 12956 - resolved "https://registry.yarnpkg.com/react-static-plugin-react-router/-/react-static-plugin-react-router-7.5.0.tgz#d3b56287e157637c36421d00747ccfe421aa4077" 12957 - integrity sha512-ylOCRNACvfXx0KIFxuismQ3GpUXusBrdIdpcUhpKjSze91+gPTyIVrVaf8/DxNqKNYP5Kcxyy5C5NtpYOsJicw== 12958 - 12959 - react-static-plugin-sitemap@^7.0.0: 12960 - version "7.5.0" 12961 - resolved "https://registry.yarnpkg.com/react-static-plugin-sitemap/-/react-static-plugin-sitemap-7.5.0.tgz#7fe2b6327b3bc787c576f66d1df0a416bb2fecd0" 12962 - integrity sha512-k93RRslHk5jGL0/3rU3SNm+xUP2N6CQ1ZER7A753+jA4no/PVu08aHzgM79yeUfyRbQGGEhaNZ2gVafuQIv/+A== 12954 + react-static-plugin-sitemap@7.2.2: 12955 + version "7.2.2" 12956 + resolved "https://registry.yarnpkg.com/react-static-plugin-sitemap/-/react-static-plugin-sitemap-7.2.2.tgz#6f454e352958fb48c1c27f22d6aeeeace53ca44e" 12957 + integrity sha512-uBnsjJBC/IIH+/FJXBUuMvxUPgZNe5KMPuVJPxaRhXFv9HBgYe9H1tCYnlrkZHRjF5aln399cvKyxrJs1CYhiQ== 12963 12958 dependencies: 12964 12959 chalk "^2.4.2" 12965 12960 fs-extra "^8.1.0" 12966 12961 12967 - react-static-plugin-styled-components@^7.2.2: 12968 - version "7.5.0" 12969 - resolved "https://registry.yarnpkg.com/react-static-plugin-styled-components/-/react-static-plugin-styled-components-7.5.0.tgz#2d03f77cf2a12429788797310b6e6625f0dd7835" 12970 - integrity sha512-oZq169VBHemynzpxqIWSBjZHcccftIlenNfq7vPS8FwULGU1K9vbstLw1DnlI+NslKwIvLj9Jnasa8Df8c6H1Q== 12962 + react-static-plugin-styled-components@7.2.2: 12963 + version "7.2.2" 12964 + resolved "https://registry.yarnpkg.com/react-static-plugin-styled-components/-/react-static-plugin-styled-components-7.2.2.tgz#17b71a448780005e1f5fbb0432a440d994144b5d" 12965 + integrity sha512-yjZ2V5b4HLRs6ldbLmreXpXBiNU5y4IByPID/rYWe3J8NFenPMI7kbhiFlBDkUDEhJvGIpSFw3I8OCvAcm4yQg== 12971 12966 12972 - react-static@7.4.2: 12973 - version "7.4.2" 12974 - resolved "https://registry.yarnpkg.com/react-static/-/react-static-7.4.2.tgz#4433dc724c85a074eb7f7412a2d6d55a1e062207" 12975 - integrity sha512-RSrA2dRb3xue4r1fbvG1CA8QLt0kENz2B57NXGVXdC0NPkX3iXUYa8YVPKQV5yHo04Vidcgzki598gtQIK6Omw== 12967 + react-static@7.2.2: 12968 + version "7.2.2" 12969 + resolved "https://registry.yarnpkg.com/react-static/-/react-static-7.2.2.tgz#09c43fd73d0c4201a3d21d8d1609d6afd578447a" 12970 + integrity sha512-+ebhBhRnAT/pPqwJBF1gqqxJOZWpV57fklxm5yM7zRU6xa+CNG3wnYj8VgYI4asjI+WSLnWx92Z+Yk2bWSKd9w== 12976 12971 dependencies: 12977 12972 "@babel/cli" "^7.5.5" 12978 12973 "@babel/core" "^7.5.5" ··· 12988 12983 "@babel/preset-stage-0" "^7.0.0" 12989 12984 "@babel/register" "^7.5.5" 12990 12985 "@babel/runtime" "^7.5.5" 12991 - "@reach/router" "^1.3.1" 12992 - autoprefixer "^9.7.4" 12986 + "@reach/router" "^1.2.1" 12987 + autoprefixer "^9.6.1" 12993 12988 axios "^0.19.0" 12994 12989 babel-core "7.0.0-bridge.0" 12995 12990 babel-loader "^8.0.6"