-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hashi-head): validate props.image, add twitter:description (#623)
* feat(hashi-head): validate that props.image is absolute URL * feat: throw error in dev * doc: comment on is-absolute-url * fix: name not property * docs: add reference link for absolute URL in open graph * tests: add test for image error, update descrip test * docs: add examples to is-aboslute-url * fix: clean up TODO comments * chore: update changeset
- Loading branch information
Showing
4 changed files
with
85 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@hashicorp/react-head': minor | ||
--- | ||
|
||
Validates that props.image is an absolute URL, and throws an error in development if it is not. As well, adds `twitter:description` when `description` prop is provided. |
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,26 @@ | ||
/** | ||
* Given a string, | ||
* return true if the string is an absolute URL, | ||
* or false otherwise. | ||
* | ||
* Uses regex so may not be 100% accurate. | ||
* Based on https://github.com/sindresorhus/is-absolute-url | ||
* | ||
* @example | ||
* // returns true, this is an absolute URL | ||
* isAbsoluteUrl('https://www.hashicorp.com/foo/bar'); | ||
* @example | ||
* // returns false, this is a relative path | ||
* isAbsoluteUrl('./foo/bar'); | ||
* @example | ||
* // returns false, this is an absolute path, but not an absolute URL | ||
* isAbsoluteUrl('/foo/bar'); | ||
* @param string The URL to test | ||
* @returns true if the URL is absolute, false otherwise | ||
*/ | ||
function isAbsoluteUrl(string: string): boolean { | ||
const regex = /^[a-zA-Z][a-zA-Z\d+\-.]*:/ | ||
return regex.test(string) | ||
} | ||
|
||
export default isAbsoluteUrl |
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
270c679
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
react-components – ./
react-components.vercel.app
react-components-git-main-hashicorp.vercel.app
react-components-hashicorp.vercel.app