-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
150 changed files
with
4,672 additions
and
1,155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
NEXT_PUBLIC_GA_TRACKING_ID = 'UA-41298772-4' | ||
NEXT_PUBLIC_GA_TRACKING_ID = 'G-B1E83PJ3RT' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,13 +30,12 @@ | |
"classnames": "^2.2.6", | ||
"date-fns": "^2.16.1", | ||
"debounce": "^1.2.1", | ||
"ga-lite": "^2.1.4", | ||
"github-slugger": "^1.3.0", | ||
"next": "^13.4.1", | ||
"next-remote-watch": "^1.0.0", | ||
"parse-numeric-range": "^1.2.0", | ||
"react": "^0.0.0-experimental-16d053d59-20230506", | ||
"react-collapsed": "npm:@gaearon/[email protected]", | ||
"react-collapsed": "4.0.4", | ||
"react-dom": "^0.0.0-experimental-16d053d59-20230506", | ||
"remark-frontmatter": "^4.0.1", | ||
"remark-gfm": "^3.0.1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Error Decoder requires reading pregenerated error message from getStaticProps, | ||
// but MDX component doesn't support props. So we use React Context to populate | ||
// the value without prop-drilling. | ||
// TODO: Replace with React.cache + React.use when migrating to Next.js App Router | ||
|
||
import {createContext, useContext} from 'react'; | ||
|
||
const notInErrorDecoderContext = Symbol('not in error decoder context'); | ||
|
||
export const ErrorDecoderContext = createContext< | ||
| {errorMessage: string | null; errorCode: string | null} | ||
| typeof notInErrorDecoderContext | ||
>(notInErrorDecoderContext); | ||
|
||
export const useErrorDecoderParams = () => { | ||
const params = useContext(ErrorDecoderContext); | ||
|
||
if (params === notInErrorDecoderContext) { | ||
throw new Error('useErrorDecoder must be used in error decoder pages only'); | ||
} | ||
|
||
return params; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import {useEffect, useState} from 'react'; | ||
import {useErrorDecoderParams} from '../ErrorDecoderContext'; | ||
import cn from 'classnames'; | ||
|
||
function replaceArgs( | ||
msg: string, | ||
argList: Array<string | undefined>, | ||
replacer = '[missing argument]' | ||
): string { | ||
let argIdx = 0; | ||
return msg.replace(/%s/g, function () { | ||
const arg = argList[argIdx++]; | ||
// arg can be an empty string: ?args[0]=&args[1]=count | ||
return arg === undefined || arg === '' ? replacer : arg; | ||
}); | ||
} | ||
|
||
/** | ||
* Sindre Sorhus <https://sindresorhus.com> | ||
* Released under MIT license | ||
* https://github.com/sindresorhus/linkify-urls/blob/edd75a64a9c36d7025f102f666ddbb6cf0afa7cd/index.js#L4C25-L4C137 | ||
* | ||
* The regex is used to extract URL from the string for linkify. | ||
*/ | ||
const urlRegex = | ||
/((?<!\+)https?:\/\/(?:www\.)?(?:[-\w.]+?[.@][a-zA-Z\d]{2,}|localhost)(?:[-\w.:%+~#*$!?&/=@]*?(?:,(?!\s))*?)*)/g; | ||
|
||
// When the message contains a URL (like https://fb.me/react-refs-must-have-owner), | ||
// make it a clickable link. | ||
function urlify(str: string): React.ReactNode[] { | ||
const segments = str.split(urlRegex); | ||
|
||
return segments.map((message, i) => { | ||
if (i % 2 === 1) { | ||
return ( | ||
<a | ||
key={i} | ||
target="_blank" | ||
className="underline" | ||
rel="noopener noreferrer" | ||
href={message}> | ||
{message} | ||
</a> | ||
); | ||
} | ||
return message; | ||
}); | ||
} | ||
|
||
// `?args[]=foo&args[]=bar` | ||
// or `// ?args[0]=foo&args[1]=bar` | ||
function parseQueryString(search: string): Array<string | undefined> { | ||
const rawQueryString = search.substring(1); | ||
if (!rawQueryString) { | ||
return []; | ||
} | ||
|
||
const args: Array<string | undefined> = []; | ||
|
||
const queries = rawQueryString.split('&'); | ||
for (let i = 0; i < queries.length; i++) { | ||
const query = decodeURIComponent(queries[i]); | ||
if (query.startsWith('args[')) { | ||
args.push(query.slice(query.indexOf(']=') + 2)); | ||
} | ||
} | ||
|
||
return args; | ||
} | ||
|
||
export default function ErrorDecoder() { | ||
const {errorMessage} = useErrorDecoderParams(); | ||
/** error messages that contain %s require reading location.search */ | ||
const hasParams = errorMessage?.includes('%s'); | ||
const [message, setMessage] = useState<React.ReactNode | null>(() => | ||
errorMessage ? urlify(errorMessage) : null | ||
); | ||
|
||
const [isReady, setIsReady] = useState(errorMessage == null || !hasParams); | ||
|
||
useEffect(() => { | ||
if (errorMessage == null || !hasParams) { | ||
return; | ||
} | ||
|
||
setMessage( | ||
urlify( | ||
replaceArgs( | ||
errorMessage, | ||
parseQueryString(window.location.search), | ||
'[missing argument]' | ||
) | ||
) | ||
); | ||
setIsReady(true); | ||
}, [hasParams, errorMessage]); | ||
|
||
return ( | ||
<code | ||
className={cn( | ||
'block bg-red-100 text-red-600 py-4 px-6 mt-5 rounded-lg', | ||
isReady ? 'opacity-100' : 'opacity-0' | ||
)}> | ||
<b>{message}</b> | ||
</code> | ||
); | ||
} |
Oops, something went wrong.