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

Commit

Permalink
Merge pull request #949 from WebDevStudios/hotfix/383-update-todos
Browse files Browse the repository at this point in the history
Hotfix/383 update todos
  • Loading branch information
gregrickaby authored Feb 23, 2022
2 parents 9b81a38 + 874fcef commit ce6f329
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 101 deletions.
23 changes: 23 additions & 0 deletions components/atoms/ExitPreview/ExitPreview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Link from 'next/link'

/**
* Renders an anchor to exit Preview Mode.
*
* @param {object} props The component as props.
* @param {object} props.preview Checks if a preview exists.
* @return {Element | null} The ExitPreview component.
*/
export default function ExitPreview({preview}) {
if (preview) {
return (
<p>
This page is a preview.
<Link href="/api/exit-preview">
<a>Exit preview mode</a>
</Link>
</p>
)
}

return null
}
1 change: 1 addition & 0 deletions components/atoms/ExitPreview/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default} from './ExitPreview.js'
22 changes: 5 additions & 17 deletions functions/isLinkActive.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,10 @@ export default function isLinkActive(asPath, path) {
return false
}

// TODO: Add functionality to check if link is in the full URL path.
// e.g. /portfolio /portfolio/cambells-soup

return asPath === stripTrailingSlash(path)
}

/**
* Remove the last trailing slash from a URL path.
*
* @author WebDevStudios
* @param {string} str The string to search and remove trailing slash.
* @return {string} The formatted string.
*/
function stripTrailingSlash(str) {
if (str.substr(-1) === '/' && str.length > 1) {
return str.substr(0, str.length - 1)
if (path.length > 1) {
const checkSubStr = new RegExp(path)
return checkSubStr.test(asPath)
}
return str

return path === asPath
}
Loading

1 comment on commit ce6f329

@vercel
Copy link

@vercel vercel bot commented on ce6f329 Feb 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.